package com.jasamedika.medifirst2000.service.impl;


import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.TransferPasienExsternalDao;
import com.jasamedika.medifirst2000.dao.TransferPasienInternalDao;
import com.jasamedika.medifirst2000.entities.Alergi;
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
import com.jasamedika.medifirst2000.entities.DetailDiagnosaSekunder;
import com.jasamedika.medifirst2000.entities.DetailInformasiMedis;
import com.jasamedika.medifirst2000.entities.Diagnosa;
import com.jasamedika.medifirst2000.entities.Fasilitas;
import com.jasamedika.medifirst2000.entities.HubunganKeluarga;
import com.jasamedika.medifirst2000.entities.InformasiMedis;
import com.jasamedika.medifirst2000.entities.JenisNyeri;
import com.jasamedika.medifirst2000.entities.KeadaanPasien;
import com.jasamedika.medifirst2000.entities.Obat;
import com.jasamedika.medifirst2000.entities.PapTandaVital;
import com.jasamedika.medifirst2000.entities.Pasien;
import com.jasamedika.medifirst2000.entities.PasienDaftar;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.entities.Peralatan;
import com.jasamedika.medifirst2000.entities.PeralatanDetail;
import com.jasamedika.medifirst2000.entities.PetugasPendampingDetail;
import com.jasamedika.medifirst2000.entities.Produk;
import com.jasamedika.medifirst2000.entities.ResikoJatuh;
import com.jasamedika.medifirst2000.entities.Ruangan;
import com.jasamedika.medifirst2000.entities.StatusKemandirian;
import com.jasamedika.medifirst2000.entities.StatusMandiri;
import com.jasamedika.medifirst2000.entities.StatusPsikologis;
import com.jasamedika.medifirst2000.entities.StatusYaTidak;
import com.jasamedika.medifirst2000.entities.Tenaga;
import com.jasamedika.medifirst2000.entities.TerapiSaatPindahDetail;
import com.jasamedika.medifirst2000.entities.TransferPasienExsternal;
import com.jasamedika.medifirst2000.entities.TransferPasienInternal;
import com.jasamedika.medifirst2000.service.StatusKemandirianService;
import com.jasamedika.medifirst2000.service.TransferPasienInternalService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.AlergiVO;
import com.jasamedika.medifirst2000.vo.AntrianPasienDiPeriksaVO;
import com.jasamedika.medifirst2000.vo.DetailDiagnosaSekunderVO;
import com.jasamedika.medifirst2000.vo.DetailInformasiMedisVO;
import com.jasamedika.medifirst2000.vo.DiagnosaVO;
import com.jasamedika.medifirst2000.vo.FasilitasVO;
import com.jasamedika.medifirst2000.vo.HubunganKeluargaVO;
import com.jasamedika.medifirst2000.vo.InformasiMedisVO;
import com.jasamedika.medifirst2000.vo.JenisNyeriVO;
import com.jasamedika.medifirst2000.vo.KeadaanPasienVO;
import com.jasamedika.medifirst2000.vo.ObatVO;
import com.jasamedika.medifirst2000.vo.PapTandaVitalVO;
import com.jasamedika.medifirst2000.vo.PasienDaftarVO;
import com.jasamedika.medifirst2000.vo.PasienVO;
import com.jasamedika.medifirst2000.vo.PegawaiVO;
import com.jasamedika.medifirst2000.vo.PeralatanDetailVO;
import com.jasamedika.medifirst2000.vo.PeralatanVO;
import com.jasamedika.medifirst2000.vo.PetugasPendampingDetailVO;
import com.jasamedika.medifirst2000.vo.ProdukVO;
import com.jasamedika.medifirst2000.vo.ResikoJatuhVO;
import com.jasamedika.medifirst2000.vo.RuanganVO;
import com.jasamedika.medifirst2000.vo.StatusKemandirianVO;
import com.jasamedika.medifirst2000.vo.StatusMandiriVO;
import com.jasamedika.medifirst2000.vo.StatusPsikologisVO;
import com.jasamedika.medifirst2000.vo.StatusYaTidakVO;
import com.jasamedika.medifirst2000.vo.TenagaVO;
import com.jasamedika.medifirst2000.vo.TerapiSaatPindahDetailVO;
import com.jasamedika.medifirst2000.vo.TransferPasienExsternalVO;
import com.jasamedika.medifirst2000.vo.TransferPasienInternalVO;


/**
 * Implement class for PasienService
 * 
 * @author Adik
 * @param <T>
 */


@Service("transferPasienInternalService")
public class TransferPasienInternalServiceImpl extends BaseVoServiceImpl implements TransferPasienInternalService {

	@Autowired
	private BaseConverterImpl<TransferPasienInternalVO, TransferPasienInternal> transferPasienInternalConverter; 
	
	@Autowired
	private BaseConverterImpl<TransferPasienExsternalVO, TransferPasienExsternal> transferPasienExsternalConverter; 
	
	@Autowired
	private BaseConverterImpl<HubunganKeluargaVO, HubunganKeluarga> hubunganKeluargaConverter; 
	
	@Autowired
	private BaseConverterImpl<RuanganVO, Ruangan> ruanganConverter; 
	
	@Autowired
	private BaseConverterImpl<DetailDiagnosaSekunderVO, DetailDiagnosaSekunder> detailDiagnosaSekunderConverter; 
	
	@Autowired
	private BaseConverterImpl<PapTandaVitalVO, PapTandaVital> papTandaVitalConverter; 
	
	@Autowired
	private BaseConverterImpl<DetailInformasiMedisVO, DetailInformasiMedis> detailInformasiMedisConverter;
	
	@Autowired
	private BaseConverterImpl<InformasiMedisVO, InformasiMedis> informasiMedisConverter;
	
	@Autowired
	private BaseConverterImpl<PeralatanDetailVO, PeralatanDetail> peralatanDetailConverter;
	
	@Autowired
	private BaseConverterImpl<TerapiSaatPindahDetailVO, TerapiSaatPindahDetail> terapiSaatPindahDetailConverter;
	
	@Autowired
	private BaseConverterImpl<PetugasPendampingDetailVO, PetugasPendampingDetail> petugasPendampingDetailConverter;
	
	@Autowired
	private BaseConverterImpl<AntrianPasienDiPeriksaVO, AntrianPasienDiPeriksa> antrianPasienDiperiksaConverter; 
	
	@Autowired
	private BaseConverterImpl<PegawaiVO, Pegawai> pegawaiConverter; 
	
	@Autowired
	private BaseConverterImpl<AlergiVO, Alergi> alergiConverter;
	
	@Autowired
	private BaseConverterImpl<PasienDaftarVO, PasienDaftar> pasienDaftarConverter;
	
	@Autowired
	private BaseConverterImpl<ProdukVO, Produk> obatConverter;
	
	@Autowired
	private BaseConverterImpl<ResikoJatuhVO, ResikoJatuh> resikoJatuhConverter; 
	
	@Autowired
	private BaseConverterImpl<DiagnosaVO, Diagnosa> diagnosaConverter;
	
	@Autowired
	private BaseConverterImpl<PeralatanVO, Peralatan> peralatanConverter;
	
	@Autowired
	private BaseConverterImpl<JenisNyeriVO, JenisNyeri> jenisNyeriConverter;
	
	@Autowired
	private BaseConverterImpl<StatusKemandirianVO, StatusKemandirian> statusKemandirianConverter;
	
	@Autowired
	private BaseConverterImpl<StatusPsikologisVO, StatusPsikologis> statusPsikologisConverter;
	
	@Autowired
	private BaseConverterImpl<StatusYaTidakVO, StatusYaTidak> statusYaTidakConverter; 
	
	@Autowired
	private BaseConverterImpl<KeadaanPasienVO, KeadaanPasien> keadaanPasienConverter; 
	
	@Autowired
	private BaseConverterImpl<FasilitasVO, Fasilitas> fasilitasConverter; 
	
	@Autowired
	private BaseConverterImpl<TenagaVO, Tenaga> tenagaConverter; 
	
	@Autowired
	private StatusKemandirianService statusKemandirianService;
	
	@Autowired
	private TransferPasienInternalDao transferPasienInternalDao;
	
	@Autowired
	private TransferPasienExsternalDao transferPasienExsternalDao;
	
	@Autowired
	private BaseConverterImpl<StatusMandiriVO,StatusMandiri>statusMandiriConverter;
	
	@Override
	public Map<String, Object> saveTransferPasienInternal(TransferPasienInternalVO vo) {
		TransferPasienInternal transferPasienInternal=new TransferPasienInternal();
		Map<String,Object> result=new HashMap<String,Object>();
		AntrianPasienDiPeriksa antrianPasienDiPeriksa = new AntrianPasienDiPeriksa();
		if(CommonUtil.isNotNullOrEmpty(vo))
		{
			transferPasienInternal.setTanggalInput(new Date());
			transferPasienInternal=transferPasienInternalConverter.transferVOToModel(vo, new TransferPasienInternal());
			
			if(CommonUtil.isNotNullOrEmpty(vo.getResikoJatuh())){
				transferPasienInternal.setResikoJatuh(resikoJatuhConverter.transferVOToModel(vo.getResikoJatuh(), new ResikoJatuh()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getHubunganKeluarga()))
			{
				transferPasienInternal.setHubunganKeluarga(hubunganKeluargaConverter.transferVOToModel(vo.getHubunganKeluarga(), new HubunganKeluarga()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getRuangRawatSelanjutnya())){
				transferPasienInternal.setRuangRawatSelanjutnya(ruanganConverter.transferVOToModel(vo.getRuangRawatSelanjutnya(), new Ruangan()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getAsalRuanganRawat())){
				transferPasienInternal.setAsalRuanganRawat(ruanganConverter.transferVOToModel(vo.getAsalRuanganRawat(), new Ruangan()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getPasienDaftar())){
				antrianPasienDiPeriksa = antrianPasienDiperiksaConverter.transferVOToModel(vo.getPasienDaftar(), new AntrianPasienDiPeriksa());
				//antrianPasienDiPeriksa.setPasienDaftar(pasienDaftarConverter.transferVOToModel(vo.getPasienDaftar().getPasienDaftar(), new PasienDaftar()));
				transferPasienInternal.setPasien(antrianPasienDiPeriksa);
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getDokterJaga())){
				transferPasienInternal.setDokterJaga(pegawaiConverter.transferVOToModel(vo.getDokterJaga(), new Pegawai()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getIsKeluargaDiberiTahuAlasanPemindahan())){
				transferPasienInternal.setIsKeluargaDiberiTahuAlasanPemindahan(statusYaTidakConverter.transferVOToModel(vo.getIsKeluargaDiberiTahuAlasanPemindahan(), new StatusYaTidak()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getIsPasienDiberiTahuAlasanPemindahan())){
				transferPasienInternal.setIsPasienDiberiTahuAlasanPemindahan(statusYaTidakConverter.transferVOToModel(vo.getIsPasienDiberiTahuAlasanPemindahan(), new StatusYaTidak()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getKeadaanPasien())){
				transferPasienInternal.setKeadaanPasien(keadaanPasienConverter.transferVOToModel(vo.getKeadaanPasien(), new KeadaanPasien()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getFasilitas())){
				transferPasienInternal.setFasilitas(fasilitasConverter.transferVOToModel(vo.getFasilitas(), new Fasilitas()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getTenaga())){
				transferPasienInternal.setTenaga(tenagaConverter.transferVOToModel(vo.getTenaga(),new Tenaga()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getDokterPenanggungJawab())){
				transferPasienInternal.setDokterPenanggungJawab(pegawaiConverter.transferVOToModel(vo.getDokterPenanggungJawab(), new Pegawai()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getDokterYangMengirim())){
				transferPasienInternal.setDokterYangMengirim(pegawaiConverter.transferVOToModel(vo.getDokterYangMengirim(), new Pegawai()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getPetugasYangMenerima())){
				transferPasienInternal.setPetugasYangMenerima(pegawaiConverter.transferVOToModel(vo.getPetugasYangMenerima(), new Pegawai()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getPetugasYangMengantar())){
				transferPasienInternal.setPetugasYangMengantar(pegawaiConverter.transferVOToModel(vo.getPetugasYangMengantar(), new Pegawai()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getAlergi())){
				transferPasienInternal.setAlergi(alergiConverter.transferVOToModel(vo.getAlergi(), new Alergi()));
			}			
			
			if(CommonUtil.isNotNullOrEmpty(vo.getDiagnosaUtama())){
				transferPasienInternal.setDiagnosaUtama(diagnosaConverter.transferVOToModel(vo.getDiagnosaUtama(), new Diagnosa()));
			}	
			
			if(CommonUtil.isNotNullOrEmpty(vo.getMetodePemindahan()))
			{
				transferPasienInternal.setMetodePemindahan(peralatanConverter.transferVOToModel(vo.getMetodePemindahan(), new Peralatan()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getJenisNyeri())){
				transferPasienInternal.setJenisNyeri(jenisNyeriConverter.transferVOToModel(vo.getJenisNyeri(), new JenisNyeri()));
			}
			
			if(CommonUtil.isNotNullOrEmpty(vo.getStatusPsikologis())){
				transferPasienInternal.setStatusPsikologis(statusPsikologisConverter.transferVOToModel(vo.getStatusPsikologis(), new StatusPsikologis()));
			}	
			if(CommonUtil.isNotNullOrEmpty(vo.getInformasiMedis())){
				transferPasienInternal.setInformasiMedis(informasiMedisConverter.transferVOToModel(vo.getInformasiMedis(), new InformasiMedis()));
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getGangguan())){
				transferPasienInternal.setGangguan(informasiMedisConverter.transferVOToModel(vo.getGangguan(), new InformasiMedis()));
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getInkontinensia())){
				transferPasienInternal.setInkontinensia(informasiMedisConverter.transferVOToModel(vo.getInkontinensia(), new InformasiMedis()));
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getPotensiRehabilitasi())){
				transferPasienInternal.setPotensiRehabilitasi(informasiMedisConverter.transferVOToModel(vo.getPotensiRehabilitasi(), new InformasiMedis()));
			}			
			
			//StatusKemandirian
			StatusKemandirianVO statusKemandirianVO = vo.getStatusKemandirian();
			StatusKemandirian model = new StatusKemandirian();
			model = statusKemandirianConverter.transferVOToModel(statusKemandirianVO,model);
			
			if(CommonUtil.isNotNullOrEmpty(antrianPasienDiPeriksa))
			{
				model.setPasien(antrianPasienDiPeriksa);
			}
			
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.getEkstremitasAtas()))
			{
					model.setEkstremitasAtas(statusMandiriConverter.transferVOToModel(statusKemandirianVO.getEkstremitasAtas(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.getBatangTumbuh()))
			{
					model.setBatangTumbuh(statusMandiriConverter.transferVOToModel(statusKemandirianVO.getBatangTumbuh(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.getEkstremitasBawah()))
			{
					model.setEkstremitasBawah(statusMandiriConverter.transferVOToModel(statusKemandirianVO.getEkstremitasBawah(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.getMakanan()))
			{
					model.setMakanan(statusMandiriConverter.transferVOToModel(statusKemandirianVO.getMakanan(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.getJalanKaki()))
			{
					model.setJalanKaki(statusMandiriConverter.transferVOToModel(statusKemandirianVO.getJalanKaki(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.getKursiRoda()))
			{
					model.setKursiRoda(statusMandiriConverter.transferVOToModel(statusKemandirianVO.getKursiRoda(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.getBerguling()))
			{
					model.setBerguling(statusMandiriConverter.transferVOToModel(statusKemandirianVO.getBerguling(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.getDuduk()))
			{
					model.setDuduk(statusMandiriConverter.transferVOToModel(statusKemandirianVO.getDuduk(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.gethPWajahRambutTangan()))
			{
					model.sethPWajahRambutTangan(statusMandiriConverter.transferVOToModel(statusKemandirianVO.gethPWajahRambutTangan(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.gethPBatangTubuhDanPerineum()))
			{
					model.sethPBatangTubuhDanPerineum(statusMandiriConverter.transferVOToModel(statusKemandirianVO.gethPBatangTubuhDanPerineum(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.gethPEkstremitasBawah()))
			{
					model.sethPEkstremitasBawah(statusMandiriConverter.transferVOToModel(statusKemandirianVO.gethPEkstremitasBawah(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.gethPTraktusDigestivus()))
			{
					model.sethPTraktusDigestivus(statusMandiriConverter.transferVOToModel(statusKemandirianVO.gethPTraktusDigestivus(), new StatusMandiri()));
			}
			if (CommonUtil.isNotNullOrEmpty(statusKemandirianVO.gethPTraktusUrinarius()))
			{
					model.sethPTraktusUrinarius(statusMandiriConverter.transferVOToModel(statusKemandirianVO.gethPTraktusUrinarius(), new StatusMandiri()));
			}		
			model.setTransferPasienInternal(transferPasienInternal);
			transferPasienInternal.setStatusKemandirian(model);
			//-----------------------------------------------------------
			Set<DetailInformasiMedis> setDetailInformasiMedis = new HashSet<DetailInformasiMedis>();
			Set<PeralatanDetail> setPeralatanDetail = new HashSet<PeralatanDetail>();
			Set<PetugasPendampingDetail> setPetugasPendampingDetail = new HashSet<PetugasPendampingDetail>();
			Set<TerapiSaatPindahDetail> setTerapiSaatPindahDetail = new HashSet<TerapiSaatPindahDetail>();
			Set<DetailDiagnosaSekunder> setDiagnosaSekunder = new HashSet<DetailDiagnosaSekunder>();
			for(DetailDiagnosaSekunderVO detailDiagnosaSekunderVO : vo.getDiagnosaSekunder())
			{
				DetailDiagnosaSekunder detailDiagnosaSekunder = detailDiagnosaSekunderConverter.transferVOToModel(detailDiagnosaSekunderVO, new DetailDiagnosaSekunder());
				if(CommonUtil.isNotNullOrEmpty(detailDiagnosaSekunderVO.getDiagnosa()))
				{
					detailDiagnosaSekunder.setDiagnosa(diagnosaConverter.transferVOToModel(detailDiagnosaSekunderVO.getDiagnosa(), new Diagnosa()));
				}				
				detailDiagnosaSekunder.setTransferPasienInternal(transferPasienInternal);
				setDiagnosaSekunder.add(detailDiagnosaSekunder);				
			}
			/*for(DetailInformasiMedisVO detailInformasiMedisVO : vo.getDetailInformasiMedis())
			{ 
				DetailInformasiMedis detailInformasiMedis = detailInformasiMedisConverter.transferVOToModel(detailInformasiMedisVO, new DetailInformasiMedis());
				if(CommonUtil.isNotNullOrEmpty(detailInformasiMedisVO.getInformasiMedis()))
				{
					detailInformasiMedis.setInformasiMedis(informasiMedisConverter.transferVOToModel(detailInformasiMedisVO.getInformasiMedis(), new InformasiMedis()));					
				}
				detailInformasiMedis.setTransferPasienInternal(transferPasienInternal);
				setDetailInformasiMedis.add(detailInformasiMedis);
			}*/
			
			for(PeralatanDetailVO peralatanDetailVO : vo.getDetailPeralatan())
			{ 
				PeralatanDetail peralatanDetail = peralatanDetailConverter.transferVOToModel(peralatanDetailVO, new PeralatanDetail());
				if(CommonUtil.isNotNullOrEmpty(peralatanDetailVO.getPeralatan()))
				{
					peralatanDetail.setPeralatan(peralatanConverter.transferVOToModel(peralatanDetailVO.getPeralatan(), new Peralatan()));					
				}
				peralatanDetail.setTransferPasienInternal(transferPasienInternal);
				setPeralatanDetail.add(peralatanDetail);
			}
			
			for(PetugasPendampingDetailVO petugasPendampingDetailVO : vo.getDetailPetugasPendamping())
			{ 
				PetugasPendampingDetail petugasPendampingDetail = petugasPendampingDetailConverter.transferVOToModel(petugasPendampingDetailVO, new PetugasPendampingDetail());
				if(CommonUtil.isNotNullOrEmpty(petugasPendampingDetailVO.getPegawai()))
				{
					petugasPendampingDetail.setPegawai(pegawaiConverter.transferVOToModel(petugasPendampingDetailVO.getPegawai(), new Pegawai()));
				}				
				petugasPendampingDetail.setTransferPasienInternal(transferPasienInternal);
				setPetugasPendampingDetail.add(petugasPendampingDetail);
			}
			
			for(TerapiSaatPindahDetailVO terapiSaatPindahDetailVO : vo.getDetailTerapiSaatPindah())
			{ 
				TerapiSaatPindahDetail terapiSaatPindahDetail = terapiSaatPindahDetailConverter.transferVOToModel(terapiSaatPindahDetailVO, new TerapiSaatPindahDetail());
				if(CommonUtil.isNotNullOrEmpty(terapiSaatPindahDetailVO.getObat()))
				{
					terapiSaatPindahDetail.setObat(obatConverter.transferVOToModel(terapiSaatPindahDetailVO.getObat(), new Produk()));					
				}
				terapiSaatPindahDetail.setTransferPasienInternal(transferPasienInternal);
				setTerapiSaatPindahDetail.add(terapiSaatPindahDetail);
			}
			transferPasienInternal.getDiagnosaSekunder().clear();
			//transferPasienInternal.getDetailInformasiMedis().clear();
			transferPasienInternal.getDetailPeralatan().clear();
			transferPasienInternal.getDetailPetugasPendamping().clear();
			transferPasienInternal.getDetailTerapiSaatPindah().clear();
			//transferPasienInternal.setDetailInformasiMedis(setDetailInformasiMedis);
			transferPasienInternal.setDetailPeralatan(setPeralatanDetail);
			transferPasienInternal.setDetailPetugasPendamping(setPetugasPendampingDetail);
			transferPasienInternal.setDetailTerapiSaatPindah(setTerapiSaatPindahDetail);
			transferPasienInternal.setStatusKemandirian(model);
			transferPasienInternal.setDiagnosaSekunder(setDiagnosaSekunder);			
			//String noRegistrasi = transferPasienInternalDao.findNoRegistrasi(antrianPasienDiPeriksa.noRec);
			String noRec = transferPasienInternalDao.findTransferPasienInternal(antrianPasienDiPeriksa.noRec);
			if(CommonUtil.isNotNullOrEmpty(noRec))
			{
				TransferPasienInternal currentModel = transferPasienInternalDao.findOne(noRec);
				if(CommonUtil.isNotNullOrEmpty(currentModel))
				{
					transferPasienInternalDao.delete(noRec);
				}
				//transferPasienInternal.setNoRec(noRecAntrian);				
			}			
			transferPasienInternal=transferPasienInternalDao.save(transferPasienInternal);
			result.put("noRec", transferPasienInternal.getNoRec());
			result.put("noRecStatusKemandirian", transferPasienInternal.getStatusKemandirian().getNoRec());
		}
		return result;
	}

	@Override
	public Map<String, Object> saveTransferPasienExsternal(TransferPasienExsternalVO vo) {
		TransferPasienExsternal transferPasienExsternal=new TransferPasienExsternal();
		
		transferPasienExsternal=transferPasienExsternalConverter.transferVOToModel(vo, new TransferPasienExsternal());
		
		if(CommonUtil.isNotNullOrEmpty(vo.getRuangRawatSelanjutnya())){
			transferPasienExsternal.setRuangRawatSelanjutnya(ruanganConverter.transferVOToModel(vo.getRuangRawatSelanjutnya(), new Ruangan()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getAsalRuanganRawat())){
			transferPasienExsternal.setAsalRuanganRawat(ruanganConverter.transferVOToModel(vo.getAsalRuanganRawat(), new Ruangan()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getPasienDaftar())){
			transferPasienExsternal.setPasien(antrianPasienDiperiksaConverter.transferVOToModel(vo.getPasienDaftar(), new AntrianPasienDiPeriksa()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getDokterJaga())){
			transferPasienExsternal.setDokterJaga(pegawaiConverter.transferVOToModel(vo.getDokterJaga(), new Pegawai()));
		}

		
		if(CommonUtil.isNotNullOrEmpty(vo.getIsKeluargaDiberiTahuAlasanPemindahan())){
			transferPasienExsternal.setIsKeluargaDiberiTahuAlasanPemindahan(statusYaTidakConverter.transferVOToModel(vo.getIsKeluargaDiberiTahuAlasanPemindahan(), new StatusYaTidak()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getIsPasienDiberiTahuAlasanPemindahan())){
			transferPasienExsternal.setIsKeluargaDiberiTahuAlasanPemindahan(statusYaTidakConverter.transferVOToModel(vo.getIsKeluargaDiberiTahuAlasanPemindahan(), new StatusYaTidak()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getKeadaanPasien())){
			transferPasienExsternal.setKeadaanPasien(keadaanPasienConverter.transferVOToModel(vo.getKeadaanPasien(), new KeadaanPasien()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getFasilitas())){
			transferPasienExsternal.setFasilitas(fasilitasConverter.transferVOToModel(vo.getFasilitas(), new Fasilitas()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getTenaga())){
			transferPasienExsternal.setTenaga(tenagaConverter.transferVOToModel(vo.getTenaga(),new Tenaga()));
		}
		
		transferPasienExsternal=transferPasienExsternalDao.save(transferPasienExsternal);
		Map<String,Object> result=new HashMap<String,Object>();
		result.put("noRec", transferPasienExsternal.getNoRec());
		return result;
	}

	@Override
	public List<Map<String, Object>> findPeralatan(Boolean values) {
		List<Map<String, Object>> result = transferPasienInternalDao.findPeralatan(values);
		return result;
	}

	@Override
	public Map<String,Object> findTransferInternal(String startDate, String endDate) {
		List<Map<String,Object>> result = transferPasienInternalDao.findTransferPasienInternal(startDate, endDate);
		for(Map<String,Object> data:result)
		{
			String noRec = data.get("noRec")+"";
			data.put("detailDiagnosaSekunder", transferPasienInternalDao.findDetailDiagnosaSekunder(noRec));
			//data.put("detailInformasiMedis", transferPasienInternalDao.findDetailDiagnosaSekunder(noRec));
			data.put("detailPeralatan", transferPasienInternalDao.findDetailDiagnosaSekunder(noRec));
			data.put("detailPetugasPendamping", transferPasienInternalDao.findDetailDiagnosaSekunder(noRec));
			data.put("detailTerapiSaatPindah", transferPasienInternalDao.findDetailTerapiSaatPindah(noRec));
			data.put("statusKemandirian", transferPasienInternalDao.findDetailDiagnosaSekunder(noRec));
		}
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("Data", result);
		return map;
	}
	
	
}
