From 5e2c39fd58eae2c4973e2968cd1c1e7357e60f9a Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Fri, 4 Oct 2024 14:42:04 +0100 Subject: [PATCH 01/22] add confirm method --- .../manager/MedicalInventoryManager.java | 64 ++++++++++++++++++- 1 file changed, 61 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index c31a6c70d..1d7202aa7 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -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; @@ -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; @@ -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; } @@ -372,4 +386,48 @@ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceE } ioOperations.deleteInventory(medicalInventory); } + + public void confirmMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { + // validate the inventory + this.validateMedicalInventoryRow(inventory, inventoryRowSearchList); + // create Movements + String dischargeCode = inventory.getDischargeType(); + String chargeCode = inventory.getChargeType(); + Integer supplierId = inventory.getSupplier(); + String wardCode = inventory.getDestination(); + MovementType chargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(chargeCode); + MovementType dischargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(dischargeCode); + Supplier supplier = supplierManager.getByID(supplierId); + Ward ward = wardManager.findWard(wardCode); + LocalDateTime today = LocalDateTime.now(); + for (Iterator iterator = inventoryRowSearchList.iterator(); iterator.hasNext();) { + String reference = "Ref-" + LocalDateTime.now(); + MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); + double theoQty = medicalInventoryRow.getTheoreticQty(); + double realQty = medicalInventoryRow.getRealQty(); + Double ajustQty = theoQty - realQty; + Medical medical = medicalInventoryRow.getMedical(); + String lotCode = medicalInventoryRow.getLot().getCode(); + Lot currentLot = movStockInsertingManager.getLot(lotCode); + boolean isNew = medicalInventoryRow.isNewLot(); + if (realQty > theoQty && !isNew) { // charge movement when realQty > theoQty + Movement movement = new Movement(medical, chargeType, null, currentLot, today, -(ajustQty.intValue()), supplier, reference); + List chargeMovement = new ArrayList<>(); + chargeMovement.add(movement); + chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference); + } else if (realQty < theoQty && !isNew) { // discharge movement when realQty < theoQty + Movement movement = new Movement(medical, dischargeType, ward, currentLot, today, ajustQty.intValue(), null, reference); + List dischargeMovement = new ArrayList<>(); + dischargeMovement.add(movement); + dischargeMovement = movStockInsertingManager.newMultipleDischargingMovements(dischargeMovement, reference); + } + // If new lot has been inserted, create charge movement with real qty + if (isNew) { + Movement movement = new Movement(medical, chargeType, null, currentLot, today, (int) realQty, supplier, reference); + List chargeMovement = new ArrayList<>(); + chargeMovement.add(movement); + chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference); + } + } + } } From d997c3b5e30b26c783156eee6149ce264c8cc13d Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Fri, 4 Oct 2024 14:44:52 +0100 Subject: [PATCH 02/22] add documentation of the method --- .../medicalinventory/manager/MedicalInventoryManager.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 1d7202aa7..2b68fa187 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -387,6 +387,13 @@ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceE ioOperations.deleteInventory(medicalInventory); } + /** + * Confirm the Inventory rows of inventory. + * + * @param inventory - The {@link MedicalInventory} + * @param inventoryRowSearchList- The list of {@link MedicalInventory} + * @throws OHDataValidationException + */ public void confirmMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { // validate the inventory this.validateMedicalInventoryRow(inventory, inventoryRowSearchList); From 376283efda003ee5b018318acba0710807c3f431 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 7 Oct 2024 11:45:21 +0100 Subject: [PATCH 03/22] update the status on TestMedicalInventory.java and writting test for validate and confirm inventory, update validateInventoryMethod --- .../manager/MedicalInventoryManager.java | 2 +- .../TestMedicalInventory.java | 3 +- .../java/org/isf/medicalsinventory/Tests.java | 59 ++++++++++++++++++- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 2b68fa187..380d3c00e 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -407,8 +407,8 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List iterator = inventoryRowSearchList.iterator(); iterator.hasNext();) { - String reference = "Ref-" + LocalDateTime.now(); MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); double theoQty = medicalInventoryRow.getTheoreticQty(); double realQty = medicalInventoryRow.getRealQty(); diff --git a/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java b/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java index 6911881c1..42f59e6d5 100644 --- a/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java +++ b/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java @@ -27,6 +27,7 @@ import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; +import org.isf.medicalinventory.model.InventoryStatus; import org.isf.medicalinventory.model.MedicalInventory; import org.isf.utils.exception.OHException; import org.isf.ward.model.Ward; @@ -34,7 +35,7 @@ public class TestMedicalInventory { private int id = 1; - private String status = "STATUS"; + private String status = InventoryStatus.draft.toString(); private LocalDateTime inventoryDate = LocalDateTime.now(); private String user = "USER"; private String inventoryReference = "REFERENCE"; diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index c767753fc..3693d5fdd 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -520,8 +520,7 @@ void testMgrGetMedicalInventoryRowByInventoryId() throws Exception { assertThat(newMedicalInventoryRow).isNotNull(); List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); assertThat(medicalInventoryRows).isNotEmpty(); - assertThat(medicalInventoryRows).hasSize(1); - + assertThat(medicalInventoryRows).hasSize(1); } private int setupTestMedicalInventory(boolean usingSet) throws OHException, OHServiceException { @@ -572,4 +571,60 @@ void testDeleteInventory() throws Exception { assertThat(deletedInventory).isNotNull(); assertThat(deletedInventory.getStatus()).isEqualTo(InventoryStatus.canceled.toString()); } + + @Test + void testValidateMedicalInventory() throws Exception { + Ward ward = testWard.setup(false); + wardIoOperationRepository.saveAndFlush(ward); + MedicalInventory inventory = testMedicalInventory.setup(ward, false); + MedicalInventory savedInventory = medicalInventoryIoOperation.newMedicalInventory(inventory); + MedicalType medicalType = testMedicalType.setup(false); + medicalTypeIoOperationRepository.saveAndFlush(medicalType); + Medical medical = testMedical.setup(medicalType, false); + medicalsIoOperationRepository.saveAndFlush(medical); + Lot lot = testLot.setup(medical, false); + lotIoOperationRepository.saveAndFlush(lot); + MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false); + int inventoryId = medicalInventoryRow.getId(); + MedicalInventoryRow newMedicalInventoryRow = medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); + assertThat(newMedicalInventoryRow).isNotNull(); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); + assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows).hasSize(1); + medicalInventoryManager.validateMedicalInventoryRow(savedInventory, medicalInventoryRows); + inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); + String status = InventoryStatus.validated.toString(); + inventory.setStatus(status); + inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory); + assertThat(inventory).isNotNull(); + assertThat(inventory.getStatus()).isEqualTo(status); + } + + @Test + void testConfirmMedicalInventory() throws Exception { + Ward ward = testWard.setup(false); + wardIoOperationRepository.saveAndFlush(ward); + MedicalInventory inventory = testMedicalInventory.setup(ward, false); + MedicalInventory savedInventory = medicalInventoryIoOperation.newMedicalInventory(inventory); + MedicalType medicalType = testMedicalType.setup(false); + medicalTypeIoOperationRepository.saveAndFlush(medicalType); + Medical medical = testMedical.setup(medicalType, false); + medicalsIoOperationRepository.saveAndFlush(medical); + Lot lot = testLot.setup(medical, false); + lotIoOperationRepository.saveAndFlush(lot); + MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false); + int inventoryId = medicalInventoryRow.getId(); + MedicalInventoryRow newMedicalInventoryRow = medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); + assertThat(newMedicalInventoryRow).isNotNull(); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); + assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows).hasSize(1); + medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows); + inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); + String status = InventoryStatus.done.toString(); + inventory.setStatus(status); + inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory); + assertThat(inventory).isNotNull(); + assertThat(inventory.getStatus()).isEqualTo(status); + } } From b99bf6922ce55498ea20a4a2218677d8698c639f Mon Sep 17 00:00:00 2001 From: FOFOU FONZAM Gui Arnaud <101590821+ArnaudFonzam@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:28:25 +0100 Subject: [PATCH 04/22] Update src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java Co-authored-by: Alessandro Domanico --- .../manager/MedicalInventoryManager.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 380d3c00e..5b14dd6c8 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -416,25 +416,17 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List theoQty && !isNew) { // charge movement when realQty > theoQty + if (realQty > theoQty) { // charge movement when realQty > theoQty Movement movement = new Movement(medical, chargeType, null, currentLot, today, -(ajustQty.intValue()), supplier, reference); List chargeMovement = new ArrayList<>(); chargeMovement.add(movement); chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference); - } else if (realQty < theoQty && !isNew) { // discharge movement when realQty < theoQty + } else { // discharge movement when realQty < theoQty Movement movement = new Movement(medical, dischargeType, ward, currentLot, today, ajustQty.intValue(), null, reference); List dischargeMovement = new ArrayList<>(); dischargeMovement.add(movement); dischargeMovement = movStockInsertingManager.newMultipleDischargingMovements(dischargeMovement, reference); } - // If new lot has been inserted, create charge movement with real qty - if (isNew) { - Movement movement = new Movement(medical, chargeType, null, currentLot, today, (int) realQty, supplier, reference); - List chargeMovement = new ArrayList<>(); - chargeMovement.add(movement); - chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference); - } } } } From f7170287ed94d1cbdf7b43ad5f7f4a35d42d09b9 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 7 Oct 2024 15:42:51 +0100 Subject: [PATCH 05/22] add transactional annotation --- .../isf/medicalinventory/manager/MedicalInventoryManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 5b14dd6c8..84cddf276 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -394,6 +394,7 @@ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceE * @param inventoryRowSearchList- The list of {@link MedicalInventory} * @throws OHDataValidationException */ + @Transactional(rollbackFor = OHServiceException.class) public void confirmMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { // validate the inventory this.validateMedicalInventoryRow(inventory, inventoryRowSearchList); From 642376844585260211765f35ae9a32bc67767f09 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Mon, 7 Oct 2024 17:49:15 +0100 Subject: [PATCH 06/22] use TimeTools not LocalDateTime to have time --- .../manager/MedicalInventoryManager.java | 3 +-- .../medicalsinventory/TestMedicalInventory.java | 8 +++++--- .../java/org/isf/medicalsinventory/Tests.java | 16 +++++++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 84cddf276..b256bd774 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -394,7 +394,6 @@ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceE * @param inventoryRowSearchList- The list of {@link MedicalInventory} * @throws OHDataValidationException */ - @Transactional(rollbackFor = OHServiceException.class) public void confirmMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { // validate the inventory this.validateMedicalInventoryRow(inventory, inventoryRowSearchList); @@ -407,7 +406,7 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List iterator = inventoryRowSearchList.iterator(); iterator.hasNext();) { MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); diff --git a/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java b/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java index 42f59e6d5..b6473a629 100644 --- a/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java +++ b/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java @@ -28,18 +28,20 @@ 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 = InventoryStatus.draft.toString(); - private LocalDateTime inventoryDate = LocalDateTime.now(); - private String user = "USER"; + 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 String destination = "INV"; diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 3693d5fdd..57fc011d2 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -585,14 +585,16 @@ void testValidateMedicalInventory() throws Exception { Lot lot = testLot.setup(medical, false); lotIoOperationRepository.saveAndFlush(lot); MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false); - int inventoryId = medicalInventoryRow.getId(); + int inventoryRowId = medicalInventoryRow.getId(); MedicalInventoryRow newMedicalInventoryRow = medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); assertThat(newMedicalInventoryRow).isNotNull(); - List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId); assertThat(medicalInventoryRows).isNotEmpty(); assertThat(medicalInventoryRows).hasSize(1); medicalInventoryManager.validateMedicalInventoryRow(savedInventory, medicalInventoryRows); + int inventoryId = inventory.getId(); inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); + assertThat(inventory).isNotNull(); String status = InventoryStatus.validated.toString(); inventory.setStatus(status); inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory); @@ -611,16 +613,20 @@ void testConfirmMedicalInventory() throws Exception { Medical medical = testMedical.setup(medicalType, false); medicalsIoOperationRepository.saveAndFlush(medical); Lot lot = testLot.setup(medical, false); - lotIoOperationRepository.saveAndFlush(lot); + lot.setMainStoreQuantity(100); + lot = lotIoOperationRepository.saveAndFlush(lot); MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false); - int inventoryId = medicalInventoryRow.getId(); + int inventoryRowId = medicalInventoryRow.getId(); + medicalInventoryRow.setRealqty(40); MedicalInventoryRow newMedicalInventoryRow = medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); assertThat(newMedicalInventoryRow).isNotNull(); - List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId); assertThat(medicalInventoryRows).isNotEmpty(); assertThat(medicalInventoryRows).hasSize(1); medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows); + int inventoryId = savedInventory.getId(); inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); + assertThat(inventory).isNotNull(); String status = InventoryStatus.done.toString(); inventory.setStatus(status); inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory); From 9f3c23d12a9256017ecae0d942fbe6a9b5d8de08 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Tue, 8 Oct 2024 10:38:06 +0100 Subject: [PATCH 07/22] update src/test/java/org/isf/medicalsinventory/Tests.java --- .../manager/MedicalInventoryManager.java | 7 ++++--- src/test/java/org/isf/medicalsinventory/Tests.java | 9 +++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index b256bd774..a0c5caf73 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -394,6 +394,7 @@ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceE * @param inventoryRowSearchList- The list of {@link MedicalInventory} * @throws OHDataValidationException */ + @Transactional(rollbackFor = OHServiceException.class) public void confirmMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { // validate the inventory this.validateMedicalInventoryRow(inventory, inventoryRowSearchList); @@ -406,7 +407,7 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List iterator = inventoryRowSearchList.iterator(); iterator.hasNext();) { MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); @@ -417,12 +418,12 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List theoQty) { // charge movement when realQty > theoQty - Movement movement = new Movement(medical, chargeType, null, currentLot, today, -(ajustQty.intValue()), supplier, reference); + Movement movement = new Movement(medical, chargeType, null, currentLot, now, -(ajustQty.intValue()), supplier, reference); List chargeMovement = new ArrayList<>(); chargeMovement.add(movement); chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference); } else { // discharge movement when realQty < theoQty - Movement movement = new Movement(medical, dischargeType, ward, currentLot, today, ajustQty.intValue(), null, reference); + Movement movement = new Movement(medical, dischargeType, ward, currentLot, now, ajustQty.intValue(), null, reference); List dischargeMovement = new ArrayList<>(); dischargeMovement.add(movement); dischargeMovement = movStockInsertingManager.newMultipleDischargingMovements(dischargeMovement, reference); diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 57fc011d2..db14f14b0 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -40,6 +40,7 @@ import org.isf.medicals.TestMedical; import org.isf.medicals.model.Medical; import org.isf.medicals.service.MedicalsIoOperationRepository; +import org.isf.medicals.service.MedicalsIoOperations; import org.isf.medicalstock.TestLot; import org.isf.medicalstock.model.Lot; import org.isf.medicalstock.service.LotIoOperationRepository; @@ -96,6 +97,9 @@ class Tests extends OHCoreTestCase { @Autowired LotIoOperationRepository lotIoOperationRepository; + + @Autowired + MedicalsIoOperations medicalsIoOperations; @BeforeAll static void setUpClass() { @@ -611,10 +615,12 @@ void testConfirmMedicalInventory() throws Exception { MedicalType medicalType = testMedicalType.setup(false); medicalTypeIoOperationRepository.saveAndFlush(medicalType); Medical medical = testMedical.setup(medicalType, false); - medicalsIoOperationRepository.saveAndFlush(medical); + medical = medicalsIoOperationRepository.saveAndFlush(medical); + assertThat(medical).isNotNull(); Lot lot = testLot.setup(medical, false); lot.setMainStoreQuantity(100); lot = lotIoOperationRepository.saveAndFlush(lot); + assertThat(lot).isNotNull(); MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false); int inventoryRowId = medicalInventoryRow.getId(); medicalInventoryRow.setRealqty(40); @@ -622,7 +628,6 @@ void testConfirmMedicalInventory() throws Exception { assertThat(newMedicalInventoryRow).isNotNull(); List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId); assertThat(medicalInventoryRows).isNotEmpty(); - assertThat(medicalInventoryRows).hasSize(1); medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows); int inventoryId = savedInventory.getId(); inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); From 1763dc4504ab0d7c11eee95a807517d68af9dcbc Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Tue, 8 Oct 2024 18:15:55 +0100 Subject: [PATCH 08/22] update src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java --- .../manager/MedicalInventoryManager.java | 11 +++++++++-- .../java/org/isf/medicalsinventory/Tests.java | 18 +++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index a0c5caf73..576697567 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -408,9 +408,12 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List iterator = inventoryRowSearchList.iterator(); iterator.hasNext();) { MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); + StringBuilder referenceBuilder = new StringBuilder(); + referenceBuilder.append(inventory.getInventoryReference()) + .append("-") + .append(now); double theoQty = medicalInventoryRow.getTheoreticQty(); double realQty = medicalInventoryRow.getRealQty(); Double ajustQty = theoQty - realQty; @@ -418,11 +421,15 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List theoQty) { // charge movement when realQty > theoQty + referenceBuilder.append("-charge"); + String reference = referenceBuilder.toString(); Movement movement = new Movement(medical, chargeType, null, currentLot, now, -(ajustQty.intValue()), supplier, reference); List chargeMovement = new ArrayList<>(); chargeMovement.add(movement); chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference); - } else { // discharge movement when realQty < theoQty + } else if (realQty < theoQty) { // discharge movement when realQty < theoQty + referenceBuilder.append("-discharge"); + String reference = referenceBuilder.toString(); Movement movement = new Movement(medical, dischargeType, ward, currentLot, now, ajustQty.intValue(), null, reference); List dischargeMovement = new ArrayList<>(); dischargeMovement.add(movement); diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index db14f14b0..da586b3e4 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -27,6 +27,7 @@ import java.util.List; import org.isf.OHCoreTestCase; +import org.isf.generaldata.GeneralData; import org.isf.medicalinventory.manager.MedicalInventoryManager; import org.isf.medicalinventory.manager.MedicalInventoryRowManager; import org.isf.medicalinventory.model.InventoryStatus; @@ -40,7 +41,6 @@ import org.isf.medicals.TestMedical; import org.isf.medicals.model.Medical; import org.isf.medicals.service.MedicalsIoOperationRepository; -import org.isf.medicals.service.MedicalsIoOperations; import org.isf.medicalstock.TestLot; import org.isf.medicalstock.model.Lot; import org.isf.medicalstock.service.LotIoOperationRepository; @@ -99,7 +99,7 @@ class Tests extends OHCoreTestCase { LotIoOperationRepository lotIoOperationRepository; @Autowired - MedicalsIoOperations medicalsIoOperations; + MedicalInventoryRowIoOperationRepository medicalInventoryRowIoOperationRepository; @BeforeAll static void setUpClass() { @@ -613,19 +613,15 @@ void testConfirmMedicalInventory() throws Exception { MedicalInventory inventory = testMedicalInventory.setup(ward, false); MedicalInventory savedInventory = medicalInventoryIoOperation.newMedicalInventory(inventory); MedicalType medicalType = testMedicalType.setup(false); - medicalTypeIoOperationRepository.saveAndFlush(medicalType); Medical medical = testMedical.setup(medicalType, false); - medical = medicalsIoOperationRepository.saveAndFlush(medical); - assertThat(medical).isNotNull(); Lot lot = testLot.setup(medical, false); - lot.setMainStoreQuantity(100); - lot = lotIoOperationRepository.saveAndFlush(lot); - assertThat(lot).isNotNull(); MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false); + medicalInventoryRow.setRealqty(60); + medicalTypeIoOperationRepository.saveAndFlush(medicalType); + medicalsIoOperationRepository.saveAndFlush(medical); + lotIoOperationRepository.saveAndFlush(lot); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRow); int inventoryRowId = medicalInventoryRow.getId(); - medicalInventoryRow.setRealqty(40); - MedicalInventoryRow newMedicalInventoryRow = medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); - assertThat(newMedicalInventoryRow).isNotNull(); List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId); assertThat(medicalInventoryRows).isNotEmpty(); medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows); From f881639a956a4859048efa50255df67df2005bb3 Mon Sep 17 00:00:00 2001 From: FOFOU FONZAM Gui Arnaud <101590821+ArnaudFonzam@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:34:33 +0100 Subject: [PATCH 09/22] Update src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java Co-authored-by: Alessandro Domanico --- .../isf/medicalinventory/manager/MedicalInventoryManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 576697567..33debefb3 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -416,7 +416,7 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List Date: Wed, 9 Oct 2024 08:34:49 +0100 Subject: [PATCH 10/22] Update src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java Co-authored-by: Alessandro Domanico --- .../isf/medicalinventory/manager/MedicalInventoryManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 33debefb3..a5b831896 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -423,7 +423,7 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List theoQty) { // charge movement when realQty > theoQty referenceBuilder.append("-charge"); String reference = referenceBuilder.toString(); - Movement movement = new Movement(medical, chargeType, null, currentLot, now, -(ajustQty.intValue()), supplier, reference); + Movement movement = new Movement(medical, chargeType, null, currentLot, now, ajustQty.intValue(), supplier, reference); List chargeMovement = new ArrayList<>(); chargeMovement.add(movement); chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference); From c15454630be886af5f99663fdad8537ca099fd23 Mon Sep 17 00:00:00 2001 From: FOFOU FONZAM Gui Arnaud <101590821+ArnaudFonzam@users.noreply.github.com> Date: Wed, 9 Oct 2024 08:35:07 +0100 Subject: [PATCH 11/22] Update src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java Co-authored-by: Alessandro Domanico --- .../isf/medicalinventory/manager/MedicalInventoryManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index a5b831896..ad779d0b7 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -420,7 +420,7 @@ public void confirmMedicalInventoryRow(MedicalInventory inventory, List theoQty) { // charge movement when realQty > theoQty + if (ajustQty > 0) { // charge movement when realQty > theoQty referenceBuilder.append("-charge"); String reference = referenceBuilder.toString(); Movement movement = new Movement(medical, chargeType, null, currentLot, now, ajustQty.intValue(), supplier, reference); From 550bbbe9c89a46b4043b56570fcbbd417a0e0946 Mon Sep 17 00:00:00 2001 From: mwithi Date: Wed, 9 Oct 2024 10:17:16 +0200 Subject: [PATCH 12/22] Fix lot check when charging and lotcode is not provided --- .../service/MedicalStockIoOperations.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/isf/medicalstock/service/MedicalStockIoOperations.java b/src/main/java/org/isf/medicalstock/service/MedicalStockIoOperations.java index 7fd528864..0b8e5fa0a 100644 --- a/src/main/java/org/isf/medicalstock/service/MedicalStockIoOperations.java +++ b/src/main/java/org/isf/medicalstock/service/MedicalStockIoOperations.java @@ -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; } @@ -180,26 +180,23 @@ public List 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); @@ -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. @@ -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); @@ -590,7 +590,8 @@ public List 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 From c51a908836a3639bffbf03a0ec4b2a4470a6d07e Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Wed, 9 Oct 2024 11:04:17 +0100 Subject: [PATCH 13/22] add suggestion --- .../manager/MedicalInventoryManager.java | 64 +++++++++---------- .../java/org/isf/medicalsinventory/Tests.java | 22 ++++++- 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 576697567..c9ae75b25 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -395,46 +395,46 @@ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceE * @throws OHDataValidationException */ @Transactional(rollbackFor = OHServiceException.class) - public void confirmMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { + public List confirmMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { // validate the inventory this.validateMedicalInventoryRow(inventory, inventoryRowSearchList); - // create Movements - String dischargeCode = inventory.getDischargeType(); - String chargeCode = inventory.getChargeType(); - Integer supplierId = inventory.getSupplier(); - String wardCode = inventory.getDestination(); - MovementType chargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(chargeCode); - MovementType dischargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(dischargeCode); - Supplier supplier = supplierManager.getByID(supplierId); - Ward ward = wardManager.findWard(wardCode); + // 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 chargeMovements = new ArrayList<>(); + List dischargeMovements = new ArrayList<>(); for (Iterator iterator = inventoryRowSearchList.iterator(); iterator.hasNext();) { MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next(); - StringBuilder referenceBuilder = new StringBuilder(); - referenceBuilder.append(inventory.getInventoryReference()) - .append("-") - .append(now); + double theoQty = medicalInventoryRow.getTheoreticQty(); double realQty = medicalInventoryRow.getRealQty(); - Double ajustQty = theoQty - realQty; + Double ajustQty = realQty - theoQty; Medical medical = medicalInventoryRow.getMedical(); - String lotCode = medicalInventoryRow.getLot().getCode(); - Lot currentLot = movStockInsertingManager.getLot(lotCode); - if (realQty > theoQty) { // charge movement when realQty > theoQty - referenceBuilder.append("-charge"); - String reference = referenceBuilder.toString(); - Movement movement = new Movement(medical, chargeType, null, currentLot, now, -(ajustQty.intValue()), supplier, reference); - List chargeMovement = new ArrayList<>(); - chargeMovement.add(movement); - chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference); - } else if (realQty < theoQty) { // discharge movement when realQty < theoQty - referenceBuilder.append("-discharge"); - String reference = referenceBuilder.toString(); - Movement movement = new Movement(medical, dischargeType, ward, currentLot, now, ajustQty.intValue(), null, reference); - List dischargeMovement = new ArrayList<>(); - dischargeMovement.add(movement); - dischargeMovement = movStockInsertingManager.newMultipleDischargingMovements(dischargeMovement, reference); - } + 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 insertedMovements = new ArrayList<>(); + if (!chargeMovements.isEmpty()) { + insertedMovements.addAll(movStockInsertingManager.newMultipleChargingMovements(chargeMovements, chargeReferenceNumber)); + } + if (!dischargeMovements.isEmpty()) { + insertedMovements.addAll(movStockInsertingManager.newMultipleDischargingMovements(dischargeMovements, dischargeReferenceNumber)); } + return insertedMovements; } } diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index da586b3e4..23fcdb362 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -43,10 +43,15 @@ import org.isf.medicals.service.MedicalsIoOperationRepository; import org.isf.medicalstock.TestLot; import org.isf.medicalstock.model.Lot; +import org.isf.medicalstock.model.Movement; import org.isf.medicalstock.service.LotIoOperationRepository; +import org.isf.medstockmovtype.model.MovementType; +import org.isf.medstockmovtype.service.MedicalDsrStockMovementTypeIoOperationRepository; import org.isf.medtype.TestMedicalType; import org.isf.medtype.model.MedicalType; import org.isf.medtype.service.MedicalTypeIoOperationRepository; +import org.isf.supplier.model.Supplier; +import org.isf.supplier.service.SupplierIoOperationRepository; import org.isf.utils.exception.OHException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.time.TimeTools; @@ -100,6 +105,12 @@ class Tests extends OHCoreTestCase { @Autowired MedicalInventoryRowIoOperationRepository medicalInventoryRowIoOperationRepository; + + @Autowired + MedicalDsrStockMovementTypeIoOperationRepository medicalDsrStockMovementTypeIoOperationRepository; + + @Autowired + SupplierIoOperationRepository supplierIoOperationRepository; @BeforeAll static void setUpClass() { @@ -610,6 +621,14 @@ void testValidateMedicalInventory() throws Exception { void testConfirmMedicalInventory() throws Exception { Ward ward = testWard.setup(false); wardIoOperationRepository.saveAndFlush(ward); + MovementType chargeType = new MovementType("inventory+", "inventory +", "+", "non-operational"); + MovementType dischargeType = new MovementType("inventory-", "inventory -", "-", "non-operational"); + Supplier supplier = new Supplier(3, "INVEnTORY", null, null, null, null, null, null); + Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); + medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(dischargeType); + medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(chargeType); + supplierIoOperationRepository.saveAndFlush(supplier); + wardIoOperationRepository.saveAndFlush(destination); MedicalInventory inventory = testMedicalInventory.setup(ward, false); MedicalInventory savedInventory = medicalInventoryIoOperation.newMedicalInventory(inventory); MedicalType medicalType = testMedicalType.setup(false); @@ -624,7 +643,8 @@ void testConfirmMedicalInventory() throws Exception { int inventoryRowId = medicalInventoryRow.getId(); List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId); assertThat(medicalInventoryRows).isNotEmpty(); - medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows); + List insertMovements = medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows); + assertThat(insertMovements).isNotEmpty(); int inventoryId = savedInventory.getId(); inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); assertThat(inventory).isNotNull(); From d2642d14091d02f607992ac4d400d39c48d27068 Mon Sep 17 00:00:00 2001 From: FOFOU FONZAM Gui Arnaud <101590821+ArnaudFonzam@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:04:47 +0100 Subject: [PATCH 14/22] Update src/test/java/org/isf/medicalsinventory/Tests.java Co-authored-by: Alessandro Domanico --- src/test/java/org/isf/medicalsinventory/Tests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 23fcdb362..350fcc0b3 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -621,8 +621,8 @@ void testValidateMedicalInventory() throws Exception { void testConfirmMedicalInventory() throws Exception { Ward ward = testWard.setup(false); wardIoOperationRepository.saveAndFlush(ward); - MovementType chargeType = new MovementType("inventory+", "inventory +", "+", "non-operational"); - MovementType dischargeType = new MovementType("inventory-", "inventory -", "-", "non-operational"); + MovementType chargeType = new MovementType("inventory+", "Inventory+", "+", "non-operational"); + MovementType dischargeType = new MovementType("inventory-", "Inventory-", "-", "non-operational"); Supplier supplier = new Supplier(3, "INVEnTORY", null, null, null, null, null, null); Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(dischargeType); From d668f5ca7f3278bdcbb090b7526de2b954b71736 Mon Sep 17 00:00:00 2001 From: FOFOU FONZAM Gui Arnaud <101590821+ArnaudFonzam@users.noreply.github.com> Date: Wed, 9 Oct 2024 17:04:57 +0100 Subject: [PATCH 15/22] Update src/test/java/org/isf/medicalsinventory/Tests.java Co-authored-by: Alessandro Domanico --- src/test/java/org/isf/medicalsinventory/Tests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 350fcc0b3..63499ccad 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -623,7 +623,7 @@ void testConfirmMedicalInventory() throws Exception { wardIoOperationRepository.saveAndFlush(ward); MovementType chargeType = new MovementType("inventory+", "Inventory+", "+", "non-operational"); MovementType dischargeType = new MovementType("inventory-", "Inventory-", "-", "non-operational"); - Supplier supplier = new Supplier(3, "INVEnTORY", null, null, null, null, null, null); + Supplier supplier = new Supplier(3, "INVENTORY", null, null, null, null, null, null); Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(dischargeType); medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(chargeType); From 6f8b0272d8e198c14aff7320ea55074337b55c65 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Wed, 9 Oct 2024 17:06:11 +0100 Subject: [PATCH 16/22] update src/test/java/org/isf/medicalsinventory/Tests.java --- .../org/isf/medicalstock/manager/MovStockInsertingManager.java | 2 +- src/test/java/org/isf/medicalsinventory/Tests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java index 0ce6061c7..53625b52e 100644 --- a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java +++ b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java @@ -330,7 +330,7 @@ public List newMultipleChargingMovements(List movements, Str errors.add(new OHExceptionMessage( mov.getMedical() != null ? mov.getMedical().getDescription() : MessageBundle.getMessage("angal.medicalstock.nodescription.txt"))); - throw new OHDataValidationException(errors); + throw new OHDataValidationException(errors.get(0)); } } return insertedMovements; diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 23fcdb362..400d32836 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -623,7 +623,7 @@ void testConfirmMedicalInventory() throws Exception { wardIoOperationRepository.saveAndFlush(ward); MovementType chargeType = new MovementType("inventory+", "inventory +", "+", "non-operational"); MovementType dischargeType = new MovementType("inventory-", "inventory -", "-", "non-operational"); - Supplier supplier = new Supplier(3, "INVEnTORY", null, null, null, null, null, null); + Supplier supplier = new Supplier(3, "INVENTORY", null, null, null, null, null, null); Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(dischargeType); medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(chargeType); From 59237d65c8af98832088ea2c552157d5199cc5c2 Mon Sep 17 00:00:00 2001 From: mwithi Date: Wed, 9 Oct 2024 19:03:17 +0200 Subject: [PATCH 17/22] Fix test --- .../TestMedicalInventory.java | 2 +- .../java/org/isf/medicalsinventory/Tests.java | 55 ++++++++++--------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java b/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java index b6473a629..e3b0aaa81 100644 --- a/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java +++ b/src/test/java/org/isf/medicalsinventory/TestMedicalInventory.java @@ -43,7 +43,7 @@ public class TestMedicalInventory { private String inventoryReference = "REFERENCE"; 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-"; diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 63499ccad..1f28e6c60 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -27,7 +27,6 @@ import java.util.List; import org.isf.OHCoreTestCase; -import org.isf.generaldata.GeneralData; import org.isf.medicalinventory.manager.MedicalInventoryManager; import org.isf.medicalinventory.manager.MedicalInventoryRowManager; import org.isf.medicalinventory.model.InventoryStatus; @@ -65,7 +64,7 @@ import org.springframework.data.domain.Page; class Tests extends OHCoreTestCase { - + private static TestMedicalInventory testMedicalInventory; private static TestMedicalInventoryRow testMedicalInventoryRow; private static TestWard testWard; @@ -81,34 +80,34 @@ class Tests extends OHCoreTestCase { @Autowired MedicalInventoryIoOperationRepository medIvnIoOperationRepository; - + @Autowired WardIoOperationRepository wardIoOperationRepository; - + @Autowired MedicalInventoryIoOperation medicalInventoryIoOperation; - + @Autowired MedicalInventoryRowIoOperationRepository medIvnRowIoOperationRepository; - + @Autowired MedicalInventoryRowIoOperation medIvnRowIoOperation; - + @Autowired MedicalsIoOperationRepository medicalsIoOperationRepository; - + @Autowired MedicalTypeIoOperationRepository medicalTypeIoOperationRepository; - + @Autowired LotIoOperationRepository lotIoOperationRepository; - + @Autowired MedicalInventoryRowIoOperationRepository medicalInventoryRowIoOperationRepository; - + @Autowired MedicalDsrStockMovementTypeIoOperationRepository medicalDsrStockMovementTypeIoOperationRepository; - + @Autowired SupplierIoOperationRepository supplierIoOperationRepository; @@ -121,12 +120,12 @@ static void setUpClass() { testLot = new TestLot(); testMedicalType = new TestMedicalType(); } - + @BeforeEach void setUp() { cleanH2InMemoryDb(); } - + @Test void testMedicalInventoryGets() throws Exception { int code = setupTestMedicalInventory(false); @@ -177,7 +176,7 @@ void testMedicalInventoryRowGetsSets() throws Exception { double realQty = -37.3; medicalInventoryRow.setRealqty(realQty); assertThat(medicalInventoryRow.getRealQty()).isEqualTo(realQty); - medicalInventoryRow.setRealQty(realQty); // Note the uppercase 'Q' + medicalInventoryRow.setRealQty(realQty); // Note the uppercase 'Q' assertThat(medicalInventoryRow.getRealQty()).isEqualTo(realQty); int lock = -99; @@ -221,7 +220,7 @@ void testIoNewMedicalInventory() throws Exception { checkMedicalInventoryIntoDb(newMedicalInventory.getId()); assertThat(medicalInventoryIoOperation.referenceExists(newMedicalInventory.getInventoryReference())).isTrue(); } - + @Test void testMgrUpdateMedicalInventory() throws Exception { Integer id = setupTestMedicalInventory(false); @@ -279,7 +278,8 @@ void testMgrGetMedicalInventoryWithStatus() throws Exception { inventory.setInventoryType(inventoryType); MedicalInventory secondMedicalInventory = medIvnIoOperationRepository.saveAndFlush(inventory); assertThat(secondMedicalInventory).isNotNull(); - List medicalInventories = medicalInventoryManager.getMedicalInventoryByStatusAndInventoryType(firstMedicalInventory.getStatus(), firstMedicalInventory.getInventoryType()); + List medicalInventories = medicalInventoryManager.getMedicalInventoryByStatusAndInventoryType(firstMedicalInventory.getStatus(), + firstMedicalInventory.getInventoryType()); assertThat(medicalInventories).hasSize(1); assertThat(medicalInventories.get(0).getStatus()).isEqualTo(firstMedicalInventory.getStatus()); } @@ -297,7 +297,8 @@ void testIoGetMedicalInventoryWithStatus() throws Exception { inventory.setInventoryType(inventoryType); MedicalInventory secondMedicalInventory = medIvnIoOperationRepository.saveAndFlush(inventory); assertThat(secondMedicalInventory).isNotNull(); - List medicalInventories = medicalInventoryIoOperation.getMedicalInventoryByStatusAndInventoryType(firstMedicalInventory.getStatus(), firstMedicalInventory.getInventoryType()); + List medicalInventories = medicalInventoryIoOperation.getMedicalInventoryByStatusAndInventoryType(firstMedicalInventory.getStatus(), + firstMedicalInventory.getInventoryType()); assertThat(medicalInventories).hasSize(1); assertThat(medicalInventories.get(0).getStatus()).isEqualTo(firstMedicalInventory.getStatus()); } @@ -340,7 +341,7 @@ void testIoGetMedicalInventoryWithStatusAndWard() throws Exception { MedicalInventory secondMedicalInventory = medIvnIoOperationRepository.saveAndFlush(inventory); assertThat(secondMedicalInventory).isNotNull(); List medicalinventories = medicalInventoryIoOperation - .getMedicalInventoryByStatusAndWard(firstMedicalInventory.getStatus(), firstMedicalInventory.getWard()); + .getMedicalInventoryByStatusAndWard(firstMedicalInventory.getStatus(), firstMedicalInventory.getWard()); assertThat(medicalinventories).hasSize(1); assertThat(medicalinventories.get(0).getStatus()).isEqualTo(firstMedicalInventory.getStatus()); assertThat(medicalinventories.get(0).getWard()).isEqualTo(firstMedicalInventory.getWard()); @@ -516,7 +517,7 @@ void testMgrUpdateMedicalInventoryRow() throws Exception { MedicalInventoryRow updatedMedicalInventoryRow = medicalInventoryRowManager.updateMedicalInventoryRow(foundMedicalInventoryRow); assertThat(updatedMedicalInventoryRow.getRealQty()).isEqualTo(realQty); } - + @Test void testMgrGetMedicalInventoryRowByInventoryId() throws Exception { Ward ward = testWard.setup(false); @@ -535,7 +536,7 @@ void testMgrGetMedicalInventoryRowByInventoryId() throws Exception { assertThat(newMedicalInventoryRow).isNotNull(); List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); assertThat(medicalInventoryRows).isNotEmpty(); - assertThat(medicalInventoryRows).hasSize(1); + assertThat(medicalInventoryRows).hasSize(1); } private int setupTestMedicalInventory(boolean usingSet) throws OHException, OHServiceException { @@ -545,7 +546,7 @@ private int setupTestMedicalInventory(boolean usingSet) throws OHException, OHSe MedicalInventory savedMedicalInventory = medicalInventoryIoOperation.newMedicalInventory(medicalInventory); return savedMedicalInventory.getId(); } - + private void checkMedicalInventoryIntoDb(int id) throws OHException { MedicalInventory foundMedicalInventory = medIvnIoOperationRepository.findById(id).orElse(null); assertThat(foundMedicalInventory).isNotNull(); @@ -586,7 +587,7 @@ void testDeleteInventory() throws Exception { assertThat(deletedInventory).isNotNull(); assertThat(deletedInventory.getStatus()).isEqualTo(InventoryStatus.canceled.toString()); } - + @Test void testValidateMedicalInventory() throws Exception { Ward ward = testWard.setup(false); @@ -614,16 +615,16 @@ void testValidateMedicalInventory() throws Exception { inventory.setStatus(status); inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory); assertThat(inventory).isNotNull(); - assertThat(inventory.getStatus()).isEqualTo(status); + assertThat(inventory.getStatus()).isEqualTo(status); } - + @Test void testConfirmMedicalInventory() throws Exception { Ward ward = testWard.setup(false); wardIoOperationRepository.saveAndFlush(ward); MovementType chargeType = new MovementType("inventory+", "Inventory+", "+", "non-operational"); MovementType dischargeType = new MovementType("inventory-", "Inventory-", "-", "non-operational"); - Supplier supplier = new Supplier(3, "INVENTORY", null, null, null, null, null, null); + Supplier supplier = new Supplier(1, "INVENTORY", null, null, null, null, null, null); Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(dischargeType); medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(chargeType); @@ -652,6 +653,6 @@ void testConfirmMedicalInventory() throws Exception { inventory.setStatus(status); inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory); assertThat(inventory).isNotNull(); - assertThat(inventory.getStatus()).isEqualTo(status); + assertThat(inventory.getStatus()).isEqualTo(status); } } From 80ee0f523e8405d7d808f628d973c12b31d4a00e Mon Sep 17 00:00:00 2001 From: mwithi Date: Wed, 9 Oct 2024 19:07:09 +0200 Subject: [PATCH 18/22] Add TODO comments in Supplier class --- src/main/java/org/isf/supplier/model/Supplier.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/isf/supplier/model/Supplier.java b/src/main/java/org/isf/supplier/model/Supplier.java index 1d521de22..20cc63f80 100644 --- a/src/main/java/org/isf/supplier/model/Supplier.java +++ b/src/main/java/org/isf/supplier/model/Supplier.java @@ -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; @@ -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; From 7a4c54f5afdea97b09be478c417c2bb1d29aefc2 Mon Sep 17 00:00:00 2001 From: Alessandro Domanico Date: Wed, 9 Oct 2024 23:40:22 +0200 Subject: [PATCH 19/22] Update src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java --- .../org/isf/medicalstock/manager/MovStockInsertingManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java index 53625b52e..0ce6061c7 100644 --- a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java +++ b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java @@ -330,7 +330,7 @@ public List newMultipleChargingMovements(List movements, Str errors.add(new OHExceptionMessage( mov.getMedical() != null ? mov.getMedical().getDescription() : MessageBundle.getMessage("angal.medicalstock.nodescription.txt"))); - throw new OHDataValidationException(errors.get(0)); + throw new OHDataValidationException(errors); } } return insertedMovements; From 10f065577da0146e083e30c250ed3a9312cd7b87 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Thu, 10 Oct 2024 16:49:55 +0100 Subject: [PATCH 20/22] update src/test/java/org/isf/medicalsinventory/Tests.java --- .../manager/MedicalInventoryManager.java | 22 ++--- .../java/org/isf/medicalsinventory/Tests.java | 80 ++++++++++++------- 2 files changed, 59 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index c9ae75b25..874fa4c96 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -30,6 +30,7 @@ import org.isf.generaldata.GeneralData; import org.isf.generaldata.MessageBundle; +import org.isf.medicalinventory.model.InventoryStatus; import org.isf.medicalinventory.model.MedicalInventory; import org.isf.medicalinventory.model.MedicalInventoryRow; import org.isf.medicalinventory.service.MedicalInventoryIoOperation; @@ -105,21 +106,6 @@ public MedicalInventory updateMedicalInventory(MedicalInventory medicalInventory return ioOperations.updateMedicalInventory(medicalInventory); } - /** - * Delete the specified {@link MedicalInventory}. - * - * @param medicalInventory - the {@link MedicalInventory} to delete. - * @throws OHServiceException - */ - @Transactional(rollbackFor = OHServiceException.class) - public void deleteMedicalInventory(MedicalInventory medicalInventory) throws OHServiceException { - List inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(medicalInventory.getId()); - for (MedicalInventoryRow invRow : inventoryRowList) { - medicalInventoryRowManager.deleteMedicalInventoryRow(invRow); - } - ioOperations.deleteMedicalInventory(medicalInventory); - } - /** * Check if the reference number is already used. * @@ -364,6 +350,9 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, List confirmMedicalInventoryRow(MedicalInventory inventory, Lis if (!dischargeMovements.isEmpty()) { insertedMovements.addAll(movStockInsertingManager.newMultipleDischargingMovements(dischargeMovements, dischargeReferenceNumber)); } + String status = InventoryStatus.done.toString(); + inventory.setStatus(status); + this.updateMedicalInventory(inventory); return insertedMovements; } } diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 1f28e6c60..78173cb41 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -23,10 +23,13 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; +import java.util.stream.Stream; import org.isf.OHCoreTestCase; +import org.isf.generaldata.GeneralData; import org.isf.medicalinventory.manager.MedicalInventoryManager; import org.isf.medicalinventory.manager.MedicalInventoryRowManager; import org.isf.medicalinventory.model.InventoryStatus; @@ -60,6 +63,9 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; @@ -111,6 +117,24 @@ class Tests extends OHCoreTestCase { @Autowired SupplierIoOperationRepository supplierIoOperationRepository; + static Stream automaticlot() { + return Stream.of( + Arguments.of(false, false, false), + Arguments.of(false, false, true), + Arguments.of(false, true, false), + Arguments.of(false, true, true), + Arguments.of(true, false, false), + Arguments.of(true, false, true), + Arguments.of(true, true, false), + Arguments.of(true, true, true)); + } + + private static void setGeneralData(boolean in, boolean out, boolean toward) { + GeneralData.AUTOMATICLOT_IN = in; + GeneralData.AUTOMATICLOT_OUT = out; + GeneralData.AUTOMATICLOTWARD_TOWARD = toward; + } + @BeforeAll static void setUpClass() { testMedicalInventory = new TestMedicalInventory(); @@ -243,16 +267,6 @@ void testIoUpdateMedicalInventory() throws Exception { assertThat(updatedMedicalInventory.getStatus()).isEqualTo(status); } - @Test - void testMgrDeleteMedicalInventory() throws Exception { - Integer id = setupTestMedicalInventory(false); - MedicalInventory foundMedicalInventory = medIvnIoOperationRepository.findById(id).orElse(null); - assertThat(foundMedicalInventory).isNotNull(); - String reference = foundMedicalInventory.getInventoryReference(); - medicalInventoryManager.deleteMedicalInventory(foundMedicalInventory); - assertThat(medicalInventoryManager.referenceExists(reference)).isFalse(); - } - @Test void testIoDeleteMedicalInventory() throws Exception { Integer id = setupTestMedicalInventory(false); @@ -609,17 +623,16 @@ void testValidateMedicalInventory() throws Exception { assertThat(medicalInventoryRows).hasSize(1); medicalInventoryManager.validateMedicalInventoryRow(savedInventory, medicalInventoryRows); int inventoryId = inventory.getId(); - inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); - assertThat(inventory).isNotNull(); String status = InventoryStatus.validated.toString(); - inventory.setStatus(status); - inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory); + inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); assertThat(inventory).isNotNull(); assertThat(inventory.getStatus()).isEqualTo(status); } - @Test - void testConfirmMedicalInventory() throws Exception { + @ParameterizedTest(name = "Test with AUTOMATICLOT_IN={0}, AUTOMATICLOT_OUT={1}, AUTOMATICLOTWARD_TOWARD={2}") + @MethodSource("automaticlot") + void testConfirmMedicalInventory(boolean in, boolean out, boolean toward) throws Exception { + setGeneralData(in, out, toward); Ward ward = testWard.setup(false); wardIoOperationRepository.saveAndFlush(ward); MovementType chargeType = new MovementType("inventory+", "Inventory+", "+", "non-operational"); @@ -634,24 +647,35 @@ void testConfirmMedicalInventory() throws Exception { MedicalInventory savedInventory = medicalInventoryIoOperation.newMedicalInventory(inventory); MedicalType medicalType = testMedicalType.setup(false); Medical medical = testMedical.setup(medicalType, false); - Lot lot = testLot.setup(medical, false); - MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false); - medicalInventoryRow.setRealqty(60); + Lot lotOne = testLot.setup(medical, false); + LocalDateTime preparationDate = LocalDateTime.of(2024, 8, 1, 0, 0); + LocalDateTime dueDate = LocalDateTime.of(2024, 10, 1, 0, 0); + BigDecimal cost = new BigDecimal(25); + Lot lotTwo = new Lot(medical, "LOT-001", preparationDate, dueDate, cost); + Lot lotThree = new Lot(medical, "LOT-002", preparationDate, dueDate, cost); + MedicalInventoryRow medicalInventoryRowOne = testMedicalInventoryRow.setup(savedInventory, medical, lotOne, false); + MedicalInventoryRow medicalInventoryRowTwo = testMedicalInventoryRow.setup(savedInventory, medical, lotTwo, false); + medicalInventoryRowTwo.setId(2); + medicalInventoryRowTwo.setRealqty(30); + MedicalInventoryRow medicalInventoryRowThree = testMedicalInventoryRow.setup(savedInventory, medical, lotThree, false); + medicalInventoryRowThree.setId(3); + medicalInventoryRowThree.setRealqty(60); medicalTypeIoOperationRepository.saveAndFlush(medicalType); medicalsIoOperationRepository.saveAndFlush(medical); - lotIoOperationRepository.saveAndFlush(lot); - medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRow); - int inventoryRowId = medicalInventoryRow.getId(); - List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId); + lotIoOperationRepository.saveAndFlush(lotOne); + lotIoOperationRepository.saveAndFlush(lotTwo); + lotIoOperationRepository.saveAndFlush(lotThree); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowOne); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowTwo); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowThree); + int inventoryId = savedInventory.getId(); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows.size()).isEqualTo(3); List insertMovements = medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows); assertThat(insertMovements).isNotEmpty(); - int inventoryId = savedInventory.getId(); - inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); - assertThat(inventory).isNotNull(); String status = InventoryStatus.done.toString(); - inventory.setStatus(status); - inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory); + inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); assertThat(inventory).isNotNull(); assertThat(inventory.getStatus()).isEqualTo(status); } From ade0e6c2b32be267b92c56e8d16451dd3e5f5307 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Fri, 11 Oct 2024 11:49:40 +0100 Subject: [PATCH 21/22] update src/test/java/org/isf/medicalsinventory/Tests.java --- .../java/org/isf/medicalsinventory/Tests.java | 153 +++++++++++++----- 1 file changed, 115 insertions(+), 38 deletions(-) diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 78173cb41..6b8f65494 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -23,7 +23,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; import java.util.stream.Stream; @@ -44,9 +43,14 @@ import org.isf.medicals.model.Medical; import org.isf.medicals.service.MedicalsIoOperationRepository; import org.isf.medicalstock.TestLot; +import org.isf.medicalstock.TestMedicalStock; +import org.isf.medicalstock.TestMovement; import org.isf.medicalstock.model.Lot; +import org.isf.medicalstock.model.MedicalStock; import org.isf.medicalstock.model.Movement; import org.isf.medicalstock.service.LotIoOperationRepository; +import org.isf.medicalstock.service.MedicalStockIoOperationRepository; +import org.isf.medicalstock.service.MedicalStockIoOperations; import org.isf.medstockmovtype.model.MovementType; import org.isf.medstockmovtype.service.MedicalDsrStockMovementTypeIoOperationRepository; import org.isf.medtype.TestMedicalType; @@ -77,6 +81,8 @@ class Tests extends OHCoreTestCase { private static TestMedical testMedical; private static TestLot testLot; private static TestMedicalType testMedicalType; + private static TestMovement testMovement; + private static TestMedicalStock testMedicalStock; @Autowired MedicalInventoryManager medicalInventoryManager; @@ -116,17 +122,18 @@ class Tests extends OHCoreTestCase { @Autowired SupplierIoOperationRepository supplierIoOperationRepository; + + @Autowired + MedicalStockIoOperationRepository medicalStockIoOperationRepository; + + @Autowired + MedicalStockIoOperations medicalStockIoOperation; static Stream automaticlot() { - return Stream.of( - Arguments.of(false, false, false), - Arguments.of(false, false, true), - Arguments.of(false, true, false), - Arguments.of(false, true, true), - Arguments.of(true, false, false), - Arguments.of(true, false, true), - Arguments.of(true, true, false), - Arguments.of(true, true, true)); + return Stream.of(Arguments.of(true, true, false), + Arguments.of(true, true, true), + Arguments.of(false, true, false), + Arguments.of(false, true, true)); } private static void setGeneralData(boolean in, boolean out, boolean toward) { @@ -143,6 +150,8 @@ static void setUpClass() { testMedical = new TestMedical(); testLot = new TestLot(); testMedicalType = new TestMedicalType(); + testMovement = new TestMovement(); + testMedicalStock = new TestMedicalStock(); } @BeforeEach @@ -268,15 +277,42 @@ void testIoUpdateMedicalInventory() throws Exception { } @Test - void testIoDeleteMedicalInventory() throws Exception { + void testDeleteMedicalInventoryWithInventoryRowsWithoutNewLot() throws Exception { Integer id = setupTestMedicalInventory(false); MedicalInventory foundMedicalInventory = medIvnIoOperationRepository.findById(id).orElse(null); assertThat(foundMedicalInventory).isNotNull(); - String reference = foundMedicalInventory.getInventoryReference(); - Integer code = foundMedicalInventory.getId(); - medicalInventoryIoOperation.deleteMedicalInventory(foundMedicalInventory); - assertThat(medicalInventoryIoOperation.referenceExists(reference)).isFalse(); - assertThat(medicalInventoryIoOperation.isCodePresent(code)).isFalse(); + MedicalType medicalType = testMedicalType.setup(false); + Medical medical = testMedical.setup(medicalType, false); + Lot lot = testLot.setup(medical, false); + medicalType = medicalTypeIoOperationRepository.save(medicalType); + medical = medicalsIoOperationRepository.save(medical); + lot = lotIoOperationRepository.save(lot); + MedicalInventoryRow medicalInventoryRowOne = testMedicalInventoryRow.setup(foundMedicalInventory, medical, lot, false); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowOne); + medicalInventoryManager.deleteInventory(foundMedicalInventory); + foundMedicalInventory = medIvnIoOperationRepository.findById(id).orElse(null); + assertThat(foundMedicalInventory).isNotNull(); + assertThat(foundMedicalInventory.getStatus()).isEqualTo(InventoryStatus.canceled.toString()); + } + + @Test + void testDeleteMedicalInventoryWithInventoryRowsWithNewLot() throws Exception { + Integer id = setupTestMedicalInventory(false); + MedicalInventory foundMedicalInventory = medIvnIoOperationRepository.findById(id).orElse(null); + assertThat(foundMedicalInventory).isNotNull(); + MedicalType medicalType = testMedicalType.setup(false); + Medical medical = testMedical.setup(medicalType, false); + Lot lot = testLot.setup(medical, false); + medicalType = medicalTypeIoOperationRepository.save(medicalType); + medical = medicalsIoOperationRepository.save(medical); + lot = lotIoOperationRepository.save(lot); + MedicalInventoryRow medicalInventoryRowOne = testMedicalInventoryRow.setup(foundMedicalInventory, medical, lot, false); + medicalInventoryRowOne.setNewLot(true); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowOne); + medicalInventoryManager.deleteInventory(foundMedicalInventory); + foundMedicalInventory = medIvnIoOperationRepository.findById(id).orElse(null); + assertThat(foundMedicalInventory).isNotNull(); + assertThat(foundMedicalInventory.getStatus()).isEqualTo(InventoryStatus.canceled.toString()); } @Test @@ -603,7 +639,7 @@ void testDeleteInventory() throws Exception { } @Test - void testValidateMedicalInventory() throws Exception { + void testValidateMedicalInventoryRow() throws Exception { Ward ward = testWard.setup(false); wardIoOperationRepository.saveAndFlush(ward); MedicalInventory inventory = testMedicalInventory.setup(ward, false); @@ -639,44 +675,85 @@ void testConfirmMedicalInventory(boolean in, boolean out, boolean toward) throws MovementType dischargeType = new MovementType("inventory-", "Inventory-", "-", "non-operational"); Supplier supplier = new Supplier(1, "INVENTORY", null, null, null, null, null, null); Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); - medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(dischargeType); - medicalDsrStockMovementTypeIoOperationRepository.saveAndFlush(chargeType); - supplierIoOperationRepository.saveAndFlush(supplier); - wardIoOperationRepository.saveAndFlush(destination); + dischargeType = medicalDsrStockMovementTypeIoOperationRepository.save(dischargeType); + chargeType = medicalDsrStockMovementTypeIoOperationRepository.save(chargeType); + supplier = supplierIoOperationRepository.save(supplier); + destination = wardIoOperationRepository.save(destination); MedicalInventory inventory = testMedicalInventory.setup(ward, false); - MedicalInventory savedInventory = medicalInventoryIoOperation.newMedicalInventory(inventory); + inventory.setChargeType(chargeType.getCode()); + inventory.setDestination(destination.getCode()); + inventory.setSupplier(supplier.getSupId()); + inventory.setDischargeType(dischargeType.getCode()); + inventory = medicalInventoryIoOperation.newMedicalInventory(inventory); MedicalType medicalType = testMedicalType.setup(false); Medical medical = testMedical.setup(medicalType, false); Lot lotOne = testLot.setup(medical, false); - LocalDateTime preparationDate = LocalDateTime.of(2024, 8, 1, 0, 0); - LocalDateTime dueDate = LocalDateTime.of(2024, 10, 1, 0, 0); - BigDecimal cost = new BigDecimal(25); - Lot lotTwo = new Lot(medical, "LOT-001", preparationDate, dueDate, cost); - Lot lotThree = new Lot(medical, "LOT-002", preparationDate, dueDate, cost); - MedicalInventoryRow medicalInventoryRowOne = testMedicalInventoryRow.setup(savedInventory, medical, lotOne, false); - MedicalInventoryRow medicalInventoryRowTwo = testMedicalInventoryRow.setup(savedInventory, medical, lotTwo, false); + Movement firstMovement = testMovement.setup(medical, chargeType, ward, lotOne, supplier, false); + firstMovement.setQuantity(100); + MedicalStock firstmedicalStock = testMedicalStock.setup(firstMovement); + Lot lotTwo = testLot.setup(medical, false); + lotTwo.setCode("LOT-001"); + Movement secondMovement = testMovement.setup(medical, chargeType, ward, lotTwo, supplier, false); + secondMovement.setQuantity(100); + MedicalStock secondmedicalStock = testMedicalStock.setup(firstMovement); + Lot lotThree = testLot.setup(medical, false); + lotTwo.setCode("LOT-003"); + medicalType = medicalTypeIoOperationRepository.save(medicalType); + medical = medicalsIoOperationRepository.save(medical); + lotOne = lotIoOperationRepository.save(lotOne); + lotTwo = lotIoOperationRepository.save(lotTwo); + lotThree = lotIoOperationRepository.save(lotThree); + firstMovement = medicalStockIoOperation.newMovement(firstMovement); + secondMovement = medicalStockIoOperation.newMovement(secondMovement); + medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); + medicalStockIoOperationRepository.saveAndFlush(secondmedicalStock); + MedicalInventoryRow medicalInventoryRowOne = testMedicalInventoryRow.setup(inventory, medical, lotOne, false); + medicalInventoryRowOne.setRealqty(60); + MedicalInventoryRow medicalInventoryRowTwo = testMedicalInventoryRow.setup(inventory, medical, lotTwo, false); medicalInventoryRowTwo.setId(2); medicalInventoryRowTwo.setRealqty(30); - MedicalInventoryRow medicalInventoryRowThree = testMedicalInventoryRow.setup(savedInventory, medical, lotThree, false); + MedicalInventoryRow medicalInventoryRowThree = testMedicalInventoryRow.setup(inventory, medical, lotThree, false); medicalInventoryRowThree.setId(3); - medicalInventoryRowThree.setRealqty(60); - medicalTypeIoOperationRepository.saveAndFlush(medicalType); - medicalsIoOperationRepository.saveAndFlush(medical); - lotIoOperationRepository.saveAndFlush(lotOne); - lotIoOperationRepository.saveAndFlush(lotTwo); - lotIoOperationRepository.saveAndFlush(lotThree); medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowOne); medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowTwo); medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowThree); - int inventoryId = savedInventory.getId(); + int inventoryId = inventory.getId(); List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); assertThat(medicalInventoryRows).isNotEmpty(); assertThat(medicalInventoryRows.size()).isEqualTo(3); - List insertMovements = medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows); + List insertMovements = medicalInventoryManager.confirmMedicalInventoryRow(inventory, medicalInventoryRows); assertThat(insertMovements).isNotEmpty(); String status = InventoryStatus.done.toString(); inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); assertThat(inventory).isNotNull(); assertThat(inventory.getStatus()).isEqualTo(status); } + + @Test + void testReferenceOfInventoryExist() throws Exception { + int id = setupTestMedicalInventory(false); + MedicalInventory inventory = medIvnIoOperationRepository.findById(id).orElse(null); + assertThat(inventory).isNotNull(); + String reference = inventory.getInventoryReference(); + boolean exist = medicalInventoryManager.referenceExists(reference); + assertThat(exist).isEqualTo(true); + } + + @Test + void testGetInventoryByID() throws Exception { + int id = setupTestMedicalInventory(false); + MedicalInventory inventory = medicalInventoryManager.getInventoryById(id); + assertThat(inventory).isNotNull(); + } + + @Test + void testGetInventoryByReference() throws Exception { + int id = setupTestMedicalInventory(false); + MedicalInventory inventory = medIvnIoOperationRepository.findById(id).orElse(null); + assertThat(inventory).isNotNull(); + String reference = inventory.getInventoryReference(); + MedicalInventory found = medicalInventoryManager.getInventoryByReference(reference); + assertThat(found).isNotNull(); + assertThat(found.getInventoryReference()).isEqualTo(inventory.getInventoryReference()); + } } From fec550bb7dd0078989a2780c4ce02ce76bab9c65 Mon Sep 17 00:00:00 2001 From: ArnaudFonzam Date: Fri, 11 Oct 2024 18:08:55 +0100 Subject: [PATCH 22/22] start with validateInventory Test --- .../java/org/isf/medicalsinventory/Tests.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 6b8f65494..714ac20c3 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -756,4 +756,61 @@ void testGetInventoryByReference() throws Exception { assertThat(found).isNotNull(); assertThat(found.getInventoryReference()).isEqualTo(inventory.getInventoryReference()); } + + @Test + void testValidateMedicalInventory() throws Exception { + Ward ward = testWard.setup(false); + wardIoOperationRepository.saveAndFlush(ward); + MovementType chargeType = new MovementType("inventory+", "Inventory+", "+", "non-operational"); + MovementType dischargeType = new MovementType("inventory-", "Inventory-", "-", "non-operational"); + Supplier supplier = new Supplier(1, "INVENTORY", null, null, null, null, null, null); + Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); + dischargeType = medicalDsrStockMovementTypeIoOperationRepository.save(dischargeType); + chargeType = medicalDsrStockMovementTypeIoOperationRepository.save(chargeType); + supplier = supplierIoOperationRepository.save(supplier); + destination = wardIoOperationRepository.save(destination); + MedicalInventory inventory = testMedicalInventory.setup(ward, false); + inventory.setChargeType(chargeType.getCode()); + inventory.setDestination(destination.getCode()); + inventory.setSupplier(supplier.getSupId()); + inventory.setDischargeType(dischargeType.getCode()); + inventory = medicalInventoryIoOperation.newMedicalInventory(inventory); + MedicalType medicalType = testMedicalType.setup(false); + Medical medical = testMedical.setup(medicalType, false); + Lot lotOne = testLot.setup(medical, false); + Movement firstMovement = testMovement.setup(medical, chargeType, ward, lotOne, supplier, false); + firstMovement.setQuantity(100); + MedicalStock firstmedicalStock = testMedicalStock.setup(firstMovement); + Lot lotTwo = testLot.setup(medical, false); + lotTwo.setCode("LOT-001"); + Movement secondMovement = testMovement.setup(medical, chargeType, ward, lotTwo, supplier, false); + secondMovement.setQuantity(100); + MedicalStock secondmedicalStock = testMedicalStock.setup(firstMovement); + Lot lotThree = testLot.setup(medical, false); + lotTwo.setCode("LOT-003"); + medicalType = medicalTypeIoOperationRepository.save(medicalType); + medical = medicalsIoOperationRepository.save(medical); + lotOne = lotIoOperationRepository.save(lotOne); + lotTwo = lotIoOperationRepository.save(lotTwo); + lotThree = lotIoOperationRepository.save(lotThree); + MedicalInventoryRow medicalInventoryRowOne = testMedicalInventoryRow.setup(inventory, medical, lotOne, false); + medicalInventoryRowOne.setRealqty(60); + MedicalInventoryRow medicalInventoryRowTwo = testMedicalInventoryRow.setup(inventory, medical, lotTwo, false); + medicalInventoryRowTwo.setId(2); + medicalInventoryRowTwo.setRealqty(30); + MedicalInventoryRow medicalInventoryRowThree = testMedicalInventoryRow.setup(inventory, medical, lotThree, false); + medicalInventoryRowThree.setId(3); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowOne); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowTwo); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowThree); + firstMovement = medicalStockIoOperation.newMovement(firstMovement); + secondMovement = medicalStockIoOperation.newMovement(secondMovement); + medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); + medicalStockIoOperationRepository.saveAndFlush(secondmedicalStock); + int inventoryId = inventory.getId(); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); + assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows.size()).isEqualTo(3); + medicalInventoryManager.validateMedicalInventoryRow(inventory, medicalInventoryRows); + } }