Update service pelayanan pasien

Pembuatan api pengecekan kode voucher
This commit is contained in:
Salman Manoe 2023-08-21 19:18:16 +07:00
parent acbfe4b2f8
commit 350ed2a2b8
3 changed files with 41 additions and 0 deletions

View File

@ -33,4 +33,6 @@ public interface PelayananPasienService {
List<TagihanPendaftaranDto> tagihan(String noRegistrasi);
void diskonTagihan(String kodeVoucher, List<TagihanPendaftaranDto> dtoList);
boolean isValidVoucher(String kodeVoucher, String noRegistrasi);
}

View File

@ -2284,7 +2284,26 @@ public class PelayananPasienServiceImpl extends BaseVoServiceImpl implements Pel
});
pelayananPasienDao.save(listPelayanan);
}
}
@Override
public boolean isValidVoucher(String kodeVoucher, String noRegistrasi) {
if (kodeVoucher.isEmpty())
throw new ServiceVOException("Kode voucher harus diisi");
VoucherPaket voucher = voucherPaketDao.findByKode(kodeVoucher);
if (CommonUtil.isNullOrEmpty(voucher))
throw new ServiceVOException("Kode voucher tidak ditemukan");
if (voucher.getTmt().after(new Date()))
throw new ServiceVOException("Kode voucher baru dapat dipakai mulai "
+ new SimpleDateFormat("dd MMMM yyyy HH:mm:ss", new Locale("in", "ID")).format(voucher.getTmt()));
if (voucher.getTglKedaluwarsa().before(new Date()))
throw new ServiceVOException("Kode voucher sudah kedaluwarsa pada "
+ new SimpleDateFormat("dd MMMM yyyy HH:mm:ss", new Locale("in", "ID"))
.format(voucher.getTglKedaluwarsa()));
PasienDaftar pendaftaran = pasienDaftarDao.findByNoRegistrasi(noRegistrasi);
if (CommonUtil.isNotNullOrEmpty(pendaftaran) && !pendaftaran.getPasien().getId().equals(voucher.getPasienId()))
throw new ServiceVOException("Kode voucher tidak sesuai dengan pasien yang diperuntukkan");
return true;
}
}

View File

@ -237,4 +237,24 @@ public class PelayananController extends LocaleController<PelayananPasienVO> {
return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
}
}
@RequestMapping(value = "/vouchers/validity", method = RequestMethod.GET)
public ResponseEntity<Object> 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 exception {} when check voucher validity", e.getMessage());
Map<String, String> error = new HashMap<>();
error.put("bad_request", e.getMessage());
return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, error);
} catch (JpaSystemException jse) {
LOGGER.error("Got exception {} when check voucher validity", jse.getMessage());
addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
}
}
}