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.converter.BaseConverterImpl;
import com.jasamedika.medifirst2000.converter.StatusLukaLesiPendarahanConverter;
import com.jasamedika.medifirst2000.converter.TransportasiPasienConverter;
import com.jasamedika.medifirst2000.dao.RegistrasiGawatDaruratDetailDao;
import com.jasamedika.medifirst2000.entities.JenisNyeri;
import com.jasamedika.medifirst2000.entities.PasienDaftar;
import com.jasamedika.medifirst2000.entities.RegistrasiGawatDaruratDetail;
import com.jasamedika.medifirst2000.entities.RisikoJatuh;
import com.jasamedika.medifirst2000.entities.StatusLukaLesiPendarahan;
import com.jasamedika.medifirst2000.entities.TransportasiPasien;
import com.jasamedika.medifirst2000.service.RegistrasiGawatDaruratDetailService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.JenisNyeriVO;
import com.jasamedika.medifirst2000.vo.RegistrasiPasienGawatDaruratVO;
import com.jasamedika.medifirst2000.vo.RisikoJatuhVO;


/**
 * Implement class for PasienService
 * 
 * @author Adik
 * @param <T>
 */


@Service("registrasiGawatDaruratDetailService")
public class RegistrasiGawatDaruratDetailServiceImpl extends BaseVoServiceImpl implements RegistrasiGawatDaruratDetailService {

	@Autowired
	private RegistrasiGawatDaruratDetailDao registasiGawatDaruratDetailDao;
	
	@Autowired
	private TransportasiPasienConverter transportasiPasienConverter;
	
	@Autowired
	private StatusLukaLesiPendarahanConverter statusLukaLesiPendarahanConverter;
	
	@Autowired
	private BaseConverterImpl<JenisNyeriVO, JenisNyeri> jenisNyeriConverter;

	@Autowired
	private BaseConverterImpl<RisikoJatuhVO, RisikoJatuh> risikoJatuhConverter;

	@Override
	public Map<String, Object> saveRegistrasiPasienGawatDaruratDetail(PasienDaftar pasienDaftar,RegistrasiPasienGawatDaruratVO vo) {
		RegistrasiGawatDaruratDetail registrasiGawatDaruratDetail=new RegistrasiGawatDaruratDetail();
		registrasiGawatDaruratDetail.setDefibrasi(vo.getDefibrasi());
		registrasiGawatDaruratDetail.setBerikanOksigen(vo.getBerikanOksigen());
		registrasiGawatDaruratDetail.setLainnya(vo.getLainnya());
		registrasiGawatDaruratDetail.setTempatKejadian(vo.getTempatKejadian());
		registrasiGawatDaruratDetail.setPasangEtt(vo.getPasangEtt());
		registrasiGawatDaruratDetail.setPasangInfus1(vo.getPasangInfus1());
		registrasiGawatDaruratDetail.setPasienDaftar(pasienDaftar);
		if(CommonUtil.isNotNullOrEmpty(vo.getStatusLukaLesiPendarahan())){
			registrasiGawatDaruratDetail.setStatusLukaLesiPendarahan(statusLukaLesiPendarahanConverter.transferVOToModel(vo.getStatusLukaLesiPendarahan(), new StatusLukaLesiPendarahan()));
		}
		
		if(CommonUtil.isNotNullOrEmpty(vo.getTransportasiPasien())){
			registrasiGawatDaruratDetail.setTransportasiPasien(transportasiPasienConverter.transferVOToModel(vo.getTransportasiPasien(), new TransportasiPasien()));
		}
		//add by askur 02120216
		registrasiGawatDaruratDetail.setSkorNyeri(vo.getSkorNyeri());
		registrasiGawatDaruratDetail.setLokasi(vo.getLokasi());
		registrasiGawatDaruratDetail.setDurasi(vo.getDurasi());
		registrasiGawatDaruratDetail.setPencetus(vo.getPencetus());
		registrasiGawatDaruratDetail.setIsDeathOnArrival(vo.getIsDeathOnArrival());
		registrasiGawatDaruratDetail.setIsapLendir(vo.getIsapLendir());
		registrasiGawatDaruratDetail.setPasangOroPharingAirway(vo.getPasangOroPharingAirway());
		registrasiGawatDaruratDetail.setAturPosisi1(vo.getAturPosisi1());
		registrasiGawatDaruratDetail.setAturPosisi2(vo.getAturPosisi2());
		registrasiGawatDaruratDetail.setMonitorIntakeOuttake(vo.getMonitorIntakeOuttake());
		registrasiGawatDaruratDetail.setMonitorTtv(vo.getMonitorTtv());
		registrasiGawatDaruratDetail.setSpO2(vo.getSpO2());
		if(CommonUtil.isNotNullOrEmpty(vo.getJenisNyeri())){
		registrasiGawatDaruratDetail.setJenisNyeri(jenisNyeriConverter.transferVOToModel(vo.getJenisNyeri(),new JenisNyeri()));
		}
		if(CommonUtil.isNotNullOrEmpty(vo.getJenisNyeri())){
		registrasiGawatDaruratDetail.setRisikoJatuh(risikoJatuhConverter.transferVOToModel(vo.getRisikoJatuh(),new RisikoJatuh()));
		}
		//
		RegistrasiGawatDaruratDetail model=registasiGawatDaruratDetailDao.save(registrasiGawatDaruratDetail);
		Map<String,Object>result=new HashMap<String,Object>();
		result.put("registrasiGawatDaruratDetail", model);
		return result;
	}
	
	
	


}
