package com.jasamedika.medifirst2000.dao;

import java.util.List;
import java.util.Map;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.jasamedika.medifirst2000.entities.LisOrderSysmex; 

@Repository("PelayananLaboratoriumDao")
public interface PelayananLaboratoriumDao extends PagingAndSortingRepository<LisOrderSysmex, Integer>{

	@Query("select NEW MAP(orderpelayanan.noRec as noRec, "
			+" orderpelayanan.isCito as cito, "
			+" orderpelayanan.tglPelayanan as tglPelayanan, "
			+" produk.id as produkId , "
			+" produk.namaProduk as namaProduk, "
			+" pasien.noCm as noCm, "
			+" strukorder.noOrderIntern as noOrderIntern, "
			+" pasien.namaPasien as namaPasien , "
			+" pasien.tglLahir as tglLahir, "
			+" jeniskelamin.jenisKelamin as jenisKelamin, "
			+" alamat.alamatLengkap as alamatLengkap, "
			+" ruangan.id as ruanganId, "
			+" ruangan.namaRuangan as namaRuangan, "
			+" coalesce(alamat.alamatLengkap,'') as alamat, "
			+" coalesce(kelurahan.namaDesaKelurahan,'') as kelurahan,  "
			+" coalesce(kecamatan.namaKecamatan,'') as kecamatan, "
			+" coalesce(kabupaten.namaKotaKabupaten,'') as kota,	 "		
			+" pasiendaftar.noRegistrasi as noRegis, "
			+" pegawai.id as pegawaiId, "
			+" pegawai.namaLengkap as namaLengkap,"
			+" departemen.id as idDep  )"
			+" FROM "
			+" OrderPelayanan orderpelayanan "
			+" left join orderpelayanan.produk produk "
			+" left join orderpelayanan.strukOrder strukorder "
			+" left join strukorder.noCm pasien "
			+" left join pasien.jenisKelamin jeniskelamin "
			+" left join pasien.alamats alamat "
			+" left join alamat.desaKelurahan kelurahan "
			+" left join alamat.kotaKabupaten kabupaten "
			+" left join alamat.kecamatan kecamatan "
			+" left join strukorder.noRegistrasi pasiendaftar "
			+" left join orderpelayanan.ruangan ruangan "
			+" left join strukorder.pegawaiOrder pegawai "   
			+" left join ruangan.departemen departemen "
			+" where "
			+" strukorder.noOrder = :noOrder  ")
			List<Map<String, Object>> getListHeadOrder(
			@Param("noOrder") String noOrder);
 
	
	@Query("select NEW MAP(model.ono as ono) from LisOrderSysmex model  where  model.ono =:noLab")
	List<Map<String, Object>> chekOrder(@Param("noLab") String noLab);
}
