package com.jasamedika.medifirst2000.service.impl;

import java.util.Date;
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.RehabilitasiAsesmenDao;
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
import com.jasamedika.medifirst2000.entities.RehabilitasiAsesmen;
import com.jasamedika.medifirst2000.service.RehabilitasiAsesmenService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.AntrianPasienDiPeriksaVO;
import com.jasamedika.medifirst2000.vo.RehabilitasiAsesmenVO;

@Service("RehabilitasiAsesmenService")
public class RehabilitasiAsesmenServiceImpl implements RehabilitasiAsesmenService{
	
	@Autowired
	BaseConverterImpl<RehabilitasiAsesmenVO, RehabilitasiAsesmen> rehabilitasiAsesmenConverter;
	
	@Autowired
	BaseConverterImpl<AntrianPasienDiPeriksaVO, AntrianPasienDiPeriksa> antrianPasienDiPeriksaConverter;
	
	@Autowired
	RehabilitasiAsesmenDao rehabilitasiAsesmenDao;

	@Override
	public Map<String, Object> saveRehabilitasiAsesmen(RehabilitasiAsesmenVO vo) {
		Map<String, Object> result = new HashMap<String, Object>();
		if(CommonUtil.isNotNullOrEmpty(vo))
		{
			RehabilitasiAsesmen rehabilitasiAsesmen = rehabilitasiAsesmenConverter.transferVOToModel(vo, new RehabilitasiAsesmen());
			if(CommonUtil.isNotNullOrEmpty(vo.getPasienDaftar()))
			{
				AntrianPasienDiPeriksa antrianPasienDiPeriksa = antrianPasienDiPeriksaConverter.transferVOToModel(vo.getPasienDaftar(), new AntrianPasienDiPeriksa());
				rehabilitasiAsesmen.setPasien(antrianPasienDiPeriksa);
			}
			if(CommonUtil.isNotNullOrEmpty(vo.getNoRec()))
			{
				rehabilitasiAsesmen.setNoRec(vo.getNoRec());
			}
			if(CommonUtil.isNotNullOrEmpty(rehabilitasiAsesmen))
			{
				rehabilitasiAsesmen.setTglInput(new Date());
				rehabilitasiAsesmen.setStatusEnabled(true);
				rehabilitasiAsesmen.setKdProfile((short)0);
				RehabilitasiAsesmen model = rehabilitasiAsesmenDao.save(rehabilitasiAsesmen);
				result.put("noRec", model.getNoRec());
			}
		}
		return result;
	}

	@Override
	public List<Map<String, Object>> getListRehabilitasiAsesmen(String norecAntrian) {
		List<Map<String, Object>> result = rehabilitasiAsesmenDao.getListRehabilitasiAsesmen(norecAntrian);
		return result;		
	}

	@Override
	public Map<String, Object> getRehabilitasiAsesmen(String norec) {
		Map<String, Object> result = rehabilitasiAsesmenDao.getRehabilitasiAsesmen(norec);
		return result;
	}

}
