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.orm.jpa.JpaSystemException;
import org.springframework.stereotype.Service;

import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.dao.AntrianPasienDiPeriksaDao;
import com.jasamedika.medifirst2000.dao.RiwayatKehamilanPersalinanNifasYangLaluDao;
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
import com.jasamedika.medifirst2000.entities.RiwayatKehamilanPersalinanNifasYangLalu;
import com.jasamedika.medifirst2000.entities.SkalaNyeri;
import com.jasamedika.medifirst2000.entities.StatusHidupMati;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.RiwayatKehamilanPersalinanNifasYangLaluService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.util.JsonUtil;
import com.jasamedika.medifirst2000.vo.RiwayatKehamilanPersalinanNifasYangLaluVO;
import com.jasamedika.medifirst2000.vo.SkalaNyeriVO;
import com.jasamedika.medifirst2000.vo.StatusHidupMatiVO;

/**
 * Implement class for PAPStatusFungsionalService
 * 
 * @author Askur
 */
@Service("RiwayatKehamilanPersalinanNifasYangLaluService")
public class RiwayatKehamilanPersalinanNifasYangLaluServiceImpl implements RiwayatKehamilanPersalinanNifasYangLaluService<RiwayatKehamilanPersalinanNifasYangLaluVO> {
	@Autowired
	private RiwayatKehamilanPersalinanNifasYangLaluDao riwayatKehamilanPersalinanNifasYangLaluDao;
	@Autowired
	private AntrianPasienDiPeriksaDao antrianPasienDiPeriksaDao;
	@Autowired
	private BaseConverterImpl<RiwayatKehamilanPersalinanNifasYangLaluVO, RiwayatKehamilanPersalinanNifasYangLalu> riwayatKehamilanPersalinanNifasYangLaluConverter;
	@Autowired
	private BaseConverterImpl<StatusHidupMatiVO, StatusHidupMati> statusHidupMatiConverter;
	
	@Autowired
	private BaseConverterImpl<SkalaNyeriVO, SkalaNyeri> skalaNyeriConverter;
	
	@Override
	public Map<String,Object> addRiwayatKehamilanPersalinanNifasYangLalu(List<RiwayatKehamilanPersalinanNifasYangLaluVO> vos) {
		Map<String,Object> result=new HashMap<String,Object>();
		RiwayatKehamilanPersalinanNifasYangLalu model=new RiwayatKehamilanPersalinanNifasYangLalu();
		for(RiwayatKehamilanPersalinanNifasYangLaluVO vo:vos){
		model=riwayatKehamilanPersalinanNifasYangLaluConverter.transferVOToModel(vo, model);
		AntrianPasienDiPeriksa antrianPasienDiPeriksa=antrianPasienDiPeriksaDao.findByNoRec(vo.getAntrianPasienDiPeriksa().getNoRec());
		model.setAntrianPasienDiPeriksa(antrianPasienDiPeriksa);
		if(CommonUtil.isNotNullOrEmpty(vo.getStatus())){
			model.setStatus(statusHidupMatiConverter.transferVOToModel(vo.getStatus(), new StatusHidupMati()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getSkalaNyeri())){
			model.setSkalaNyeri(skalaNyeriConverter.transferVOToModel(vo.getSkalaNyeri(), new SkalaNyeri()));
		}
		RiwayatKehamilanPersalinanNifasYangLalu resultModel=riwayatKehamilanPersalinanNifasYangLaluDao.save(model);
			if(CommonUtil.isNotNullOrEmpty(resultModel)){	
				try {
					result.put("riwayatKehamilanPersalinanNifasYangLalu", JsonUtil.ToMap(resultModel));
				} catch (IllegalArgumentException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				}
			}
		}
		return result;
	}

	@Override
	public RiwayatKehamilanPersalinanNifasYangLaluVO add(RiwayatKehamilanPersalinanNifasYangLaluVO vo)
			throws JpaSystemException, ServiceVOException {
		return null;
	}

	@Override
	public RiwayatKehamilanPersalinanNifasYangLaluVO update(RiwayatKehamilanPersalinanNifasYangLaluVO vo)
			throws JpaSystemException, ServiceVOException {
		return null;
	}

	@Override
	public Boolean delete(String key) throws JpaSystemException {
		return null;
	}

	@Override
	public RiwayatKehamilanPersalinanNifasYangLaluVO findById(String key) throws JpaSystemException {
		return null;
	}

	@Override
	public List<RiwayatKehamilanPersalinanNifasYangLaluVO> findAll() throws JpaSystemException {
		return null;
	}

	@Override
	public Map<String, Object> findAllWithPageAndLimitAndSortByAndDirectionParameter(Integer page, Integer limit,
			String sort, String dir) {
		return null;
	}



}
