Skip to content

Commit

Permalink
update MedInventory model and getLotsByMedical Method
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFonzam committed Jul 1, 2024
1 parent 089cae5 commit f3d1fcd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public class MedicalInventory extends Auditable<String> {
private String ward;

@Column(name = "MINVT_CHARGE_TYPE")
private String changeType;
private String chargeType;

@Column(name = "MINVT_DISCHARGE_TYPE")
private String dischangeType;
private String dischargeType;

@Column(name = "MINVT_SUPPLIER")
private Integer supplier;
Expand All @@ -106,16 +106,16 @@ public MedicalInventory(Integer id, String status, LocalDateTime inventoryDate,
}

public MedicalInventory(Integer id, String status, LocalDateTime inventoryDate, String user, String inventoryReference,
String inventoryType, String ward, String changeType, String dischangeType, int supplier, String destination) {
String inventoryType, String ward, String chargeType, String dischargeType, int supplier, String destination) {
this.id = id;
this.status = status;
this.inventoryDate = inventoryDate;
this.user = user;
this.inventoryReference = inventoryReference;
this.inventoryType = inventoryType;
this.ward = ward;
this.changeType = changeType;
this.dischangeType = dischangeType;
this.chargeType = chargeType;
this.dischargeType = dischargeType;
this.supplier = supplier;
this.destination = destination;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,33 +235,20 @@ private boolean isAutomaticLotIn() {
private boolean isAutomaticLotOut() {
return GeneralData.AUTOMATICLOT_OUT;
}

/**
* Retrieves all the lot referred to the specified {@link Medical}, expiring first on top
*
* @param medical the medical.
* @return a list of {@link Lot}.
* @throws OHServiceException if an error occurs retrieving the lot list.
*/
public List<Lot> getAllLotsByMedical(Medical medical) throws OHServiceException {
if (medical == null) {
return new ArrayList<>();
}
return ioOperations.getAllLotsByMedical(medical);
}

/**
* Retrieves all the {@link Lot} associated to the specified {@link Medical}, expiring first on top with zero quantities will be stripped out
*
* @param medical the medical.
* @param removeEmpty.
* @return the list of retrieved {@link Lot}s.
* @throws OHServiceException
*/
public List<Lot> getLotByMedical(Medical medical) throws OHServiceException {
public List<Lot> getLotByMedical(Medical medical, boolean removeEmpty) throws OHServiceException {
if (medical == null) {
return new ArrayList<>();
}
return ioOperations.getLotsByMedical(medical);
return ioOperations.getLotsByMedical(medical, removeEmpty);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public List<Movement> getMovementByLot(Lot lot) throws OHServiceException {
*/
public List<Movement> newAutomaticDischargingMovement(Movement movement) throws OHServiceException {
List<Movement> dischargingMovements = new ArrayList<>();
List<Lot> lots = getLotsByMedical(movement.getMedical());
List<Lot> lots = getLotsByMedical(movement.getMedical(), true);
Medical medical = movement.getMedical();
int qty = movement.getQuantity(); // movement initial quantity

Expand Down Expand Up @@ -633,10 +633,11 @@ public List<Lot> getAllLotsByMedical(Medical medical) throws OHServiceException
* Retrieves lot referred to the specified {@link Medical}, expiring first on top Lots with zero quantities will be stripped out
*
* @param medical the medical.
* @param removeEmpty
* @return a list of {@link Lot}.
* @throws OHServiceException if an error occurs retrieving the lot list.
*/
public List<Lot> getLotsByMedical(Medical medical) throws OHServiceException {
public List<Lot> getLotsByMedical(Medical medical, boolean removeEmpty) throws OHServiceException {
List<Lot> lots = lotRepository.findByMedicalOrderByDueDate(medical.getCode());

if (lots.isEmpty()) {
Expand Down Expand Up @@ -675,7 +676,9 @@ public List<Lot> getLotsByMedical(Medical medical) throws OHServiceException {
}

// Remove empty lots
lots.removeIf(lot -> lot.getMainStoreQuantity() <= 0);
if (removeEmpty) {
lots.removeIf(lot -> lot.getMainStoreQuantity() <= 0);
}

return lots;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public void setParameters(MedicalInventory medInventory) {
medInventory.setInventoryReference(inventoryReference);
medInventory.setInventoryType(inventoryType);
medInventory.setWard(ward);
medInventory.setChangeType(charge);
medInventory.setDischangeType(discharge);
medInventory.setChargeType(charge);
medInventory.setDischargeType(discharge);
medInventory.setSupplier(supplier);
medInventory.setDestination(destination);
}
Expand All @@ -81,8 +81,8 @@ public void check(MedicalInventory medInventory, int id) {
assertThat(medInventory.getInventoryReference()).isEqualTo(inventoryReference);
assertThat(medInventory.getInventoryType()).isEqualTo(inventoryType);
assertThat(medInventory.getWard()).isEqualTo(ward);
assertThat(medInventory.getChangeType()).isEqualTo(charge);
assertThat(medInventory.getDischangeType()).isEqualTo(discharge);
assertThat(medInventory.getChargeType()).isEqualTo(charge);
assertThat(medInventory.getDischargeType()).isEqualTo(discharge);
assertThat(medInventory.getSupplier()).isEqualTo(supplier);
assertThat(medInventory.getDestination()).isEqualTo(destination);
}
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/isf/medicalstock/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ void testIoGetLotsByMedical(boolean in, boolean out, boolean toward) throws Exce
int code = setupTestMovement(false);
Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null);
assertThat(foundMovement).isNotNull();
List<Lot> lots = medicalStockIoOperation.getLotsByMedical(foundMovement.getMedical());
List<Lot> lots = medicalStockIoOperation.getLotsByMedical(foundMovement.getMedical(), true);
assertThat(lots).hasSize(1);
assertThat(lots.get(0).getCode()).isEqualTo(foundMovement.getLot().getCode());
}
Expand All @@ -245,7 +245,7 @@ void testIoGetLotsByMedicalEmptyLot(boolean in, boolean out, boolean toward) thr
foundMovement.setQuantity(0);
movementIoOperationRepository.saveAndFlush(foundMovement);

List<Lot> lots = medicalStockIoOperation.getLotsByMedical(foundMovement.getMedical());
List<Lot> lots = medicalStockIoOperation.getLotsByMedical(foundMovement.getMedical(), true);
assertThat(lots).isEmpty();
}

Expand Down Expand Up @@ -319,7 +319,7 @@ void testIoNewAutomaticDischargingMovementDifferentLots(boolean in, boolean out,
medicalStockIoOperation.newAutomaticDischargingMovement(dischargeMovement);
GeneralData.AUTOMATICLOT_OUT = automaticLotMode;

List<Lot> lots = medicalStockIoOperation.getLotsByMedical(medical);
List<Lot> lots = medicalStockIoOperation.getLotsByMedical(medical, true);
assertThat(lots).hasSize(1); // first lot should be 0 quantity and stripped by the list
}

Expand Down Expand Up @@ -754,7 +754,7 @@ void testMgrGetLotsByMedical(boolean in, boolean out, boolean toward) throws Exc
int code = setupTestMovement(false);
Movement foundMovement = movementIoOperationRepository.findById(code).orElse(null);
assertThat(foundMovement).isNotNull();
List<Lot> lots = movStockInsertingManager.getLotByMedical(foundMovement.getMedical());
List<Lot> lots = movStockInsertingManager.getLotByMedical(foundMovement.getMedical(), true);
assertThat(lots).hasSize(1);
assertThat(lots.get(0).getCode()).isEqualTo(foundMovement.getLot().getCode());
}
Expand All @@ -763,7 +763,7 @@ void testMgrGetLotsByMedical(boolean in, boolean out, boolean toward) throws Exc
@MethodSource("automaticlot")
void testMgrGetLotsByMedicalNull(boolean in, boolean out, boolean toward) throws Exception {
setGeneralData(in, out, toward);
assertThat(movStockInsertingManager.getLotByMedical(null)).isEmpty();
assertThat(movStockInsertingManager.getLotByMedical(null, true)).isEmpty();
}

@ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}")
Expand Down

0 comments on commit f3d1fcd

Please sign in to comment.