
package com.jasamedika.medifirst2000.controller;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.service.GenericViewService;
import com.jasamedika.medifirst2000.vo.GenericViewVO;
import com.jasamedika.medifirst2000.vo.PapAlergiVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

import static com.jasamedika.medifirst2000.util.DateUtil.toDate;
import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;

/**
 * Controller class for Pengakjian Awal Gawat Darurat Business
 * 
 * @author Askur
 */
@RestController
@RequestMapping("/papgeneric")
@JsonIgnoreProperties(ignoreUnknown = true)
public class PapGenericController extends LocaleController<PapAlergiVO> {

	@Autowired
	private GenericViewService<GenericViewVO> genericViewService;

	@RequestMapping(value = "/find-medical-record-noRec/", method = GET, produces = 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);
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/check-input-pasien/", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> cekInputPasien(
			@RequestParam(value = "noRec", required = false) String noRec, HttpServletRequest request) {
		Map<String, Object> result = new HashMap<>();
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-noCm-and-tglInput/", method = GET, produces = 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, toDate(tglInput));
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-tglInput/", method = GET, produces = 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, toDate(from), toDate(until), key);
		} else
			result = genericViewService.findMedicalRecordByTglInput(i, toDate(from), toDate(until));
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/find-noCm-and-tglInput/", method = GET, produces = 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, toDate(tglInput));
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/find-noCm/", method = GET, produces = 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 getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-noRec-and-tglinput/", method = GET, produces = 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, toDate(tglInput));
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-noRec-and-tglinput-pasien/", method = GET, produces = 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,
				toDate(tglInput));
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-noRec-antrian-pasien-diperiksa/", method = GET, produces = 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);
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

	@RequestMapping(value = "/find-medical-record-noRec-pasien-antrian-pasien-diperiksa/", method = GET, produces = 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);
		return getJsonResponse(result, OK, mapHeaderMessage);
	}

}
