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

import com.jasamedika.medifirst2000.converter.PapInstruksiRanapConverter;
import com.jasamedika.medifirst2000.dao.PapInstruksiRanapDao;
import com.jasamedika.medifirst2000.entities.PapInstruksiRanap;
import com.jasamedika.medifirst2000.entities.PapKeluhanUtama;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.PapInstruksiRanapService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.PapInstruksiRanapVO;

/**
 * Implement class for PapInstruksiRanapService
 * 
 * @author Askur
 */
@Service("PapInstruksiRanapService")
public class PapInstruksiRanapServiceImpl implements PapInstruksiRanapService {
	@Autowired
	private PapInstruksiRanapDao PapInstruksiRanapDao;
	@Autowired
	private PapInstruksiRanapConverter PapInstruksiRanapConverter;
	
	@Override
	public Map<String,Object> addInstruksiRanap(PapInstruksiRanapVO vo) throws JpaSystemException, ServiceVOException {
		Map<String,Object> result=new HashMap<String,Object>();
		PapInstruksiRanap model=PapInstruksiRanapConverter.transferVOToModel(vo, new PapInstruksiRanap());
		PapInstruksiRanap resultModel=PapInstruksiRanapDao.save(model);
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("noRec", resultModel.getNoRec());
			result.put("tglInput", resultModel.getTglInput());
			if(CommonUtil.isNotNullOrEmpty(resultModel.getPasien().getId())){
				result.put("pasien.noCm", resultModel.getPasien().getNoCm());
			}
		}
		return result;
	}

	@Override
	public Map<String,Object> updateInstruksiRanap(PapInstruksiRanapVO vo) throws JpaSystemException, ServiceVOException {
		Map<String,Object> result=new HashMap<String,Object>();
		PapInstruksiRanap model=PapInstruksiRanapDao.findOne(vo.getNoRec());
		PapInstruksiRanap resultModel=PapInstruksiRanapDao.save(model);
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("noRec", resultModel.getNoRec());
			result.put("tglInput", resultModel.getTglInput());
			result.put("dataFound", true);
			if(CommonUtil.isNotNullOrEmpty(resultModel.getPasien().getId())){
				result.put("pasien.noCm", resultModel.getPasien().getNoCm());
			}
		}else{
			result.put("dataFound", false);
		}
		return result;
	}

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

	@Override
	public Map<String,Object> findByNoCmAndTglInput(String noCm, Date tglInput) {
		Map<String,Object> result=new HashMap<String,Object>();
		PapInstruksiRanap resultModel=PapInstruksiRanapDao.findPapInstruksiRanapByNoCmAndTglInput(noCm, tglInput);
		if(CommonUtil.isNotNullOrEmpty(resultModel)){
			result.put("noRec", resultModel.getNoRec());
			result.put("tglInput", resultModel.getTglInput());
			result.put("dataFound", true);
			if(CommonUtil.isNotNullOrEmpty(resultModel.getPasien().getId())){
				result.put("pasien.noCm", resultModel.getPasien().getNoCm());
			}
		}else{
			result.put("dataFound", false);
		}
		return result;
	}

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

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

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

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

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



}
