Update service pelayanan pasien

Penyesuaian diskon paket di verifikasi pasien pulang
This commit is contained in:
Salman Manoe 2023-08-16 15:45:44 +07:00
parent 87e70a29bd
commit c687445e3a
5 changed files with 78 additions and 20 deletions

View File

@ -9,4 +9,12 @@ import org.springframework.data.jpa.repository.JpaRepository;
* @since 16 Aug 2023 * @since 16 Aug 2023
*/ */
public interface VoucherPaketDao extends JpaRepository<VoucherPaket, String> { public interface VoucherPaketDao extends JpaRepository<VoucherPaket, String> {
/**
* Query untuk mendapatkan data voucher paket berdasarkan kode yang diminta
*
* @param kode
* sebuah <code>String</code> 7 karakter kode voucher
* @return data entitas <code>VoucherPaket</code>
*/
VoucherPaket findByKode(String kode);
} }

View File

@ -32,5 +32,5 @@ public interface PelayananPasienService {
List<TagihanPendaftaranDto> tagihan(String noRegistrasi); List<TagihanPendaftaranDto> tagihan(String noRegistrasi);
void diskonTagihan(List<TagihanPendaftaranDto> dtoList); void diskonTagihan(String kodeVoucher, List<TagihanPendaftaranDto> dtoList);
} }

View File

@ -44,7 +44,7 @@ import static com.jasamedika.medifirst2000.constants.Master.TipePegawai.PURNA_WA
/** /**
* Implement class for PelayananPasienService * Implement class for PelayananPasienService
* *
* @author Generator * @author Generator
*/ */
@Service("pelayananPasienService") @Service("pelayananPasienService")
@ -92,6 +92,12 @@ public class PelayananPasienServiceImpl extends BaseVoServiceImpl implements Pel
@Autowired @Autowired
private MapPegawaiLaboratRadiologiDao mapPegawaiLaboratRadiologiDao; private MapPegawaiLaboratRadiologiDao mapPegawaiLaboratRadiologiDao;
@Autowired
private VoucherPaketDao voucherPaketDao;
@Autowired
private MapProdukPaketToProdukDao mapProdukPaketToProdukDao;
@Override @Override
public Map<String, Object> savePelayananPasien(PelayananPasienVO vo) { public Map<String, Object> savePelayananPasien(PelayananPasienVO vo) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
@ -2198,25 +2204,67 @@ public class PelayananPasienServiceImpl extends BaseVoServiceImpl implements Pel
} }
@Override @Override
public void diskonTagihan(List<TagihanPendaftaranDto> dtoList) { public void diskonTagihan(String kodeVoucher, List<TagihanPendaftaranDto> dtoList) {
{ if (CommonUtil.isNullOrEmpty(kodeVoucher)) {
List<Integer> listIdPegawai = mapPegawaiJabatanToUnitKerjaDao.findPegawaiIdByUnitKerjaIdAndJabatanId(48, List<Integer> listIdPegawai = mapPegawaiJabatanToUnitKerjaDao.findPegawaiIdByUnitKerjaIdAndJabatanId(48,
1075); 1075);
boolean accessGranted = loginUserService.accessGranted(loginUserService.getLoginUser(), listIdPegawai); boolean accessGranted = loginUserService.accessGranted(loginUserService.getLoginUser(), listIdPegawai);
if (!accessGranted) if (!accessGranted)
throw new ServiceVOException("Tidak memiliki akses diskon total"); throw new ServiceVOException("Tidak memiliki akses diskon total");
} }
List<String> listNoRec = dtoList.stream().map(TagihanPendaftaranDto::getNoRec).collect(Collectors.toList()); if (CommonUtil.isNotNullOrEmpty(kodeVoucher)) {
List<PelayananPasien> listPelayanan = pelayananPasienDao.findAll(listNoRec); VoucherPaket voucher = voucherPaketDao.findByKode(kodeVoucher);
listPelayanan.forEach(p -> { if (CommonUtil.isNullOrEmpty(voucher))
Optional<TagihanPendaftaranDto> dto = dtoList.stream().filter(d -> d.getNoRec().equals(p.getNoRec())) throw new ServiceVOException("Kode voucher tidak ditemukan");
.findFirst(); if (voucher.getTglKedaluwarsa().before(new Date()))
dto.ifPresent(tagihanPendaftaranDto -> { throw new ServiceVOException("Kode voucher sudah kedaluwarsa pada "
p.setHargaDiscount(tagihanPendaftaranDto.getHargaDiskon()); + new SimpleDateFormat("dd MMMM yyyy HH:mm:ss", new Locale("in", "ID"))
p.setJasa(tagihanPendaftaranDto.getHargaJasa()); .format(voucher.getTglKedaluwarsa()));
List<String> listNoRec = dtoList.stream().filter(TagihanPendaftaranDto::getIsPaket)
.map(TagihanPendaftaranDto::getNoRec).collect(Collectors.toList());
List<PelayananPasien> listPelayanan = pelayananPasienDao.findAll(listNoRec);
{
Optional<PelayananPasien> byPasien = listPelayanan.stream().filter(
p -> p.getPasien().getPasienDaftar().getPasien().getId().equals(voucher.getPasien().getId()))
.findFirst();
if (!byPasien.isPresent())
throw new ServiceVOException("Kode voucher tidak sesuai dengan pasien yang diperuntukkan");
}
{
List<Integer> listId = dtoList.stream().map(TagihanPendaftaranDto::getIdProduk)
.collect(Collectors.toList());
List<MapProdukPaketToProduk> detail = mapProdukPaketToProdukDao
.findAllByPaketId(voucher.getPaket().getId());
Optional<MapProdukPaketToProduk> byProduk = detail.stream()
.filter(d -> !listId.contains(d.getProduk().getId())).findFirst();
if (byProduk.isPresent())
throw new ServiceVOException("Produk " + byProduk.get().getProduk().getNamaProduk()
+ " tidak dapat didiskon karena belum dilakukan mapping");
}
listPelayanan.forEach(p -> {
Optional<TagihanPendaftaranDto> dto = dtoList.stream().filter(d -> d.getNoRec().equals(p.getNoRec()))
.findFirst();
dto.ifPresent(tagihanPendaftaranDto -> {
p.setHargaDiscount(tagihanPendaftaranDto.getHargaDiskon());
p.setJasa(tagihanPendaftaranDto.getHargaJasa());
p.setIsPasien(tagihanPendaftaranDto.getIsPaket());
});
}); });
}); pelayananPasienDao.save(listPelayanan);
pelayananPasienDao.save(listPelayanan); } else {
List<String> listNoRec = dtoList.stream().map(TagihanPendaftaranDto::getNoRec).collect(Collectors.toList());
List<PelayananPasien> listPelayanan = pelayananPasienDao.findAll(listNoRec);
listPelayanan.forEach(p -> {
Optional<TagihanPendaftaranDto> dto = dtoList.stream().filter(d -> d.getNoRec().equals(p.getNoRec()))
.findFirst();
dto.ifPresent(tagihanPendaftaranDto -> {
p.setHargaDiscount(tagihanPendaftaranDto.getHargaDiskon());
p.setJasa(tagihanPendaftaranDto.getHargaJasa());
});
});
pelayananPasienDao.save(listPelayanan);
}
} }
} }

View File

@ -219,19 +219,20 @@ public class PelayananController extends LocaleController<PelayananPasienVO> {
@RequestMapping(value = "/tagihan/diskon/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/tagihan/diskon/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> simpanDiskonTagihan(HttpServletRequest request, public ResponseEntity<Object> simpanDiskonTagihan(HttpServletRequest request,
@RequestParam(value = "kode-voucher", required = false) String kodeVoucher,
@RequestBody List<TagihanPendaftaranDto> dtoList) { @RequestBody List<TagihanPendaftaranDto> dtoList) {
try { try {
pelayananPasienService.diskonTagihan(dtoList); pelayananPasienService.diskonTagihan(kodeVoucher, dtoList);
mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
getMessage(MessageResource.LABEL_SUCCESS, request)); getMessage(MessageResource.LABEL_SUCCESS, request));
return RestUtil.getJsonResponse(dtoList, HttpStatus.OK, mapHeaderMessage); return RestUtil.getJsonResponse(dtoList, HttpStatus.OK, mapHeaderMessage);
} catch (ServiceVOException e) { } catch (ServiceVOException e) {
LOGGER.error("Got exception {} when simpan diskon tagihan {}", e.getMessage(), null); LOGGER.error("Got exception {} when simpan diskon tagihan", e.getMessage());
Map<String, String> error = new HashMap<String, String>(); Map<String, String> error = new HashMap<>();
error.put("bad-request", e.getMessage()); error.put("bad_request", e.getMessage());
return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, error); return RestUtil.getJsonResponse(null, HttpStatus.BAD_REQUEST, error);
} catch (JpaSystemException jse) { } catch (JpaSystemException jse) {
LOGGER.error("Got exception {} when simpan diskon tagihan {}", jse.getMessage(), null); LOGGER.error("Got exception {} when simpan diskon tagihan", jse.getMessage());
addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage()); addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage); return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
} }

View File

@ -219,9 +219,10 @@ public class PelayananController extends LocaleController<PelayananPasienVO> {
@RequestMapping(value = "/tagihan/diskon/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(value = "/tagihan/diskon/save", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> simpanDiskonTagihan(HttpServletRequest request, public ResponseEntity<Object> simpanDiskonTagihan(HttpServletRequest request,
@RequestParam(value = "kode-voucher", required = false) String kodeVoucher,
@RequestBody List<TagihanPendaftaranDto> dtoList) { @RequestBody List<TagihanPendaftaranDto> dtoList) {
try { try {
pelayananPasienService.diskonTagihan(dtoList); pelayananPasienService.diskonTagihan(kodeVoucher, dtoList);
mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS, mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
getMessage(MessageResource.LABEL_SUCCESS, request)); getMessage(MessageResource.LABEL_SUCCESS, request));
return RestUtil.getJsonResponse(dtoList, HttpStatus.OK, mapHeaderMessage); return RestUtil.getJsonResponse(dtoList, HttpStatus.OK, mapHeaderMessage);