package com.jasamedika.medifirst2000.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

import com.jasamedika.medifirst2000.dao.PraAnestesiDao;
import com.jasamedika.medifirst2000.entities.PraAnestesi;
import com.jasamedika.medifirst2000.service.PraAnestesiService;
import com.jasamedika.medifirst2000.util.CommonUtil;
import com.jasamedika.medifirst2000.vo.PraAnestesiVO;

@Service("PraAnestesiService")
public class PraAnestesiServiceImpl implements PraAnestesiService {
	@Autowired
	private PraAnestesiDao praAnestesiDao;

	@Override
	public Map<String, Object> getPraAnestesiPasien() {
		Map<String, Object> result = new HashMap<>();
		
		List<Map<String, Object>> listData = this.praAnestesiDao.getPraAnestesiPasien();
		
		if(CommonUtil.isNotNullOrEmpty(listData)){
			result.put("listData", listData);
		}
		return result;
	}

	
	public Map<String, Object> getPasienByRencanaOperasi() {
		Map<String, Object> result = new HashMap<>();
		
		List<Map<String, Object>> listData = this.praAnestesiDao.getPasienByRencanaOperasi();
		
		if(CommonUtil.isNotNullOrEmpty(listData)){
			result.put("listData", listData);
		}
		return result;
	}

	
	public Map<String, Object> getPasienById(int id) {
		Map<String, Object> result = new HashMap<>();
		
		Map<String, Object> listData = this.praAnestesiDao.getPasienById(id);
		
		if(CommonUtil.isNotNullOrEmpty(listData)){
			result.put("listData", listData);
		}
		return result;
	}


	//show data pra-anestesi/sedasi
	//perawat
	@Override
	public Map<String, Object> getPraAnestesiPerawat() {
		Map<String, Object> result = new HashMap<>();
		List<Map<String, Object>> listData = new ArrayList<>();
		
		//show data Kajian Sistem dan Pemerikssaan fisik
		try {
			Map<String, Object> mapMain = new HashMap<>();
			List<Map<String, Object>> listMain = new ArrayList<>();
			List<Map<String, Object>> perawatheader = this.praAnestesiDao.getPraAnestesiPerawatHeader();
			
			for(Map<String, Object> data : perawatheader) {
				
				Map<String, Object> tempMap = new HashMap<>();
				List<Map<String, Object>> datailList = new ArrayList<>();
				
				List<Map<String, Object>> perawatdetail = this.praAnestesiDao.getPraAnestesiPerawatDetail((Integer) data.get("id"));
				tempMap.put("id", data.get("id"));
				tempMap.put("namaExternal", data.get("namaExternal"));
				
				for(Map<String, Object> datadetail : perawatdetail) {
					Map<String, Object> tempdetailMap = new HashMap<>();
					List<Map<String, Object>> detaildetailList = new ArrayList<>();
			
					List<Map<String, Object>> pemeriksaan = this.praAnestesiDao.getPraAnestesiPerawatDetailLevel1((Integer) datadetail.get("id"));
					tempdetailMap.put("id", datadetail.get("id"));
					tempdetailMap.put("namaExternal", datadetail.get("namaExternal"));
					
					for(Map<String, Object> datadetaildetail : pemeriksaan) {
						Map<String, Object> tempdetaildetailMap = new HashMap<>();
						
						List<Map<String, Object>> detaildetail = this.praAnestesiDao.getPraAnestesiPerawatDetailLevel2((Integer) datadetaildetail.get("id"));
						tempdetaildetailMap.put("id", datadetaildetail.get("id"));
						tempdetaildetailMap.put("namaExternal", datadetaildetail.get("namaExternal"));
						tempdetaildetailMap.put("detaildetail", detaildetail);
						detaildetailList.add(tempdetaildetailMap);
						
					}
					
					//tempdetailMap.put("detail", pemeriksaan);
					tempdetailMap.put("detail", detaildetailList);
					datailList.add(tempdetailMap);
				}
				
				//tempMap.put("detail", perawatdetail);
				tempMap.put("detail", datailList);
				listMain.add(tempMap);
			}
			mapMain.put("header", "Pra-Anestesi/Sedasi Perawat");
			mapMain.put("detail", listMain);
			listData.add(mapMain);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		
		//show data Perencanaan Anestesi dan Sedasi
		//try {
			
			
		//} catch (Exception e) {
		//	e.printStackTrace();
		//}
		
		
		result.put("loadData", listData);
		
		return result;
	}
	
	
	

}
