package com.jasamedika.medifirst2000.service.impl;

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

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

import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.PapRiwayatKelahiranDao;
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
import com.jasamedika.medifirst2000.entities.DataPersalinan;
import com.jasamedika.medifirst2000.entities.PapRiwayatKelahiran;
import com.jasamedika.medifirst2000.entities.Pasien;
import com.jasamedika.medifirst2000.entities.StatusYaTidak;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.PapRiwayatKelahiranService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.DataPersalinanVO;
import com.jasamedika.medifirst2000.vo.PapRiwayatKelahiranVO;
import com.jasamedika.medifirst2000.vo.PasienVO;
import com.jasamedika.medifirst2000.vo.StatusYaTidakVO;


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


@Service("papRiwayatKelahiranService")
public class PapRiwayatKelahiranServiceImpl extends BaseVoServiceImpl implements PapRiwayatKelahiranService {

	@Autowired
	private PapRiwayatKelahiranDao papRiwayatKelahiranDao;
	
	@Autowired
	private BaseConverterImpl<PapRiwayatKelahiranVO,PapRiwayatKelahiran> papRiwayatKelahiranConverter;
	
	@Autowired
	private BaseConverterImpl<StatusYaTidakVO,StatusYaTidak> menangisConverter;
	
	@Autowired
	private BaseConverterImpl<StatusYaTidakVO,StatusYaTidak> riwayatKuningConverter;
	
	@Autowired
	private BaseConverterImpl<DataPersalinanVO,DataPersalinan> dataPersalinanConverter;
	
	@Autowired
	private BaseConverterImpl<PasienVO,Pasien> pasienConverter;

	@Override
	public Map<String,Object> add(PapRiwayatKelahiranVO vo) {
		
		PapRiwayatKelahiran papRiwayatKelahiran=new PapRiwayatKelahiran();
		papRiwayatKelahiran.setNoRec(vo.getNoRec());
		if(CommonUtil.isNotNullOrEmpty(vo)){
			papRiwayatKelahiran=papRiwayatKelahiranConverter.transferVOToModel(vo, new PapRiwayatKelahiran());
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getDataPersalinan())){
			papRiwayatKelahiran.setDataPersalinan(dataPersalinanConverter.transferVOToModel(vo.getDataPersalinan(), new DataPersalinan()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getRiwayatKuning())){
			papRiwayatKelahiran.setRiwayatKuning(riwayatKuningConverter.transferVOToModel(vo.getRiwayatKuning(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getMenangis())){
			papRiwayatKelahiran.setMenangis(menangisConverter.transferVOToModel(vo.getMenangis(), new StatusYaTidak()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getPasien())){
			AntrianPasienDiPeriksa antrianPasienDiPeriksa = new AntrianPasienDiPeriksa();
			antrianPasienDiPeriksa.setNoRec(vo.getPasien().getNoRec());
			papRiwayatKelahiran.setPasien(antrianPasienDiPeriksa);
		}
		
		papRiwayatKelahiran=papRiwayatKelahiranDao.save(papRiwayatKelahiran);
		
		Map<String,Object> result=new HashMap<String,Object>();
		result.put("noRec", papRiwayatKelahiran.getNoRec());
		
		return result;
	}

	


}
