package com.jasamedika.medifirst2000.controller; import com.jasamedika.medifirst2000.constants.Constants; import com.jasamedika.medifirst2000.constants.MessageResource; import com.jasamedika.medifirst2000.controller.base.LocaleController; import com.jasamedika.medifirst2000.core.web.WebConstants; import com.jasamedika.medifirst2000.dto.BatalPaketProdukDto; import com.jasamedika.medifirst2000.dto.TagihanPendaftaranDto; import com.jasamedika.medifirst2000.exception.ServiceVOException; import com.jasamedika.medifirst2000.service.*; import com.jasamedika.medifirst2000.util.rest.RestUtil; import com.jasamedika.medifirst2000.vo.MapProdukPaketToProdukVO; import com.jasamedika.medifirst2000.vo.MapProdukPaketVO; import com.jasamedika.medifirst2000.vo.PelayananPasienVO; 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.*; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; import java.util.List; import java.util.Map; @RestController @RequestMapping("/pelayanan") public class PelayananController extends LocaleController { private static final Logger LOGGER = LoggerFactory.getLogger(PelayananController.class); @Autowired private PelayananPasienService pelayananPasienService; @Autowired private PasienDaftarService pasienDaftarService; @Autowired private ProdukService produkService; @Autowired private SatuanStandarService satuanStandarService; @Autowired private MapProdukPaketService mapProdukPaketService; @Autowired private MapProdukPaketToProdukService mapProdukPaketToProdukService; @RequestMapping(value = "/calculate-indikator-pelayanan", method = RequestMethod.GET) public ResponseEntity>> calculateIndikatorPelayanan(HttpServletRequest request, @RequestParam("tahun") String tahun) { try { List> result = pasienDaftarService.findIndikatorPelayanan(tahun); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException sve) { LOGGER.error("Got ServiceVOException {} when calculate indikator pelayanan", sve.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, sve.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when calculate indikator pelayanan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/validate-nama-produk", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> validateNamaProduk(HttpServletRequest request, @RequestParam(value = "idProduk", required = false) Integer idProduk, @RequestParam(value = "namaProduk") String namaProduk) { try { Map result = produkService.validateNamaProduk(idProduk, namaProduk); return RestUtil.getJsonResponse(result, HttpStatus.OK); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when validate nama produk", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when validate nama produk", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/paket-to-produk", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity> getMappingPaketToProduk(HttpServletRequest request, @RequestParam(value = "idMapping") Integer idMapping) { try { Map result = produkService.getMappingPaketToProduk(idMapping); return RestUtil.getJsonResponse(result, HttpStatus.OK); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when get mapping paket to produk", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when get mapping paket to produk", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/all-paket-produk", method = RequestMethod.GET) public ResponseEntity>> getAllPaketToProduk(HttpServletRequest request) { try { List> result = produkService.getAllPaketToProduk(); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException sve) { LOGGER.error("Got ServiceVOException {} when get all data paket to produk", sve.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, sve.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when get all data paket to produk", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/master-satuan-standar", method = RequestMethod.GET) public ResponseEntity>> getAllMasterSatuanStandar(HttpServletRequest request) { try { List> result = satuanStandarService.getAll(); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException sve) { LOGGER.error("Got ServiceVOException {} when get all master satuan standar distinct on", sve.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, sve.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when get all master satuan standar distinct on", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/klaim-diskon", method = RequestMethod.GET) public ResponseEntity> KlaimDiskon(HttpServletRequest request, @RequestParam(value = "noRegistrasi") String noRegistrasi, @RequestParam(value = "totalKlaim") Double totalKlaim, @RequestParam(value = "jenisDiskon") Integer jenisDiskon) { try { List result = pelayananPasienService.updateKlaimDiskon(noRegistrasi, totalKlaim, jenisDiskon); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when klaim diskon karyawan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when klaim diskon karyawan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/reset-klaim-diskon", method = RequestMethod.GET) public ResponseEntity ResetKlaimDiskon(HttpServletRequest request, @RequestParam(value = "noRegistrasi") String noRegistrasi) { try { String result = pelayananPasienService.resetKlaimDiskon(noRegistrasi); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when reset klaim diskon karyawan", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when reset klaim diskon karyawan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/check-existing-harga-produk-kelas", method = RequestMethod.GET) public ResponseEntity>> checkExistingHargaProdukKelas(HttpServletRequest request, @RequestParam(value = "kelasId") Integer idKelas, @RequestParam(value = "produkId") Integer idProduk, @RequestParam(value = "mappingId", required = false) Integer idMapping) { try { List> result = produkService.findExistingMapHargaKelas(idKelas, idProduk, idMapping); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when check existing harga produk kelas", e.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when check existing harga produk kelas", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/tagihan/daftar/{noRegistrasi}", method = RequestMethod.GET) public ResponseEntity> daftarTagihan(HttpServletRequest request, @PathVariable String noRegistrasi) { try { List result = pelayananPasienService.tagihan(noRegistrasi); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(result, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when get daftar tagihan {}", e.getMessage(), noRegistrasi); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when get daftar tagihan {}", jse.getMessage(), noRegistrasi); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/tagihan/diskon/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity simpanDiskonTagihan(HttpServletRequest request, @RequestParam(value = "kode-voucher", required = false) String kodeVoucher, @RequestBody List dtoList) { try { pelayananPasienService.diskonTagihan(kodeVoucher, dtoList); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(dtoList, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when simpan diskon tagihan", e.getMessage()); Map error = new HashMap<>(); error.put("bad_request", e.getMessage()); return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, error); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when simpan diskon tagihan", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/tagihan/diskon/batal-paket", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity batalPaket(HttpServletRequest request, @RequestBody BatalPaketProdukDto dto) { try { pelayananPasienService.batalPaketProduk(request, dto); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(dto, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when batal diskon paket", e.getMessage()); Map error = new HashMap<>(); error.put("bad_request", e.getMessage()); return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, error); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when batal diskon paket", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/vouchers/validity", method = RequestMethod.GET) public ResponseEntity isValidVoucher(HttpServletRequest request, @RequestParam("kode-voucher") String kodeVoucher, @RequestParam("no-registrasi") String noRegistrasi) { try { boolean validVoucher = pelayananPasienService.isValidVoucher(kodeVoucher, noRegistrasi); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(validVoucher, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when check voucher validity", e.getMessage()); Map error = new HashMap<>(); error.put("bad_request", e.getMessage()); return RestUtil.getJsonResponse(false, HttpStatus.BAD_REQUEST, error); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when check voucher validity", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/produk-paket/paket", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity simpanMappingListProdukPaket(HttpServletRequest request, @RequestBody List vos) { try { mapProdukPaketService.saveAll(vos); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(vos, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when simpan mapping list produk paket", e.getMessage()); Map error = new HashMap<>(); error.put("bad_request", e.getMessage()); return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, error); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when simpan mapping list produk paket", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } @RequestMapping(value = "/produk-paket/produk", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity simpanMappingEntriProdukPaket(HttpServletRequest request, @RequestBody List vos) { try { mapProdukPaketToProdukService.saveAll(vos); mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request)); return RestUtil.getJsonResponse(vos, HttpStatus.OK, mapHeaderMessage); } catch (ServiceVOException e) { LOGGER.error("Got ServiceVOException {} when simpan mapping entri produk paket", e.getMessage()); Map error = new HashMap<>(); error.put("bad_request", e.getMessage()); return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, error); } catch (JpaSystemException jse) { LOGGER.error("Got JpaSystemException {} when simpan mapping entri produk paket", jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); } } }