Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-1305 | Add confirm inventory method #1430

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5e2c39f
add confirm method
Oct 4, 2024
d997c3b
add documentation of the method
Oct 4, 2024
376283e
update the status on TestMedicalInventory.java and writting test for …
Oct 7, 2024
80a84a9
Merge branch 'develop' into OP-1305
Oct 7, 2024
b99bf69
Update src/main/java/org/isf/medicalinventory/manager/MedicalInventor…
ArnaudFonzam Oct 7, 2024
f717028
add transactional annotation
Oct 7, 2024
6423768
use TimeTools not LocalDateTime to have time
Oct 7, 2024
cb78593
Merge branch 'develop' into OP-1305
Oct 7, 2024
9f3c23d
update src/test/java/org/isf/medicalsinventory/Tests.java
Oct 8, 2024
96e2720
Merge branch 'develop' into OP-1305
Oct 8, 2024
1763dc4
update src/main/java/org/isf/medicalinventory/manager/MedicalInventor…
Oct 8, 2024
f881639
Update src/main/java/org/isf/medicalinventory/manager/MedicalInventor…
ArnaudFonzam Oct 9, 2024
97fcfbc
Update src/main/java/org/isf/medicalinventory/manager/MedicalInventor…
ArnaudFonzam Oct 9, 2024
c154546
Update src/main/java/org/isf/medicalinventory/manager/MedicalInventor…
ArnaudFonzam Oct 9, 2024
550bbbe
Fix lot check when charging and lotcode is not provided
mwithi Oct 9, 2024
c51a908
add suggestion
Oct 9, 2024
8fb48ee
fix conflict
Oct 9, 2024
1aac4ad
Merge branch 'develop' into OP-1305
Oct 9, 2024
d2642d1
Update src/test/java/org/isf/medicalsinventory/Tests.java
ArnaudFonzam Oct 9, 2024
d668f5c
Update src/test/java/org/isf/medicalsinventory/Tests.java
ArnaudFonzam Oct 9, 2024
6f8b027
update src/test/java/org/isf/medicalsinventory/Tests.java
Oct 9, 2024
b32134a
fix conflict
Oct 9, 2024
59237d6
Fix test
mwithi Oct 9, 2024
80ee0f5
Add TODO comments in Supplier class
mwithi Oct 9, 2024
7a4c54f
Update src/main/java/org/isf/medicalstock/manager/MovStockInsertingMa…
mwithi Oct 9, 2024
10f0655
update src/test/java/org/isf/medicalsinventory/Tests.java
Oct 10, 2024
ade0e6c
update src/test/java/org/isf/medicalsinventory/Tests.java
Oct 11, 2024
5f901d7
Merge branch 'develop' into OP-1305
Oct 11, 2024
fec550b
start with validateInventory Test
Oct 11, 2024
349d699
Merge branch 'develop' into OP-1305
Oct 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
Expand All @@ -37,11 +38,16 @@
import org.isf.medicalstock.manager.MovStockInsertingManager;
import org.isf.medicalstock.model.Lot;
import org.isf.medicalstock.model.Movement;
import org.isf.medstockmovtype.manager.MedicalDsrStockMovementTypeBrowserManager;
import org.isf.medstockmovtype.model.MovementType;
import org.isf.supplier.manager.SupplierBrowserManager;
import org.isf.supplier.model.Supplier;
import org.isf.utils.exception.OHDataValidationException;
import org.isf.utils.exception.OHServiceException;
import org.isf.utils.exception.model.OHExceptionMessage;
import org.isf.utils.exception.model.OHSeverityLevel;
import org.isf.utils.time.TimeTools;
import org.isf.ward.manager.WardBrowserManager;
import org.isf.ward.model.Ward;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
Expand All @@ -58,12 +64,20 @@ public class MedicalInventoryManager {

private MovBrowserManager movBrowserManager;

public MedicalInventoryManager(MedicalInventoryIoOperation medicalInventoryIoOperation, MedicalInventoryRowManager medicalInventoryRowManager,
MovStockInsertingManager movStockInsertingManager,
MovBrowserManager movBrowserManager) {
private MedicalDsrStockMovementTypeBrowserManager medicalDsrStockMovementTypeBrowserManager;

private SupplierBrowserManager supplierManager;

private WardBrowserManager wardManager;

public MedicalInventoryManager(MedicalInventoryIoOperation medicalInventoryIoOperation, MedicalInventoryRowManager medicalInventoryRowManager, MedicalDsrStockMovementTypeBrowserManager medicalDsrStockMovementTypeBrowserManager,
SupplierBrowserManager supplierManager, MovStockInsertingManager movStockInsertingManager, WardBrowserManager wardManager, MovBrowserManager movBrowserManager) {
this.ioOperations = medicalInventoryIoOperation;
this.medicalInventoryRowManager = medicalInventoryRowManager;
this.medicalDsrStockMovementTypeBrowserManager = medicalDsrStockMovementTypeBrowserManager;
this.supplierManager = supplierManager;
this.movStockInsertingManager = movStockInsertingManager;
this.wardManager = wardManager;
this.movBrowserManager = movBrowserManager;
}

Expand Down Expand Up @@ -372,4 +386,55 @@ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceE
}
ioOperations.deleteInventory(medicalInventory);
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Confirm the Inventory rows of inventory.
*
* @param inventory - The {@link MedicalInventory}
* @param inventoryRowSearchList- The list of {@link MedicalInventory}
* @throws OHDataValidationException
*/
@Transactional(rollbackFor = OHServiceException.class)
public List<Movement> confirmMedicalInventoryRow(MedicalInventory inventory, List<MedicalInventoryRow> inventoryRowSearchList) throws OHServiceException {
// validate the inventory
this.validateMedicalInventoryRow(inventory, inventoryRowSearchList);
// get general info
String referenceNumber = inventory.getInventoryReference();
// TODO: make possibility to allow charges and discharges with same referenceNumber
String chargeReferenceNumber = referenceNumber + "-charge";
String dischargeReferenceNumber = referenceNumber + "-discharge";
MovementType chargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(inventory.getChargeType());
MovementType dischargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(inventory.getDischargeType());
Supplier supplier = supplierManager.getByID(inventory.getSupplier());
Ward ward = wardManager.findWard(inventory.getDestination());
LocalDateTime now = TimeTools.getNow();
// prepare movements
List<Movement> chargeMovements = new ArrayList<>();
List<Movement> dischargeMovements = new ArrayList<>();
for (Iterator<MedicalInventoryRow> iterator = inventoryRowSearchList.iterator(); iterator.hasNext();) {
MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next();

double theoQty = medicalInventoryRow.getTheoreticQty();
double realQty = medicalInventoryRow.getRealQty();
Double ajustQty = realQty - theoQty;
Medical medical = medicalInventoryRow.getMedical();
Lot currentLot = medicalInventoryRow.getLot();
if (ajustQty > 0) { // charge movement when realQty > theoQty
Movement movement = new Movement(medical, chargeType, null, currentLot, now, ajustQty.intValue(), supplier, chargeReferenceNumber);
chargeMovements.add(movement);
} else if (ajustQty < 0) { // discharge movement when realQty < theoQty
Movement movement = new Movement(medical, dischargeType, ward, currentLot, now, -(ajustQty.intValue()), null, dischargeReferenceNumber);
dischargeMovements.add(movement);
} // else ajustQty = 0, continue
}
// create movements
List<Movement> insertedMovements = new ArrayList<>();
if (!chargeMovements.isEmpty()) {
insertedMovements.addAll(movStockInsertingManager.newMultipleChargingMovements(chargeMovements, chargeReferenceNumber));
}
if (!dischargeMovements.isEmpty()) {
insertedMovements.addAll(movStockInsertingManager.newMultipleDischargingMovements(dischargeMovements, dischargeReferenceNumber));
}
return insertedMovements;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public enum MovementOrder {
*
* @return {@code true} if automatic lot mode, {@code false} otherwise.
*/
private boolean isAutomaticLotMode() {
private boolean isAutomaticLotInMode() {
return GeneralData.AUTOMATICLOT_IN;
}

Expand Down Expand Up @@ -180,26 +180,23 @@ public List<Movement> newAutomaticDischargingMovement(Movement movement) throws
* Stores the specified {@link Movement}.
*
* @param movement - the movement to store.
* @return the stored {@link Movement}.
* @throws OHServiceException if an error occurs during the store operation.
*/
public Movement newMovement(Movement movement) throws OHServiceException {
String lotCode = null;
Lot lot = movement.getLot();

if (movement.getLot() != null) {
lotCode = movement.getLot().getCode();
if (lot != null) {
lotCode = lot.getCode();
}

// we have to manage the Lot
if (movement.getType().getType().contains("+")) {
// if is in automatic lot mode then we have to generate a new lot code
if (isAutomaticLotMode() || "".equals(lotCode)) {
lotCode = generateLotCode();
}

boolean lotExists = lotExists(lotCode);
if (!lotExists) {
storeLot(lotCode, movement.getLot(), movement.getMedical());
}
// if charging we have to manage the Lot, if discharging the lot should be given
boolean chargeMovement = movement.getType().getType().contains("+");
boolean lotExists = lotExists(lotCode);
if (chargeMovement && !lotExists) {
lot = storeLot(lotCode, movement.getLot(), movement.getMedical());
lotCode = lot.getCode();
}

Movement movementStored = storeMovement(movement, lotCode);
Expand Down Expand Up @@ -312,7 +309,7 @@ public Lot updateLot(Lot lot) throws OHServiceException {
/**
* Stores the specified {@link Lot}.
*
* @param lotCode the {@link Lot} code.
* @param lotCode the {@link Lot} code. If {@code null} or {@code empty} it will be generated.
* @param lot the lot to store.
* @param medical
* @return the stored {@link Lot} object.
Expand All @@ -322,6 +319,9 @@ public Lot updateLot(Lot lot) throws OHServiceException {
public Lot storeLot(String lotCode, Lot lot, Medical medical) throws OHServiceException {
if (lotCode == null || lotCode.equals("")) {
lotCode = this.generateLotCode();
if (!isAutomaticLotInMode()) {
LOGGER.warn("AUTOMATICLOT_IN mode set to 'false' but lot code not provided. Generating... {}.", lotCode);
}
}
lot.setCode(lotCode);
lot.setMedical(medical);
Expand Down Expand Up @@ -590,7 +590,8 @@ public List<Movement> getMovementForPrint(
}

/**
* Retrieves lot referred to the specified {@link Medical}, expiring first on top Lots with zero quantities will be stripped out if removeEmpty is set to true.
* Retrieves lot referred to the specified {@link Medical}, expiring first on top Lots with zero quantities will be stripped out if removeEmpty is set to
* true.
*
* @param medical the medical.
* @param removeEmpty
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/isf/supplier/model/Supplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public Supplier() {
* @param supEmail
* @param supNote
*/
// TODO: to verify if it is really needed to have supID in the constructor
public Supplier(Integer supID, String supName, String supAddress, String supTaxcode, String supPhone, String supFax, String supEmail, String supNote) {
this.supId = supID;
this.supName = supName;
Expand All @@ -123,6 +124,7 @@ public Supplier(Integer supID, String supName, String supAddress, String supTaxc
* @param supNote
* @param supDeleted
*/
// TODO: to remove, used only in tests
public Supplier(Integer supID, String supName, String supAddress, String supTaxcode, String supPhone, String supFax, String supEmail, String supNote,
Character supDeleted) {
this.supId = supID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,23 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

import org.isf.medicalinventory.model.InventoryStatus;
import org.isf.medicalinventory.model.InventoryType;
import org.isf.medicalinventory.model.MedicalInventory;
import org.isf.utils.exception.OHException;
import org.isf.utils.time.TimeTools;
import org.isf.ward.model.Ward;

public class TestMedicalInventory {

private int id = 1;
private String status = "STATUS";
private LocalDateTime inventoryDate = LocalDateTime.now();
private String user = "USER";
private String status = InventoryStatus.draft.toString();
private LocalDateTime inventoryDate = TimeTools.getNow();
private String user = "admin";
private String inventoryReference = "REFERENCE";
private String inventoryType = "TYPE";
private String inventoryType = InventoryType.main.toString();
private String ward = "Z";
private int supplier = 3;
private int supplier = 1;
private String destination = "INV";
private String charge = "inventory+";
private String discharge = "inventory-";
Expand Down
Loading