Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Commit

Permalink
refactor getLot and update validateInventory
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFonzam committed Aug 9, 2024
1 parent 31d3be8 commit 269ebcb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,23 @@ public void validateInventory(MedicalInventory inventory, List<MedicalInventoryR
if (movs != null) {
Movement mov = movs.get(0);
String lotCodeOfMovement = mov.getLot().getCode();
Lot lot = movStockInsertingManager.getLot(lotCodeOfMovement);
double mainStoreQty = (double)lot.getMainStoreQuantity();
Integer medicalCode = medical.getCode();
Integer movMedicalCode = mov.getMedical().getCode();
if (movMedicalCode.equals(medicalCode) && lotCodeOfMovement.equals(lotCode)) {
if (mainStoreQty != theoQty) {
medicalInventoryRow.setTheoreticQty(mainStoreQty);
medicalInventoryRow.setRealqty(mainStoreQty);
medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow);
Lot lot = null;
List<Lot> lots = movStockInsertingManager.getLotByMedical(medical).stream().filter(l -> l.getCode().equals(lotCodeOfMovement)).collect(Collectors.toList());
if (lots != null) {
lot = lots.get(0);
double mainStoreQty = (double)lot.getMainStoreQuantity();
Integer medicalCode = medical.getCode();
Integer movMedicalCode = mov.getMedical().getCode();
if (movMedicalCode.equals(medicalCode) && lotCodeOfMovement.equals(lotCode)) {
if (mainStoreQty != theoQty) {
medicalInventoryRow.setTheoreticQty(mainStoreQty);
medicalInventoryRow.setRealqty(mainStoreQty);
medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow);
}
} else {
MedicalInventoryRow medInvRow = new MedicalInventoryRow(0, mainStoreQty, mainStoreQty, inventory, medical, lot);
medicalInventoryRowManager.newMedicalInventoryRow(medInvRow);
}
} else {
MedicalInventoryRow medInvRow = new MedicalInventoryRow(0, mainStoreQty, mainStoreQty, inventory, medical, lot);
medicalInventoryRowManager.newMedicalInventoryRow(medInvRow);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,34 +296,7 @@ public boolean lotExists(String lotCode) throws OHServiceException {
* @throws OHServiceException if an error occurs during the check.
*/
public Lot getLot(String lotCode) throws OHServiceException {
Lot lot = lotRepository.findById(String.valueOf(lotCode)).orElse(null);
// Retrieve quantities in batch
if (lot != null) {
List<String> lotCodes = new ArrayList<>();
lotCodes.add(lotCode);
List<Object[]> mainStoreQuantities = lotRepository.getMainStoreQuantities(lotCodes);
List<Object[]> wardsTotalQuantities = lotRepository.getWardsTotalQuantities(lotCodes);

// Process mainStoreQuantities and update lots
for (Object[] result : mainStoreQuantities) {
lotCode = (String) result[0];
Integer mainStoreQuantity = ((Long) result[1]).intValue();

// Update the lot
lot.setMainStoreQuantity(mainStoreQuantity);
}

// Process wardsTotalQuantities and update lots
for (Object[] result : wardsTotalQuantities) {
lotCode = (String) result[0];
Double wardsTotalQuantity = (Double) result[1];

// Update the lot if found
lot.setWardsTotalQuantity(wardsTotalQuantity);
}
return lot;
}
return null;
return lotRepository.findById(String.valueOf(lotCode)).orElse(null);
}

/**
Expand Down

0 comments on commit 269ebcb

Please sign in to comment.