package com.jasamedika.medifirst2000.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

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

import com.jasamedika.medifirst2000.converter.AsesmenGiziLanjutConverter;
import com.jasamedika.medifirst2000.converter.KasusPenyakitConverter;
import com.jasamedika.medifirst2000.converter.RuanganConverter;
import com.jasamedika.medifirst2000.dao.AntrianPasienDiPeriksaDao;
import com.jasamedika.medifirst2000.dao.AsesmenGiziLanjutDao;
import com.jasamedika.medifirst2000.entities.AsesmenGiziLanjut;
import com.jasamedika.medifirst2000.entities.KasusPenyakit;
import com.jasamedika.medifirst2000.entities.Ruangan;
import com.jasamedika.medifirst2000.service.AsesmenGiziLanjutService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.AsesmenGiziLanjutVO;

@Service("asesmenGiziLanjutService")
public class AsesmenGiziLanjutServiceImpl extends BaseVoServiceImpl implements AsesmenGiziLanjutService {

	@Autowired
	private AsesmenGiziLanjutDao asesmenGiziLanjutDao;
	@Autowired
	private AntrianPasienDiPeriksaDao antrianPasienDiPeriksaDao;
	@Autowired
	private AsesmenGiziLanjutConverter asesmenGiziLanjutConverter;

	@Autowired
	private RuanganConverter ruanganConverter;

	@Autowired
	private KasusPenyakitConverter kasusPenyakitConverter;

	@Override
	public Map<String, Object> saveAsesmenGiziLanjut(AsesmenGiziLanjutVO vo) {

		AsesmenGiziLanjut asesmenGiziLanjut = asesmenGiziLanjutConverter.transferVOToModel(vo, new AsesmenGiziLanjut());
		asesmenGiziLanjut.setPasien(antrianPasienDiPeriksaDao.findByNoRec(vo.getPasien().getNoRec()));

		AsesmenGiziLanjut resultAsesmenGiziLanjut = asesmenGiziLanjutDao.save(asesmenGiziLanjut);
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("noRec", resultAsesmenGiziLanjut.getNoRec());

		return result;

	}

	@Override
	public Map<String, Object> updateAsesmenGiziLanjut(AsesmenGiziLanjutVO vo) {

		Map<String, Object> result = new HashMap<String, Object>();
		AsesmenGiziLanjut model = asesmenGiziLanjutDao.findOne(vo.getNoRec());
		model = asesmenGiziLanjutConverter.transferVOToModel(vo, model);
		AsesmenGiziLanjut resultModel = asesmenGiziLanjutDao.save(model);
		if (CommonUtil.isNotNullOrEmpty(resultModel)) {
			result.put("id", resultModel.getNoRec());
		}
		return result;
	}

	@Override
	public Map<String, Object> findByNoRegistrasi(String noRegistrasi) {

		Map<String, Object> result = new HashMap<String, Object>();
		AsesmenGiziLanjut resultModel = asesmenGiziLanjutDao.findAsesmenGiziLanjutByNoRegistrasi(noRegistrasi);
		if (CommonUtil.isNotNullOrEmpty(resultModel)) {
			result.put("noRec", resultModel.getNoRec());
			result.put("pasien", resultModel.getPasien());
			result.put("dataFound", true);
			if (CommonUtil.isNotNullOrEmpty(resultModel.getPasien().getPasienDaftar().getPasienId())) {
				result.put("pasien.noRegistrasi", resultModel.getPasien().getPasienDaftar().getNoRegistrasi());
			}
		} else {
			result.put("dataFound", false);
		}
		return result;
	}

}
