package com.jasamedika.medifirst2000.service.impl;

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

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

import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
import com.jasamedika.medifirst2000.entities.AntrianPasienRegistrasi;
import com.jasamedika.medifirst2000.entities.PasienDaftar;
import com.jasamedika.medifirst2000.entities.StrukRetur;
import com.jasamedika.medifirst2000.service.AntrianPasienDiPeriksaService;
import com.jasamedika.medifirst2000.service.AntrianPasienRegistrasiService;
import com.jasamedika.medifirst2000.service.PasienDaftarService;
import com.jasamedika.medifirst2000.service.PembatalanPasienService;
import com.jasamedika.medifirst2000.service.StrukReturService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.PembatalanPasienRegistrasiVO;


/**
 * Implement class for RegistrasiPasienService
 * 
 * @author Adik
 * @param <T>
 */
@Service("pembatalanPasienService")
public class PembatalanPasienServiceImpl implements PembatalanPasienService {
	
	@Autowired
	private StrukReturService strukReturService;
	
	@Autowired
	private AntrianPasienDiPeriksaService antrianPasienDiPeriksaService;
	
	@Autowired
	private AntrianPasienRegistrasiService antrianPasienRegistrasiService;

	@Override
	public Map<String, Object> savePembatalanPasienRegistrasi(PembatalanPasienRegistrasiVO vo) {
		StrukRetur model=new StrukRetur();
		model.setNoRetur(strukReturService.getFormatNumberByMonthYear(vo.getTglRetur()));
		model.setKeteranganAlasan(vo.getKeteranganAlasan());
		model.setKeteranganLainnya(vo.getKeteranganaLainnya());
		model.setTglRetur(vo.getTglRetur());
		Map<String,Object> resultStrukOrder=strukReturService.saveStrukOrder(model);
		StrukRetur strukRetur=(StrukRetur) resultStrukOrder.get("strukRetur");
		
		Map<String,Object> resultMessages=new HashMap<String,Object>();
		if(CommonUtil.isNotNullOrEmpty(vo.getAntrianPasienDiPeriksa().getNoRec())){
			Map<String,Object> resultAntrianPasienDiPeriksa=antrianPasienDiPeriksaService.updateAntrianPasienDiperiksaFromPembatalanPasien(strukRetur,vo.getAntrianPasienDiPeriksa().getNoRec());
			AntrianPasienDiPeriksa antrianPasienDiPeriksa=(AntrianPasienDiPeriksa) resultAntrianPasienDiPeriksa.get("antrianPasienDiperiksa");
			
			resultMessages.put("noRetur", strukRetur.getNoRetur());
			resultMessages.put("noAntrian", antrianPasienDiPeriksa.getNoAntrian());
		}else if(CommonUtil.isNotNullOrEmpty(vo.getAntrianPasienRegistrasi().getNoRec())){
			Map<String,Object> resultAntrianPasienRegistrasi=antrianPasienRegistrasiService.updateAntrianPasienRegistrasiFromPembatalanPasien(strukRetur,vo.getAntrianPasienRegistrasi().getNoRec());
			AntrianPasienRegistrasi antrianPasienRegistrasi=(AntrianPasienRegistrasi) resultAntrianPasienRegistrasi.get("antrianPasienRegistrasi");
			
			resultMessages.put("noRetur", strukRetur.getNoRetur());
			resultMessages.put("noAntrian",antrianPasienRegistrasi.getNoAntrian());
		}
		
		return resultMessages;
		
	}

	
}
