package com.jasamedika.medifirst2000.service.impl;

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

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

import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.DiagnosaKeperawatanTransaksiDao;
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
import com.jasamedika.medifirst2000.entities.DiagnosaKeperawatan;
import com.jasamedika.medifirst2000.entities.DiagnosaKeperawatanTransaksi;
import com.jasamedika.medifirst2000.entities.Evaluasi;
import com.jasamedika.medifirst2000.entities.Implementasi;
import com.jasamedika.medifirst2000.entities.Intervensi;
import com.jasamedika.medifirst2000.entities.Pegawai;
import com.jasamedika.medifirst2000.entities.Ruangan;
import com.jasamedika.medifirst2000.service.DiagnosaKeperawatanTransaksiService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.DateUtil;
import com.jasamedika.medifirst2000.vo.AntrianPasienDiPeriksaVO;
import com.jasamedika.medifirst2000.vo.DiagnosaKeperawatanTransaksiVO;
import com.jasamedika.medifirst2000.vo.DiagnosaKeperawatanVO;
import com.jasamedika.medifirst2000.vo.EvaluasiVO;
import com.jasamedika.medifirst2000.vo.ImplementasiVO;
import com.jasamedika.medifirst2000.vo.IntervensiVO;
import com.jasamedika.medifirst2000.vo.PegawaiVO;
import com.jasamedika.medifirst2000.vo.RuanganVO;

@Service("DiagnosaKeperawatanTransaksiService")
public class DiagnosaKeperawatanTransaksiServiceImpl implements DiagnosaKeperawatanTransaksiService {

	@Autowired
	private DiagnosaKeperawatanTransaksiDao diagnosaKeperawatanTransaksiDao; 
	
	@Autowired
	private BaseConverterImpl<DiagnosaKeperawatanTransaksiVO, DiagnosaKeperawatanTransaksi> diagnosaKeperawatanTransaksiConverter;
	
	@Autowired
	private BaseConverterImpl<DiagnosaKeperawatanVO, DiagnosaKeperawatan> diagnosaKeperawatanConverter; 
	
	@Autowired
	private BaseConverterImpl<AntrianPasienDiPeriksaVO, AntrianPasienDiPeriksa> antrianPasienDiperiksaConverter; 
	
	@Autowired
	private BaseConverterImpl<ImplementasiVO, Implementasi> implementasiConverter; 
	
	@Autowired
	private BaseConverterImpl<IntervensiVO, Intervensi> intervensiConverter;
	
	@Autowired
	private BaseConverterImpl<EvaluasiVO, Evaluasi> evaluasiConverter; 
	
	@Autowired
	private BaseConverterImpl<RuanganVO, Ruangan> ruanganConverter; 
	
	@Autowired
	private BaseConverterImpl<PegawaiVO, Pegawai> pegawaiConverter; 
	
	@Override
	public Map<String, Object> saveDiagnosaKeperawatan(List<DiagnosaKeperawatanTransaksiVO> listVo) {
		Map<String, Object> result =  new HashMap<String, Object>();
		if(CommonUtil.isNotNullOrEmpty(listVo)) {
			for(DiagnosaKeperawatanTransaksiVO vo : listVo){
				
				DiagnosaKeperawatanTransaksi diagnosaKeperawatanTransaksi = new DiagnosaKeperawatanTransaksi();

				if(CommonUtil.isNotNullOrEmpty(vo)){
					diagnosaKeperawatanTransaksi = diagnosaKeperawatanTransaksiConverter.transferVOToModel(vo, new DiagnosaKeperawatanTransaksi());
					diagnosaKeperawatanTransaksi.setTglInput(DateUtil.now());
				}
				if(CommonUtil.isNotNullOrEmpty(vo.getDiagnosaKeperawatan())){					
					diagnosaKeperawatanTransaksi.setDiagnosaKeperawatan(diagnosaKeperawatanConverter.transferVOToModel(vo.getDiagnosaKeperawatan(), new DiagnosaKeperawatan()));
				}
				if(CommonUtil.isNotNullOrEmpty(vo.getPasienDaftar())){
					diagnosaKeperawatanTransaksi.setPasien(antrianPasienDiperiksaConverter.transferVOToModel(vo.getPasienDaftar(), new AntrianPasienDiPeriksa()));
				}
				if(CommonUtil.isNotNullOrEmpty(vo.getRuangan())){
					diagnosaKeperawatanTransaksi.setRuangan(ruanganConverter.transferVOToModel(vo.getRuangan(), new Ruangan()));
				}
				if(CommonUtil.isNotNullOrEmpty(vo.getPegawai())){
					diagnosaKeperawatanTransaksi.setPegawai(pegawaiConverter.transferVOToModel(vo.getPegawai(), new Pegawai()));
				}
				if(CommonUtil.isNotNullOrEmpty(vo.getImplementasi().getId())){
					diagnosaKeperawatanTransaksi.setImplementasi(implementasiConverter.transferVOToModel(vo.getImplementasi(), new Implementasi()));
				}
				if(CommonUtil.isNotNullOrEmpty(vo.getIntervensi().getId())){
					diagnosaKeperawatanTransaksi.setIntervensi(intervensiConverter.transferVOToModel(vo.getIntervensi(), new Intervensi()));
				}
				if(CommonUtil.isNotNullOrEmpty(vo.getEvaluasi().getId())){
					diagnosaKeperawatanTransaksi.setEvaluasi(evaluasiConverter.transferVOToModel(vo.getEvaluasi(), new Evaluasi()));
				}
				if(CommonUtil.isNotNullOrEmpty(diagnosaKeperawatanTransaksi)){
					DiagnosaKeperawatanTransaksi model = diagnosaKeperawatanTransaksiDao.save(diagnosaKeperawatanTransaksi);
					result.put("noRec", model.getNoRec());
				}
			}
		}
		return result;
	}

}
