package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
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.dao.DetailInformasiMedisDao;
import com.jasamedika.medifirst2000.entities.DetailInformasiMedis;
import com.jasamedika.medifirst2000.entities.InformasiMedis;
import com.jasamedika.medifirst2000.entities.TransferPasienExsternal;
import com.jasamedika.medifirst2000.entities.TransferPasienInternal;
import com.jasamedika.medifirst2000.service.DetailInformasiMedisService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.DetailInformasiMedisVO;
import com.jasamedika.medifirst2000.vo.InformasiMedisVO;
import com.jasamedika.medifirst2000.vo.TransferPasienExsternalVO;
import com.jasamedika.medifirst2000.vo.TransferPasienInformasiMedisVO;
import com.jasamedika.medifirst2000.vo.TransferPasienInternalVO;


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


@Service("informasiMedisService")
public class DetailInformasiMedisServiceImpl extends BaseVoServiceImpl implements DetailInformasiMedisService {

	@Autowired
	private DetailInformasiMedisDao detailInformasiMedisDao;
	
	@Autowired
	private BaseConverterImpl<InformasiMedisVO,InformasiMedis> informasiMedisConverter;
	
	@Autowired
	private BaseConverterImpl<DetailInformasiMedisVO,DetailInformasiMedis> detailInformasiMedisConverter;
	
	@Autowired
	private BaseConverterImpl<TransferPasienInternalVO,TransferPasienInternal> transferPasienInternalConverter;
	
	@Autowired
	private BaseConverterImpl<TransferPasienExsternalVO,TransferPasienExsternal> transferPasienExsternalConverter;
	

	@Override
	public Map<String,Object> saveInformasiMedis(TransferPasienInformasiMedisVO vo) {
		ArrayList<String> resultStringArray = new ArrayList<String>();
		for(DetailInformasiMedisVO detailInformasiMedisVO:vo.getDetailInformasiMedis()){
			resultStringArray.add(detailInformasiMedisVO.getInformasiMedis().getId().toString());
			DetailInformasiMedis model=new DetailInformasiMedis();
			
			if(CommonUtil.isNotNullOrEmpty(detailInformasiMedisVO)){
				model=detailInformasiMedisConverter.transferVOToModel(detailInformasiMedisVO, new DetailInformasiMedis());
			}
			
			/*if(CommonUtil.isNotNullOrEmpty(vo.getTransferPasienInternal())){
				model.setTransferPasienInternal(transferPasienInternalConverter.transferVOToModel(vo.getTransferPasienInternal(), new TransferPasienInternal()));
			}*/
			
			if(CommonUtil.isNotNullOrEmpty(vo.getTransferPasienExsternal())){
				model.setTransferPasienExsternal(transferPasienExsternalConverter.transferVOToModel(vo.getTransferPasienExsternal(), new TransferPasienExsternal()));
			}
			
			model.setInformasiMedis(informasiMedisConverter.transferVOToModel(detailInformasiMedisVO.getInformasiMedis(), new InformasiMedis()));
			detailInformasiMedisDao.save(model);
		}
		Map<String,Object>result=new HashMap<String,Object>();
		result.put("result", resultStringArray);
		return result;
	}

	


}
