package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jasamedika.medifirst2000.vo.PasienVO;
import com.jasamedika.medifirst2000.vo.RuanganVO;
import com.jasamedika.medifirst2000.entities.Pasien;
import com.jasamedika.medifirst2000.entities.Ruangan;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.PapInformasiIbuService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
import com.jasamedika.medifirst2000.entities.Kebangsaan;
import com.jasamedika.medifirst2000.entities.PapInformasiIbu;
import com.jasamedika.medifirst2000.vo.AntrianPasienDiPeriksaVO;
import com.jasamedika.medifirst2000.vo.KebangsaanVO;
import com.jasamedika.medifirst2000.vo.PapInformasiIbuVO;
import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.AntrianPasienDiPeriksaDao;
import com.jasamedika.medifirst2000.dao.PapInformasiIbuDao;
import com.jasamedika.medifirst2000.dao.PasienDaftarDao;

/**
 * Implement class for PapInformasiIbuService
 * 
 * @author Generator
 * @param <T>
 */
@Service("papInformasiIbuService")
public class PapInformasiIbuServiceImpl extends BaseVoServiceImpl implements PapInformasiIbuService 
{	
	@Autowired
	private BaseConverterImpl<PapInformasiIbuVO,PapInformasiIbu>papInformasiIbuConverter;

	@Autowired
	private BaseConverterImpl<AntrianPasienDiPeriksaVO, AntrianPasienDiPeriksa> antrianPasienDiPeriksaConverter;
	
	@Autowired
	private BaseConverterImpl<PasienVO,Pasien>pasienConverter;
	
	@Autowired
	private BaseConverterImpl<RuanganVO, Ruangan> ruanganConverter;
	
	@Autowired
	private BaseConverterImpl<KebangsaanVO, Kebangsaan> kebangsaanConverter;

	@Autowired
	private PapInformasiIbuDao papInformasiIbuDao;

	@Autowired
	private AntrianPasienDiPeriksaDao antrianPasienDiPeriksaDao;
	
	@Override
	public Map<String, Object> savePapInformasiIbu(PapInformasiIbuVO vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		
		PapInformasiIbu model = papInformasiIbuConverter.transferVOToModel(vo, new PapInformasiIbu());
		
		if(CommonUtil.isNotNullOrEmpty(vo.getIbu())){
			model.setIbu(pasienConverter.transferVOToModel(vo.getIbu(), new Pasien()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getRuangan())){
			model.setRuangan(ruanganConverter.transferVOToModel(vo.getRuangan(), new Ruangan()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getPasienDaftar())){
			model.setPasien(antrianPasienDiPeriksaConverter.transferVOToModel(vo.getPasienDaftar(), new AntrianPasienDiPeriksa()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getKebangsaan())){
			model.setKebangsaan(kebangsaanConverter.transferVOToModel(vo.getKebangsaan(), new Kebangsaan()));
		}
		if(CommonUtil.isNotNullOrEmpty(model)){
			PapInformasiIbu papInformasiIbuResult =  papInformasiIbuDao.save(model);
			result.put("noRec", papInformasiIbuResult.noRec);
		}
		return result;
	}
	
	/*public Map<String, Object> getPapById(Integer id){
		return papInformasiIbuDao.getPap(id);
	}*/
}