Update service pelayanan pasien
Pembuatan service batal paket produk saat verifikasi pasien pulang
This commit is contained in:
parent
1505a36241
commit
cd631719d2
@ -1,17 +1,16 @@
|
||||
package com.jasamedika.medifirst2000.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.jasamedika.medifirst2000.dto.StrukPelayananDto;
|
||||
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
|
||||
import com.jasamedika.medifirst2000.entities.PasienDaftar;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.jasamedika.medifirst2000.dto.StrukPelayananDto;
|
||||
import com.jasamedika.medifirst2000.entities.AntrianPasienDiPeriksa;
|
||||
import com.jasamedika.medifirst2000.entities.PasienDaftar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Repository("PasienDaftarDao")
|
||||
public interface PasienDaftarDao extends PagingAndSortingRepository<PasienDaftar, String> {
|
||||
@ -89,6 +88,8 @@ public interface PasienDaftarDao extends PagingAndSortingRepository<PasienDaftar
|
||||
@Query("select p from PasienDaftar p where p.pasien.id=:id ")
|
||||
List<PasienDaftar> findByPasienId(@Param("id") Integer id);
|
||||
|
||||
List<PasienDaftar> findByPasienIdAndVoucherPaketId(Integer pasienId, String voucherPaketId);
|
||||
|
||||
List<PasienDaftar> findByRuanganNextScheduleId(Integer idRuangan);
|
||||
|
||||
@Query("select NEW Map (a.tglPulang as tglPulang) " + "from PasienDaftar a " + "left join a.ruangan b "
|
||||
@ -309,4 +310,9 @@ public interface PasienDaftarDao extends PagingAndSortingRepository<PasienDaftar
|
||||
List<Map<String, Object>> findLogRekapDiskon(@Param("norecPd") String norecPd,
|
||||
@Param("jenisLogPd") String jenisLogPd, @Param("norecSp") String norecSp,
|
||||
@Param("jenisLogSp") String jenisLogSp);
|
||||
|
||||
@Query("select pd from PasienDaftar pd " + "inner join pd.voucherPaket vp " + "where pd.pasienId = :pasienId "
|
||||
+ "and vp.kode = :kodeVoucher " + "and pd.noRegistrasi <> :noRegistrasi")
|
||||
List<PasienDaftar> findByPasienAndVoucherAndNoRegistrasiNot(@Param("pasienId") Integer pasienId,
|
||||
@Param("kodeVoucher") String kodeVoucher, @Param("noRegistrasi") String noRegistrasi);
|
||||
}
|
||||
|
||||
@ -267,4 +267,6 @@ public interface PelayananPasienDao extends PagingAndSortingRepository<Pelayanan
|
||||
+ "inner join pp.produk pr " + "inner join pp.kelas kls " + "inner join ppp.kdpegawai pg "
|
||||
+ "where pd.noRegistrasi = :noRegistrasi")
|
||||
List<Map<String, Object>> findPelayananPasienByTagihanPendaftaran(@Param("noRegistrasi") String noRegistrasi);
|
||||
|
||||
List<PelayananPasien> findByPasienDaftarPasienDaftarNoRecIn(List<String> idDaftarList);
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.jasamedika.medifirst2000.service;
|
||||
|
||||
import com.jasamedika.medifirst2000.dto.BatalPaketProdukDto;
|
||||
import com.jasamedika.medifirst2000.dto.TagihanPendaftaranDto;
|
||||
import com.jasamedika.medifirst2000.vo.PelayananPasienVO;
|
||||
|
||||
@ -35,4 +36,6 @@ public interface PelayananPasienService {
|
||||
void diskonTagihan(String kodeVoucher, List<TagihanPendaftaranDto> dtoList);
|
||||
|
||||
boolean isValidVoucher(String kodeVoucher, String noRegistrasi);
|
||||
|
||||
void batalPaketProduk(BatalPaketProdukDto dto);
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package com.jasamedika.medifirst2000.service.impl;
|
||||
import com.jasamedika.medifirst2000.constants.Master;
|
||||
import com.jasamedika.medifirst2000.converter.BaseConverterImpl;
|
||||
import com.jasamedika.medifirst2000.dao.*;
|
||||
import com.jasamedika.medifirst2000.dto.BatalPaketProdukDto;
|
||||
import com.jasamedika.medifirst2000.dto.TagihanPendaftaranDto;
|
||||
import com.jasamedika.medifirst2000.entities.*;
|
||||
import com.jasamedika.medifirst2000.exception.ServiceVOException;
|
||||
@ -2217,17 +2218,7 @@ public class PelayananPasienServiceImpl extends BaseVoServiceImpl implements Pel
|
||||
throw new ServiceVOException("Tidak memiliki akses diskon total");
|
||||
}
|
||||
if (CommonUtil.isNotNullOrEmpty(kodeVoucher)) {
|
||||
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()));
|
||||
VoucherPaket voucher = getVoucher(kodeVoucher, false);
|
||||
List<String> listNoRec = dtoList.stream().filter(TagihanPendaftaranDto::getIsPaket)
|
||||
.map(TagihanPendaftaranDto::getNoRec).collect(Collectors.toList());
|
||||
List<PelayananPasien> listPelayanan = pelayananPasienDao.findAll(listNoRec);
|
||||
@ -2288,24 +2279,73 @@ public class PelayananPasienServiceImpl extends BaseVoServiceImpl implements Pel
|
||||
|
||||
@Override
|
||||
public boolean isValidVoucher(String kodeVoucher, String noRegistrasi) {
|
||||
if (kodeVoucher.isEmpty())
|
||||
throw new ServiceVOException("Kode voucher harus diisi");
|
||||
VoucherPaket voucher = getVoucher(kodeVoucher, noRegistrasi, false);
|
||||
List<PasienDaftar> listPendaftaranLain = pasienDaftarDao
|
||||
.findByPasienAndVoucherAndNoRegistrasiNot(voucher.getPasienId(), kodeVoucher, noRegistrasi);
|
||||
Optional<PasienDaftar> first = listPendaftaranLain.stream().filter(PasienDaftar::getIsBatalPaket).findFirst();
|
||||
if (first.isPresent())
|
||||
throw new ServiceVOException("Paket dengan menggunakan kode voucher ini sudah dibatalkan");
|
||||
return !CommonUtil.isNullOrEmpty(voucher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void batalPaketProduk(BatalPaketProdukDto dto) {
|
||||
VoucherPaket voucher = getVoucher(dto.getKodeVoucher(), dto.getNoRegistrasi(), true);
|
||||
{
|
||||
voucher.setIsBatal(true);
|
||||
voucherPaketDao.save(voucher);
|
||||
}
|
||||
List<PasienDaftar> listPendaftaran = pasienDaftarDao.findByPasienIdAndVoucherPaketId(voucher.getPasienId(),
|
||||
voucher.getNoRec());
|
||||
{
|
||||
listPendaftaran.forEach(p -> p.setIsBatalPaket(true));
|
||||
pasienDaftarDao.save(listPendaftaran);
|
||||
}
|
||||
List<String> idDaftarList = listPendaftaran.stream().map(PasienDaftar::getNoRec).collect(Collectors.toList());
|
||||
List<PelayananPasien> listPelayanan = pelayananPasienDao.findByPasienDaftarPasienDaftarNoRecIn(idDaftarList);
|
||||
List<MapProdukPaketToProduk> produkMapping = mapProdukPaketToProdukDao.findAllByPaketId(voucher.getPaketId());
|
||||
List<Integer> idProdukMapping = produkMapping.stream().map(MapProdukPaketToProduk::getProdukId)
|
||||
.collect(Collectors.toList());
|
||||
{
|
||||
listPelayanan.forEach(p -> p.setIsPaket(false));
|
||||
listPelayanan.stream().filter(p -> idProdukMapping.contains(p.getProdukId()))
|
||||
.forEach(p -> p.setHargaDiscount(0.0));
|
||||
listPelayanan.stream().filter(p -> voucher.getPaketId().equals(p.getProdukId()))
|
||||
.forEach(p -> p.setHargaDiscount(p.getHargaJual()));
|
||||
pelayananPasienDao.save(listPelayanan);
|
||||
}
|
||||
}
|
||||
|
||||
private VoucherPaket getVoucher(String kodeVoucher, String noRegistrasi, Boolean basicValidation) {
|
||||
if (noRegistrasi.isEmpty())
|
||||
throw new ServiceVOException("Nomor registrasi 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()));
|
||||
VoucherPaket voucher = getVoucher(kodeVoucher, basicValidation);
|
||||
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;
|
||||
return voucher;
|
||||
}
|
||||
|
||||
private VoucherPaket getVoucher(String kodeVoucher, Boolean basicValidation) {
|
||||
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 (basicValidation)
|
||||
return voucher;
|
||||
{
|
||||
// Advance Validation
|
||||
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()));
|
||||
return voucher;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.jasamedika.medifirst2000.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Salman Manoe
|
||||
* @version 1.0.0
|
||||
* @since 22 Aug 2023
|
||||
*/
|
||||
@Data
|
||||
public class BatalPaketProdukDto {
|
||||
private String kodeVoucher;
|
||||
private String noRegistrasi;
|
||||
}
|
||||
@ -4,6 +4,7 @@ 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.PasienDaftarService;
|
||||
@ -22,7 +23,6 @@ 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;
|
||||
@ -238,6 +238,25 @@ public class PelayananController extends LocaleController<PelayananPasienVO> {
|
||||
}
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/tagihan/diskon/batal-paket", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Object> batalPaket(HttpServletRequest request, @RequestBody BatalPaketProdukDto dto) {
|
||||
try {
|
||||
pelayananPasienService.batalPaketProduk(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 exception {} when batal diskon paket", 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 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<Object> isValidVoucher(HttpServletRequest request,
|
||||
@RequestParam("kode-voucher") String kodeVoucher, @RequestParam("no-registrasi") String noRegistrasi) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user