
package com.jasamedika.medifirst2000.controller;

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

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.jasamedika.medifirst2000.constants.Constants;
import com.jasamedika.medifirst2000.constants.MessageResource;
import com.jasamedika.medifirst2000.controller.base.IBaseRestController;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.core.web.WebConstants;
import com.jasamedika.medifirst2000.dao.PapAlergiDao;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.GenericViewService;
import com.jasamedika.medifirst2000.service.PapAlergiService;
import com.jasamedika.medifirst2000.util.DateUtil;
import com.jasamedika.medifirst2000.util.rest.RestUtil;
import com.jasamedika.medifirst2000.vo.PapAlergiVO;
import com.jasamedika.medifirst2000.vo.PapSkriningNyeriVO;

/**
 * Controller class for Pengakjian Awal Gawat Darurat Business
 * 
 * @author Askur
 */
@RestController
@RequestMapping("/papgeneric")
@JsonIgnoreProperties(ignoreUnknown = true) 
public class PapGenericController extends LocaleController<PapAlergiVO> implements
		IBaseRestController<PapAlergiVO> {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(PapGenericController.class);

	@Autowired
	private GenericViewService genericViewService;

	@Autowired
	private PapAlergiDao papAlergiDao;
	
	@RequestMapping(value = "/find-medical-record-noRec/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findMedicalRecordByNoRec(@RequestParam(value = "i", required = false) String i,@RequestParam(value = "noRec", required = false) String noRec,
			HttpServletRequest request) {
		Map<String,Object> result = genericViewService.findMedicalRecordByNoRec(i,noRec);
		Integer data =papAlergiDao.findByCountAntrian(noRec);
		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}
	@RequestMapping(value = "/check-input-pasien/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> cekInputPasien(@RequestParam(value = "noRec", required = false) String noRec,
			HttpServletRequest request) {
		Map<String,Object> result = new HashMap<>();
		/*result.put("Alergi", genericViewService.findByCountAntrian("PapAlergi",noRec));
		result.put("RiwayatKesehatan", genericViewService.findByCountAntrian("RiwayatKesehatan",noRec));
		//result.put("RiwayatPemeriksaan", genericViewService.findByCountAntrian("PapTandaVital",noRec));
		//result.put("SkriningNyeri", genericViewService.findByCountAntrian("PapSkriningNyeri",noRec));
		result.put("KebutuhanEdukasi", genericViewService.findByCountAntrian("PapKebutuhanEdukasi",noRec));
		result.put("MasalahKeperawatan", genericViewService.findByCountAntrian("MasalahKeperawatan",noRec));
		result.put("RiwayatPsikososial", genericViewService.findByCountAntrian("PapRiwayatPsikososial",noRec));
		result.put("RiwayatKelahiran", genericViewService.findByCountAntrian("PapRiwayatKelahiran",noRec));
		result.put("KeluhanUtama", genericViewService.findByCountAntrian("PapRiwayatKelahiran",noRec));*/
		
		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}
	
	
	@RequestMapping(value = "/find-medical-record-noCm-and-tglInput/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findMedicalRecordByNoCmAndTglInput(@RequestParam(value = "i", required = false) String i,@RequestParam(value = "noCm", required = false) String noCm,
			@RequestParam(value = "tglInput", required = false) String tglInput,HttpServletRequest request) {
		Map<String,Object> result = genericViewService.findMedicalRecordByNoCmAndTglInput(i,noCm, DateUtil.toDate(tglInput));

		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}
	@RequestMapping(value = "/find-medical-record-tglInput/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findMedicalRecordByTglInput(@RequestParam(value = "i", required = false) String i,
			@RequestParam(value = "from", required = false) String from,@RequestParam(value = "until", required = false) String until,
			@RequestParam(value = "key", required = false) String key,HttpServletRequest request) {
		Map<String,Object> result ;
		if(key!=null)
		{
			result=genericViewService.findMedicalRecordByTglInput(i, DateUtil.toDate(from), DateUtil.toDate(until),key);	
		}
		else
		result=genericViewService.findMedicalRecordByTglInput(i, DateUtil.toDate(from), DateUtil.toDate(until));

		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}
	
	
	@RequestMapping(value = "/find-noCm-and-tglInput/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findByNoCmAndTglInput(@RequestParam(value = "i", required = false) String i,@RequestParam(value = "noCm", required = false) String noCm,
			@RequestParam(value = "tglInput", required = false) String tglInput,HttpServletRequest request) {
		Map<String,Object> result = genericViewService.findByNoCmAndTglInput(i,noCm, DateUtil.toDate(tglInput));
	

		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}
	@RequestMapping(value = "/find-noCm/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findByNoCm(@RequestParam(value = "i", required = false) String i,@RequestParam(value = "noCm", required = false) String noCm,
			HttpServletRequest request) {
		Map<String,Object> result = genericViewService.findByNoCmAnd(i,noCm);
	

		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}
	@RequestMapping(value = "/find-medical-record-noRec-and-tglinput/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findMedicalRecordByNoRecAndTglInput(@RequestParam(value = "i", required = false) String i,@RequestParam(value = "noRec", required = false) String noRec,
			@RequestParam(value = "tglInput", required = false) String tglInput,
			HttpServletRequest request) {
		Map<String,Object> result = genericViewService.findMedicalRecordByNoRecAndTglInput(i,noRec,DateUtil.toDate(tglInput));
		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-noRec-and-tglinput-pasien/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findMedicalRecordByNoRecAndTglInputPasien(@RequestParam(value = "i", required = false) String i,@RequestParam(value = "noRec", required = false) String noRec,
			@RequestParam(value = "tglInput", required = false) String tglInput,
			HttpServletRequest request) {
		Map<String,Object> result = genericViewService.findMedicalRecordByNoRecAndTglInputPasien(i,noRec,DateUtil.toDate(tglInput));
		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-noRec-antrian-pasien-diperiksa/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findMedicalRecordByNoRecAntrianPasienDiPeriksa(@RequestParam(value = "i", required = false) String i,@RequestParam(value = "noRec", required = false) String noRec,
			HttpServletRequest request) {
		Map<String,Object> result = genericViewService.findMedicalRecordByNoRecAntrianPasienDiPeriksa(i,noRec);
		Integer data =papAlergiDao.findByCountAntrian(noRec);
		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-noRec-pasien-antrian-pasien-diperiksa/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> findMedicalRecordByNoRecPasienAntrianPasienDiPeriksa(@RequestParam(value = "i", required = false) String i,@RequestParam(value = "noRec", required = false) String noRec,
			HttpServletRequest request) {
		Map<String,Object> result = genericViewService.findMedicalRecordByNoRecPasienAntrianPasienDiPeriksa(i,noRec);
		Integer data =papAlergiDao.findByCountAntrian(noRec);
		return RestUtil.getJsonResponse(result, HttpStatus.OK,mapHeaderMessage);
	}

	@Override
	public ResponseEntity<Collection<PapAlergiVO>> getAllVOWithQueryString(HttpServletRequest request,
			Integer page, Integer limit, String sort, String dir) {
		return null;
	}

	@Override
	public ResponseEntity<PapAlergiVO> getVO(Integer id) {
		return null;
	}

	@Override
	public ResponseEntity<String> addVO(PapAlergiVO vo) {
		return null;
	}

	@Override
	public ResponseEntity<String> editVO(PapAlergiVO vo) {
		return null;
	}

	@Override
	public ResponseEntity<String> deleteVO(Integer id) {
		return null;
	}

	@Override
	public ResponseEntity<List<PapAlergiVO>> getAllVO() {
		return null;
	}
	
}
