From a6eafc382f2eff0a105f34db5980040dbac69497 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 19 Nov 2024 17:55:35 +0100 Subject: [PATCH 01/18] Add new column on medicalinventory --- ...escription_column_in_medical_inventory.sql | 1 + .../manager/MedicalInventoryManager.java | 14 +++++++++++ .../model/MedicalInventory.java | 24 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 sql/step_axxx_add_description_column_in_medical_inventory.sql diff --git a/sql/step_axxx_add_description_column_in_medical_inventory.sql b/sql/step_axxx_add_description_column_in_medical_inventory.sql new file mode 100644 index 000000000..dfae56669 --- /dev/null +++ b/sql/step_axxx_add_description_column_in_medical_inventory.sql @@ -0,0 +1 @@ +ALTER TABLE OH_MEDICALDSRINVENTORY ADD COLUMN MINVT_DESC VARCHAR(100) NULL; \ No newline at end of file diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 7ba2a8917..a9de059a6 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -352,6 +352,20 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { + LocalDateTime movFrom = inventory.getLastModifiedDate(); + LocalDateTime movTo = TimeTools.getNow(); + StringBuilder medDescriptionForNewMedical = new StringBuilder("\n"); // initial new line + boolean medicalAdded = false; + } + /** * Marks an inventory as deleted by changing its status. * diff --git a/src/main/java/org/isf/medicalinventory/model/MedicalInventory.java b/src/main/java/org/isf/medicalinventory/model/MedicalInventory.java index add0231f5..78fb309e3 100644 --- a/src/main/java/org/isf/medicalinventory/model/MedicalInventory.java +++ b/src/main/java/org/isf/medicalinventory/model/MedicalInventory.java @@ -86,6 +86,9 @@ public class MedicalInventory extends Auditable { @Column(name = "MINVT_DESTINATION") private String destination; + + @Column(name = "MINVT_DESC") + private String reason; @Version @Column(name="MINVT_LOCK") @@ -120,6 +123,19 @@ public MedicalInventory(Integer id, String status, LocalDateTime inventoryDate, this.destination = destination; } + public MedicalInventory(Integer id, String status, LocalDateTime inventoryDate, String user, String inventoryReference, String inventoryType, String ward, + String destination, String reason) { + this.id = id; + this.status = status; + this.inventoryDate = inventoryDate; + this.user = user; + this.inventoryReference = inventoryReference; + this.inventoryType = inventoryType; + this.ward = ward; + this.destination = destination; + this.reason = reason; + } + public Integer getId() { return id; } @@ -223,4 +239,12 @@ public String getDestination() { public void setDestination(String destination) { this.destination = destination; } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } } From c9e61e998cc786e8b12e395ce192defe70992d94 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 20 Nov 2024 11:47:16 +0100 Subject: [PATCH 02/18] add validate ward inventory row function --- .../manager/MedicalInventoryManager.java | 103 +++++++++++++++++- 1 file changed, 102 insertions(+), 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 a9de059a6..8fdc289ff 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -23,8 +23,10 @@ import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import org.isf.generaldata.GeneralData; @@ -37,6 +39,9 @@ import org.isf.medicalstock.manager.MovStockInsertingManager; import org.isf.medicalstock.model.Lot; import org.isf.medicalstock.model.Movement; +import org.isf.medicalstockward.manager.MovWardBrowserManager; +import org.isf.medicalstockward.model.MedicalWard; +import org.isf.medicalstockward.model.MovementWard; import org.isf.utils.exception.OHDataValidationException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.exception.model.OHExceptionMessage; @@ -58,13 +63,16 @@ public class MedicalInventoryManager { private MovBrowserManager movBrowserManager; + private MovWardBrowserManager movWardBrowserManager; + public MedicalInventoryManager(MedicalInventoryIoOperation medicalInventoryIoOperation, MedicalInventoryRowManager medicalInventoryRowManager, MovStockInsertingManager movStockInsertingManager, - MovBrowserManager movBrowserManager) { + MovBrowserManager movBrowserManager, MovWardBrowserManager movWardBrowserManager) { this.ioOperations = medicalInventoryIoOperation; this.medicalInventoryRowManager = medicalInventoryRowManager; this.movStockInsertingManager = movStockInsertingManager; this.movBrowserManager = movBrowserManager; + this.movWardBrowserManager = movWardBrowserManager; } /** @@ -362,8 +370,101 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { LocalDateTime movFrom = inventory.getLastModifiedDate(); LocalDateTime movTo = TimeTools.getNow(); + StringBuilder medDescriptionForLotUpdated = new StringBuilder("\n"); // initial new line + StringBuilder medDescriptionForNewLot = new StringBuilder("\n"); // initial new line StringBuilder medDescriptionForNewMedical = new StringBuilder("\n"); // initial new line + boolean lotUpdated = false; + boolean lotAdded = false; boolean medicalAdded = false; + + List movementWards = new ArrayList<>(movWardBrowserManager.getMovementWard(inventory.getWard(), movFrom, movTo)); + List movementToWards = new ArrayList<>(movBrowserManager.getMovements(inventory.getWard(), movFrom, movTo)); + List inventoryMedicalsList = inventoryRowSearchList.stream() + .map(MedicalInventoryRow::getMedical) + .distinct() + .toList(); + + // Get all the lot of the ward movements + List lotOfMovements = new ArrayList<>(movementWards.stream().map(MovementWard::getLot).toList()); + // Get all the lot of the movements + lotOfMovements.addAll(movementToWards.stream().map(Movement::getLot).toList()); + // Remove duplicates by converting the list to a set + Set uniqueLots = new HashSet<>(lotOfMovements); + // Convert the set back to a list + List uniqueLotList = new ArrayList<>(uniqueLots); + // Cycle fetched movements to see if they impact inventoryRowSearchList + for (Lot lot : uniqueLotList) { + String lotCodeOfMovement = lot.getCode(); + String lotExpiringDate = TimeTools.formatDateTime(lot.getDueDate(), TimeTools.DD_MM_YYYY); + String lotInfo = GeneralData.AUTOMATICLOT_IN ? lotExpiringDate : lotCodeOfMovement; + Medical medical = lot.getMedical(); + String medicalDesc = medical.getDescription(); + Integer medicalCode = medical.getCode(); + double wardStoreQty = 0.0; + + Optional optMedicalWard = movWardBrowserManager.getMedicalsWard(inventory.getWard(), medical.getCode(), false).stream() + .filter(m -> m.getLot().getCode().equals(lotCodeOfMovement)).findFirst(); + + if (optMedicalWard.isPresent()) { + wardStoreQty = optMedicalWard.get().getQty(); + } + + // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should be enough) + Optional matchingRow = inventoryRowSearchList.stream() + .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) && row.getMedical().getCode().equals(medicalCode)) + .findFirst(); + + if (matchingRow.isPresent()) { + MedicalInventoryRow medicalInventoryRow = matchingRow.get(); + double theoQty = medicalInventoryRow.getTheoreticQty(); + if (wardStoreQty != theoQty) { + lotUpdated = true; + medDescriptionForLotUpdated + .append("\n") + .append(MessageBundle.formatMessage( + "angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.detail.fmt.msg", + medicalDesc, lotInfo, theoQty, wardStoreQty, wardStoreQty - theoQty)); + } + } else { + // TODO: to decide if to give control to the user about this + if (!inventoryMedicalsList.contains(medical)) { + // New medical + medicalAdded = true; + medDescriptionForNewMedical + .append("\n") + .append(MessageBundle.formatMessage( + "angal.inventory.newmedicalshavebeenfound.detail.fmt.msg", + medicalDesc, lotInfo, wardStoreQty)); + } else { + // New Lot + lotAdded = true; + medDescriptionForNewLot + .append("\n") + .append(MessageBundle.formatMessage( + "angal.inventory.newlotshavebeenaddedforsomemedical.detail.fmt.msg", + medicalDesc, lotInfo, wardStoreQty)); + } + } + } + List errors = new ArrayList<>(); + if (lotUpdated) { + errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), + MessageBundle.formatMessage("angal.inventory.theoreticalqtyhavebeenupdatedforsomemedicalward.fmt.msg", medDescriptionForLotUpdated), + OHSeverityLevel.INFO)); + } + if (lotAdded) { + errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), + MessageBundle.formatMessage("angal.inventory.newlotshavebeenaddedforsomemedicalward.fmt.msg", medDescriptionForNewLot), + OHSeverityLevel.INFO)); + } + if (medicalAdded) { + errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), + MessageBundle.formatMessage("angal.inventory.newmedicalshavebeenfoundward.fmt.msg", medDescriptionForNewMedical), + OHSeverityLevel.INFO)); + } + if (!errors.isEmpty()) { + throw new OHDataValidationException(errors); + } } /** From e9441a5994bddf35d97a1d97b39168fe1ab827cc Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 20 Nov 2024 18:06:40 +0100 Subject: [PATCH 03/18] Remove uneccessary format code --- .../manager/MedicalInventoryManager.java | 234 +++++++----------- 1 file changed, 93 insertions(+), 141 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 0758e14a7..cb27ae5bd 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -113,8 +113,7 @@ public MedicalInventory newMedicalInventory(MedicalInventory medicalInventory) t * @return the updated {@link MedicalInventory} object. * @throws OHServiceException */ - public MedicalInventory updateMedicalInventory(MedicalInventory medicalInventory, boolean checkReference) - throws OHServiceException { + public MedicalInventory updateMedicalInventory(MedicalInventory medicalInventory, boolean checkReference) throws OHServiceException { validateMedicalInventory(medicalInventory); if (checkReference) { checkReference(medicalInventory); @@ -136,26 +135,24 @@ public boolean referenceExists(String reference) throws OHServiceException { /** * Return a list of {@link MedicalInventory}s for passed params. * - * @param status - the {@link MedicalInventory} status. + * @param status - the {@link MedicalInventory} status. * @param wardCode - the {@link Ward} code. * @return the list of {@link MedicalInventory}s. It could be {@code empty}. * @throws OHServiceException */ - public List getMedicalInventoryByStatusAndWard(String status, String wardCode) - throws OHServiceException { + public List getMedicalInventoryByStatusAndWard(String status, String wardCode) throws OHServiceException { return ioOperations.getMedicalInventoryByStatusAndWard(status, wardCode); } /** * Return a list {@link MedicalInventory}s for passed params. * - * @param status - the {@link MedicalInventory} status. + * @param status - the {@link MedicalInventory} status. * @param inventoryType - the {@link MedicalInventory} type. * @return the list of {@link MedicalInventory}s. It could be {@code empty}. * @throws OHServiceException */ - public List getMedicalInventoryByStatusAndInventoryType(String status, String inventoryType) - throws OHServiceException { + public List getMedicalInventoryByStatusAndInventoryType(String status, String inventoryType) throws OHServiceException { return ioOperations.getMedicalInventoryByStatusAndInventoryType(status, inventoryType); } @@ -173,15 +170,14 @@ public List getMedicalInventory() throws OHServiceException { * Return a list of {@link MedicalInventory}s for passed params. * * @param dateFrom - the lowest date for the range. - * @param dateTo - the highest date for the range. - * @param status - the {@link MedicalInventory} status. - * @param type - the {@link MedicalInventory} type. + * @param dateTo - the highest date for the range. + * @param status - the {@link MedicalInventory} status. + * @param type - the {@link MedicalInventory} type. * @return the list of {@link MedicalInventory}s. It could be {@code empty}. * @throws OHServiceException */ - public List getMedicalInventoryByParams(LocalDateTime dateFrom, LocalDateTime dateTo, - String status, String type) - throws OHServiceException { + public List getMedicalInventoryByParams(LocalDateTime dateFrom, LocalDateTime dateTo, String status, String type) + throws OHServiceException { dateFrom = TimeTools.getBeginningOfDay(dateFrom); dateTo = TimeTools.getBeginningOfNextDay(dateTo); return ioOperations.getMedicalInventoryByParams(dateFrom, dateTo, status, type); @@ -191,17 +187,16 @@ public List getMedicalInventoryByParams(LocalDateTime dateFrom * Return a list of {@link MedicalInventory}s for passed params. * * @param dateFrom - the lower date for the range. - * @param dateTo - the highest date for the range. - * @param status - the {@link MedicalInventory} status. - * @param type - the {@link MedicalInventory} type. - * @param page - the page number. - * @param size - the page size. + * @param dateTo - the highest date for the range. + * @param status - the {@link MedicalInventory} status. + * @param type - the {@link MedicalInventory} type. + * @param page - the page number. + * @param size - the page size. * @return the list of {@link MedicalInventory}s. It could be {@code empty}. * @throws OHServiceException */ - public Page getMedicalInventoryByParamsPageable(LocalDateTime dateFrom, LocalDateTime dateTo, - String status, String type, int page, - int size) throws OHServiceException { + public Page getMedicalInventoryByParamsPageable(LocalDateTime dateFrom, LocalDateTime dateTo, String status, String type, int page, + int size) throws OHServiceException { dateFrom = TimeTools.getBeginningOfDay(dateFrom); dateTo = TimeTools.getBeginningOfNextDay(dateTo); return ioOperations.getMedicalInventoryByParamsPageable(dateFrom, dateTo, status, type, page, size); @@ -240,8 +235,7 @@ private void validateMedicalInventory(MedicalInventory medInventory) throws OHDa LocalDateTime tomorrow = LocalDateTime.now().plusDays(1); String reference = medInventory.getInventoryReference(); if (medInventory.getInventoryDate() == null) { - errors.add(new OHExceptionMessage( - MessageBundle.getMessage("angal.inventory.pleaseinsertavalidinventorydate.msg"))); + errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.pleaseinsertavalidinventorydate.msg"))); } if (medInventory.getInventoryDate() != null && medInventory.getInventoryDate().isAfter(tomorrow)) { errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.notdateinfuture.msg"))); @@ -257,13 +251,12 @@ private void validateMedicalInventory(MedicalInventory medInventory) throws OHDa /** * Validate the Inventory rows of inventory. * - * @param inventory - The {@link MedicalInventory} + * @param inventory - The {@link MedicalInventory} * @param inventoryRowSearchList- The list of {@link MedicalInventory} * @throws OHServiceException */ - public void validateMedicalInventoryRow(MedicalInventory inventory, - List inventoryRowSearchList) - throws OHServiceException { + public void validateMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) + throws OHServiceException { LocalDateTime movFrom = inventory.getInventoryDate(); LocalDateTime movTo = TimeTools.getNow(); StringBuilder medDescriptionForLotUpdated = new StringBuilder("\n"); // initial new line @@ -277,17 +270,16 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, boolean allMedicals = true; List movs = new ArrayList<>(); List inventoryMedicalsList = inventoryRowSearchList.stream() - .map(MedicalInventoryRow::getMedical) - .distinct() - .collect(Collectors.toList()); + .map(MedicalInventoryRow::getMedical) + .distinct() + .collect(Collectors.toList()); if (allMedicals) { // Fetch all movements without filtering by medical code movs.addAll(movBrowserManager.getMovements(null, null, null, null, movFrom, movTo, null, null, null, null)); } else { // Fetch only movements concerning inventoryRowSearchList list for (Medical medical : inventoryMedicalsList) { - movs.addAll(movBrowserManager.getMovements(medical.getCode(), null, null, null, movFrom, movTo, null, - null, null, null)); + movs.addAll(movBrowserManager.getMovements(medical.getCode(), null, null, null, movFrom, movTo, null, null, null, null)); } } // Get all the lot of the movements @@ -305,21 +297,17 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, String medicalDesc = medical.getDescription(); Integer medicalCode = medical.getCode(); double mainStoreQty = 0.0; - // Fetch also empty lots because some movements may have discharged them - // completely - Optional optLot = movStockInsertingManager.getLotByMedical(medical, false).stream() - .filter(l -> l.getCode().equals(lotCodeOfMovement)) - .findFirst(); + // Fetch also empty lots because some movements may have discharged them completely + Optional optLot = movStockInsertingManager.getLotByMedical(medical, false).stream().filter(l -> l.getCode().equals(lotCodeOfMovement)) + .findFirst(); if (optLot.isPresent()) { mainStoreQty = optLot.get().getMainStoreQuantity(); } - // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should - // be enough) + // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should be enough) Optional matchingRow = inventoryRowSearchList.stream() - .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) - && row.getMedical().getCode().equals(medicalCode)) - .findFirst(); + .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) && row.getMedical().getCode().equals(medicalCode)) + .findFirst(); if (matchingRow.isPresent()) { MedicalInventoryRow medicalInventoryRow = matchingRow.get(); @@ -327,10 +315,10 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, if (mainStoreQty != theoQty) { lotUpdated = true; medDescriptionForLotUpdated - .append("\n") - .append(MessageBundle.formatMessage( - "angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.detail.fmt.msg", - medicalDesc, lotInfo, theoQty, mainStoreQty, mainStoreQty - theoQty)); + .append("\n") + .append(MessageBundle.formatMessage( + "angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.detail.fmt.msg", + medicalDesc, lotInfo, theoQty, mainStoreQty, mainStoreQty - theoQty)); } } else { @@ -339,39 +327,36 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, // New medical medicalAdded = true; medDescriptionForNewMedical - .append("\n") - .append(MessageBundle.formatMessage( - "angal.inventory.newmedicalshavebeenfound.detail.fmt.msg", - medicalDesc, lotInfo, mainStoreQty)); + .append("\n") + .append(MessageBundle.formatMessage( + "angal.inventory.newmedicalshavebeenfound.detail.fmt.msg", + medicalDesc, lotInfo, mainStoreQty)); } else { // New Lot lotAdded = true; medDescriptionForNewLot - .append("\n") - .append(MessageBundle.formatMessage( - "angal.inventory.newlotshavebeenaddedforsomemedical.detail.fmt.msg", - medicalDesc, lotInfo, mainStoreQty)); + .append("\n") + .append(MessageBundle.formatMessage( + "angal.inventory.newlotshavebeenaddedforsomemedical.detail.fmt.msg", + medicalDesc, lotInfo, mainStoreQty)); } } } List errors = new ArrayList<>(); if (lotUpdated) { errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), - MessageBundle.formatMessage("angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.fmt.msg", - medDescriptionForLotUpdated), - OHSeverityLevel.INFO)); + MessageBundle.formatMessage("angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.fmt.msg", medDescriptionForLotUpdated), + OHSeverityLevel.INFO)); } if (lotAdded) { errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), - MessageBundle.formatMessage("angal.inventory.newlotshavebeenaddedforsomemedical.fmt.msg", - medDescriptionForNewLot), - OHSeverityLevel.INFO)); + MessageBundle.formatMessage("angal.inventory.newlotshavebeenaddedforsomemedical.fmt.msg", medDescriptionForNewLot), + OHSeverityLevel.INFO)); } if (medicalAdded) { errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), - MessageBundle.formatMessage("angal.inventory.newmedicalshavebeenfound.fmt.msg", - medDescriptionForNewMedical), - OHSeverityLevel.INFO)); + MessageBundle.formatMessage("angal.inventory.newmedicalshavebeenfound.fmt.msg", medDescriptionForNewMedical), + OHSeverityLevel.INFO)); } if (!errors.isEmpty()) { throw new OHDataValidationException(errors); @@ -381,12 +366,11 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, /** * Validate the Inventory rows of inventory ward. * - * @param inventory - The {@link MedicalInventory} + * @param inventory - The {@link MedicalInventory} * @param inventoryRowSearchList - The list of {@link MedicalInventory} * @throws OHServiceException */ - public void validateMedicalWardInventoryRow(MedicalInventory inventory, - List inventoryRowSearchList) throws OHServiceException { + public void validateMedicalWardInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { LocalDateTime movFrom = inventory.getLastModifiedDate(); LocalDateTime movTo = TimeTools.getNow(); StringBuilder medDescriptionForLotUpdated = new StringBuilder("\n"); // initial new line @@ -396,14 +380,9 @@ public void validateMedicalWardInventoryRow(MedicalInventory inventory, boolean lotAdded = false; boolean medicalAdded = false; - List movementWards = new ArrayList<>( - movWardBrowserManager.getMovementWard(inventory.getWard(), movFrom, movTo)); - List movementToWards = new ArrayList<>( - movBrowserManager.getMovements(inventory.getWard(), movFrom, movTo)); - List inventoryMedicalsList = inventoryRowSearchList.stream() - .map(MedicalInventoryRow::getMedical) - .distinct() - .toList(); + List movementWards = new ArrayList<>(movWardBrowserManager.getMovementWard(inventory.getWard(), movFrom, movTo)); + List movementToWards = new ArrayList<>(movBrowserManager.getMovements(inventory.getWard(), movFrom, movTo)); + List inventoryMedicalsList = inventoryRowSearchList.stream().map(MedicalInventoryRow::getMedical).distinct().toList(); // Get all the lot of the ward movements List lotOfMovements = new ArrayList<>(movementWards.stream().map(MovementWard::getLot).toList()); @@ -423,20 +402,16 @@ public void validateMedicalWardInventoryRow(MedicalInventory inventory, Integer medicalCode = medical.getCode(); double wardStoreQty = 0.0; - Optional optMedicalWard = movWardBrowserManager - .getMedicalsWard(inventory.getWard(), medical.getCode(), false).stream() + Optional optMedicalWard = movWardBrowserManager.getMedicalsWard(inventory.getWard(), medical.getCode(), false).stream() .filter(m -> m.getLot().getCode().equals(lotCodeOfMovement)).findFirst(); if (optMedicalWard.isPresent()) { wardStoreQty = optMedicalWard.get().getQty(); } - // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should - // be enough) + // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should be enough) Optional matchingRow = inventoryRowSearchList.stream() - .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) - && row.getMedical().getCode().equals(medicalCode)) - .findFirst(); + .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) && row.getMedical().getCode().equals(medicalCode)).findFirst(); if (matchingRow.isPresent()) { MedicalInventoryRow medicalInventoryRow = matchingRow.get(); @@ -444,10 +419,9 @@ public void validateMedicalWardInventoryRow(MedicalInventory inventory, if (wardStoreQty != theoQty) { lotUpdated = true; medDescriptionForLotUpdated - .append("\n") - .append(MessageBundle.formatMessage( - "angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.detail.fmt.msg", - medicalDesc, lotInfo, theoQty, wardStoreQty, wardStoreQty - theoQty)); + .append("\n") + .append(MessageBundle.formatMessage("angal.inventory.theoreticalqtyhavebeenupdatedforsomemedical.detail.fmt.msg", + medicalDesc, lotInfo, theoQty, wardStoreQty, wardStoreQty - theoQty)); } } else { // TODO: to decide if to give control to the user about this @@ -455,40 +429,33 @@ public void validateMedicalWardInventoryRow(MedicalInventory inventory, // New medical medicalAdded = true; medDescriptionForNewMedical - .append("\n") - .append(MessageBundle.formatMessage( - "angal.inventory.newmedicalshavebeenfound.detail.fmt.msg", - medicalDesc, lotInfo, wardStoreQty)); + .append("\n") + .append(MessageBundle.formatMessage("angal.inventory.newmedicalshavebeenfound.detail.fmt.msg", + medicalDesc, lotInfo, wardStoreQty)); } else { // New Lot lotAdded = true; medDescriptionForNewLot - .append("\n") - .append(MessageBundle.formatMessage( - "angal.inventory.newlotshavebeenaddedforsomemedical.detail.fmt.msg", - medicalDesc, lotInfo, wardStoreQty)); + .append("\n") + .append(MessageBundle.formatMessage("angal.inventory.newlotshavebeenaddedforsomemedical.detail.fmt.msg", + medicalDesc, lotInfo, wardStoreQty)); } } } List errors = new ArrayList<>(); if (lotUpdated) { errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), - MessageBundle.formatMessage( - "angal.inventory.theoreticalqtyhavebeenupdatedforsomemedicalward.fmt.msg", - medDescriptionForLotUpdated), - OHSeverityLevel.INFO)); + MessageBundle.formatMessage("angal.inventory.theoreticalqtyhavebeenupdatedforsomemedicalward.fmt.msg", medDescriptionForLotUpdated), + OHSeverityLevel.INFO)); } if (lotAdded) { errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), - MessageBundle.formatMessage("angal.inventory.newlotshavebeenaddedforsomemedicalward.fmt.msg", - medDescriptionForNewLot), - OHSeverityLevel.INFO)); + MessageBundle.formatMessage("angal.inventory.newlotshavebeenaddedforsomemedicalward.fmt.msg", medDescriptionForNewLot), + OHSeverityLevel.INFO)); } if (medicalAdded) { errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.validate.btn"), - MessageBundle.formatMessage("angal.inventory.newmedicalshavebeenfoundward.fmt.msg", - medDescriptionForNewMedical), - OHSeverityLevel.INFO)); + MessageBundle.formatMessage("angal.inventory.newmedicalshavebeenfoundward.fmt.msg", medDescriptionForNewMedical), OHSeverityLevel.INFO)); } if (!errors.isEmpty()) { throw new OHDataValidationException(errors); @@ -503,8 +470,7 @@ public void validateMedicalWardInventoryRow(MedicalInventory inventory, */ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceException { int invenotyId = medicalInventory.getId(); - List inventoryRows = medicalInventoryRowManager - .getMedicalInventoryRowByInventoryId(invenotyId); + List inventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(invenotyId); for (MedicalInventoryRow invRow : inventoryRows) { boolean isNewLot = invRow.isNewLot(); Lot lot = invRow.getLot(); @@ -520,26 +486,23 @@ public void deleteInventory(MedicalInventory medicalInventory) throws OHServiceE /** * Confirm the Inventory rows of inventory. * - * @param inventory - The {@link MedicalInventory} + * @param inventory - The {@link MedicalInventory} * @param inventoryRowSearchList- The list of {@link MedicalInventory} * @return List {@link Movement}. It could be {@code empty}. * @throws OHServiceException */ @Transactional(rollbackFor = OHServiceException.class) - public List confirmMedicalInventoryRow(MedicalInventory inventory, - List inventoryRowSearchList) throws OHServiceException { + public List confirmMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { // validate the inventory this.validateMedicalInventoryRow(inventory, inventoryRowSearchList); // get general info String referenceNumber = inventory.getInventoryReference(); - // TODO: to explore the possibility to allow charges and discharges with same - // referenceNumber + // TODO: to explore the 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()); + MovementType dischargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(inventory.getDischargeType()); Supplier supplier = supplierManager.getByID(inventory.getSupplier()); Ward ward = wardManager.findWard(inventory.getDestination()); LocalDateTime now = TimeTools.getNow(); @@ -553,24 +516,20 @@ public List confirmMedicalInventoryRow(MedicalInventory inventory, 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); + 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); + 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)); + insertedMovements.addAll(movStockInsertingManager.newMultipleChargingMovements(chargeMovements, chargeReferenceNumber)); } if (!dischargeMovements.isEmpty()) { - insertedMovements.addAll(movStockInsertingManager.newMultipleDischargingMovements(dischargeMovements, - dischargeReferenceNumber)); + insertedMovements.addAll(movStockInsertingManager.newMultipleDischargingMovements(dischargeMovements, dischargeReferenceNumber)); } String status = InventoryStatus.done.toString(); inventory.setStatus(status); @@ -586,8 +545,7 @@ private void checkReference(MedicalInventory medicalInventory) throws OHServiceE boolean existWithSuffixCharge = movStockInsertingManager.refNoExists(chargeReferenceNumber); boolean existWithSuffixDischarge = movStockInsertingManager.refNoExists(dischargeReferenceNumber); MedicalInventory inventory = this.getInventoryByReference(reference); - if (existWithSuffixCharge || existWithSuffixDischarge - || inventory != null && inventory.getId() != medicalInventory.getId()) { + if (existWithSuffixCharge || existWithSuffixDischarge || inventory != null && inventory.getId() != medicalInventory.getId()) { errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.inventory.referencealreadyused.msg"))); } if (!errors.isEmpty()) { @@ -612,17 +570,16 @@ public MedicalInventory actualizeMedicalInventoryRow(MedicalInventory inventory) boolean allMedicals = true; List movs = new ArrayList<>(); List inventoryMedicalsList = inventoryRowList.stream() - .map(MedicalInventoryRow::getMedical) - .distinct() - .collect(Collectors.toList()); + .map(MedicalInventoryRow::getMedical) + .distinct() + .collect(Collectors.toList()); if (allMedicals) { // Fetch all movements without filtering by medical code movs.addAll(movBrowserManager.getMovements(null, null, null, null, movFrom, movTo, null, null, null, null)); } else { // Fetch only movements concerning inventoryRowSearchList list for (Medical medical : inventoryMedicalsList) { - movs.addAll(movBrowserManager.getMovements(medical.getCode(), null, null, null, movFrom, movTo, null, - null, null, null)); + movs.addAll(movBrowserManager.getMovements(medical.getCode(), null, null, null, movFrom, movTo, null, null, null, null)); } } // Get all the lot of the movements @@ -636,19 +593,15 @@ public MedicalInventory actualizeMedicalInventoryRow(MedicalInventory inventory) String lotCodeOfMovement = lot.getCode(); Medical medical = lot.getMedical(); Integer medicalCode = medical.getCode(); - // Fetch also empty lots because some movements may have discharged them - // completely - Optional optLot = movStockInsertingManager.getLotByMedical(medical, false).stream() - .filter(l -> l.getCode().equals(lotCodeOfMovement)) - .findFirst(); + // Fetch also empty lots because some movements may have discharged them completely + Optional optLot = movStockInsertingManager.getLotByMedical(medical, false).stream().filter(l -> l.getCode().equals(lotCodeOfMovement)) + .findFirst(); double mainStoreQty = optLot.get().getMainStoreQuantity(); - // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should - // be enough) + // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should be enough) Optional matchingRow = inventoryRowList.stream() - .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) - && row.getMedical().getCode().equals(medicalCode)) - .findFirst(); + .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) && row.getMedical().getCode().equals(medicalCode)) + .findFirst(); if (matchingRow.isPresent()) { MedicalInventoryRow medicalInventoryRow = matchingRow.get(); @@ -661,9 +614,8 @@ public MedicalInventory actualizeMedicalInventoryRow(MedicalInventory inventory) } else { // TODO: to decide if to give control to the user about this double realQty = mainStoreQty; - MedicalInventoryRow newMedicalInventoryRow = new MedicalInventoryRow(null, mainStoreQty, realQty, - inventory, medical, - lot); + MedicalInventoryRow newMedicalInventoryRow = new MedicalInventoryRow(null, mainStoreQty, realQty, inventory, medical, + lot); medicalInventoryRowManager.newMedicalInventoryRow(newMedicalInventoryRow); } } From eaa06f4d0bc548705bdd98db1bdd67960b21eb90 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 20 Nov 2024 18:11:14 +0100 Subject: [PATCH 04/18] Remove uneccessary format code --- .../medicalinventory/manager/MedicalInventoryManager.java | 6 ++---- 1 file changed, 2 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 cb27ae5bd..801c5ae36 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -77,11 +77,9 @@ public class MedicalInventoryManager { private MovWardBrowserManager movWardBrowserManager; - public MedicalInventoryManager(MedicalInventoryIoOperation medicalInventoryIoOperation, - MedicalInventoryRowManager medicalInventoryRowManager, + public MedicalInventoryManager(MedicalInventoryIoOperation medicalInventoryIoOperation, MedicalInventoryRowManager medicalInventoryRowManager, MedicalDsrStockMovementTypeBrowserManager medicalDsrStockMovementTypeBrowserManager, - SupplierBrowserManager supplierManager, MovStockInsertingManager movStockInsertingManager, - WardBrowserManager wardManager, + SupplierBrowserManager supplierManager, MovStockInsertingManager movStockInsertingManager, WardBrowserManager wardManager, MovBrowserManager movBrowserManager, MovWardBrowserManager movWardBrowserManager) { this.ioOperations = medicalInventoryIoOperation; this.medicalInventoryRowManager = medicalInventoryRowManager; From 2fe89dd2a5ae5ebfc5061534b59e9e48d984a069 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Fri, 22 Nov 2024 14:53:44 +0100 Subject: [PATCH 05/18] Write united test for validateWardinventory --- .../TestMedicalWardInventory.java | 63 +++++++++++ .../java/org/isf/medicalsinventory/Tests.java | 100 ++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java diff --git a/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java b/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java new file mode 100644 index 000000000..0b2aed858 --- /dev/null +++ b/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java @@ -0,0 +1,63 @@ +package org.isf.medicalsinventory; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; + +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 TestMedicalWardInventory { + private int id = 1; + private String status = InventoryStatus.draft.toString(); + private LocalDateTime inventoryDate = TimeTools.getNow(); + private String user = "admin"; + private String inventoryReference = "REFERENCE"; + private String inventoryType = InventoryType.ward.toString(); + private String ward = "Z"; + private String destination = "Z"; + private String reason = "reason"; + + public MedicalInventory setup(Ward ward, boolean usingSet) throws OHException { + MedicalInventory medicalInventory; + + if (usingSet) { + medicalInventory = new MedicalInventory(); + setParameters(medicalInventory); + } else { + // create MedicalInventory with all parameters + medicalInventory = new MedicalInventory(id, status, inventoryDate, user, inventoryReference, inventoryType, ward.getCode(), destination, reason); + } + return medicalInventory; + } + + public void setParameters(MedicalInventory medicalInventory) { + medicalInventory.setId(id); + medicalInventory.setStatus(status); + medicalInventory.setInventoryDate(inventoryDate); + medicalInventory.setUser(user); + medicalInventory.setInventoryReference(inventoryReference); + medicalInventory.setInventoryType(inventoryType); + medicalInventory.setWard(ward); + medicalInventory.setDestination(destination); + medicalInventory.setReason(reason); + } + + public void check(MedicalInventory medicalInventory, int id) { + assertThat(medicalInventory.getId()).isEqualTo(id); + assertThat(medicalInventory.getStatus()).isEqualTo(status); + assertThat(medicalInventory.getInventoryDate()).isCloseTo(inventoryDate, within(1, ChronoUnit.SECONDS)); + assertThat(medicalInventory.getUser()).isEqualTo(user); + assertThat(medicalInventory.getInventoryReference()).isEqualTo(inventoryReference); + assertThat(medicalInventory.getInventoryType()).isEqualTo(inventoryType); + assertThat(medicalInventory.getWard()).isEqualTo(ward); + assertThat(medicalInventory.getDestination()).isEqualTo(destination); + assertThat(medicalInventory.getReason()).isEqualTo(reason); + } +} diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 3cd3728a2..6506cad5c 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -51,11 +51,16 @@ import org.isf.medicalstock.service.LotIoOperationRepository; import org.isf.medicalstock.service.MedicalStockIoOperationRepository; import org.isf.medicalstock.service.MedicalStockIoOperations; +import org.isf.medicalstockward.TestMovementWard; +import org.isf.medicalstockward.model.MovementWard; +import org.isf.medicalstockward.service.MedicalStockWardIoOperations; +import org.isf.medicalstockward.service.MovementWardIoOperationRepository; 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.TestSupplier; import org.isf.supplier.model.Supplier; import org.isf.supplier.service.SupplierIoOperationRepository; import org.isf.utils.exception.OHException; @@ -83,6 +88,9 @@ class Tests extends OHCoreTestCase { private static TestMedicalType testMedicalType; private static TestMovement testMovement; private static TestMedicalStock testMedicalStock; + private static TestMedicalWardInventory testMedicalWardInventory; + private static TestMovementWard testMovementWard; + private static TestSupplier testSupplier; @Autowired MedicalInventoryManager medicalInventoryManager; @@ -129,6 +137,12 @@ class Tests extends OHCoreTestCase { @Autowired MedicalStockIoOperations medicalStockIoOperation; + @Autowired + MedicalStockWardIoOperations medicalStockWardIoOperation; + + @Autowired + MovementWardIoOperationRepository movementWardIoOperationRepository; + static Stream automaticlot() { return Stream.of(Arguments.of(true, true, false), Arguments.of(true, true, true), @@ -152,6 +166,9 @@ static void setUpClass() { testMedicalType = new TestMedicalType(); testMovement = new TestMovement(); testMedicalStock = new TestMedicalStock(); + testMedicalWardInventory = new TestMedicalWardInventory(); + testMovementWard = new TestMovementWard(); + testSupplier = new TestSupplier(); } @BeforeEach @@ -811,4 +828,87 @@ void testValidateMedicalInventory() throws Exception { assertThat(medicalInventoryRows).hasSize(3); medicalInventoryManager.validateMedicalInventoryRow(inventory, medicalInventoryRows); } + + @Test + void testValidateMedicalWardInventoryRow() throws Exception { + Ward ward = testWard.setup(false); + wardIoOperationRepository.saveAndFlush(ward); + MedicalInventory inventory = testMedicalWardInventory.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 inventoryRowId = medicalInventoryRow.getId(); + MedicalInventoryRow newMedicalInventoryRow = medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); + assertThat(newMedicalInventoryRow).isNotNull(); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId); + assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows).hasSize(1); + medicalInventoryManager.validateMedicalWardInventoryRow(savedInventory, medicalInventoryRows); + int inventoryId = inventory.getId(); + inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); + assertThat(inventory).isNotNull(); + } + + @Test + void testValidateMedicalWardInventory() 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"); + Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); + chargeType = medicalDsrStockMovementTypeIoOperationRepository.save(chargeType); + dischargeType = medicalDsrStockMovementTypeIoOperationRepository.save(dischargeType); + destination = wardIoOperationRepository.save(destination); + MedicalInventory inventory = testMedicalWardInventory.setup(ward, false); + inventory.setDestination(destination.getCode()); + inventory = medicalInventoryIoOperation.newMedicalInventory(inventory); + MedicalType medicalType = testMedicalType.setup(false); + Medical medical = testMedical.setup(medicalType, false); + Lot lotOne = testLot.setup(medical, false); + Supplier supplier = testSupplier.setup(false); + supplier = supplierIoOperationRepository.saveAndFlush(supplier); + Movement initialMovement = testMovement.setup(medical, chargeType, ward, lotOne, supplier, false); + initialMovement.setQuantity(200); + MedicalStock initialMedicalStock = testMedicalStock.setup(initialMovement); + Movement firstMovement = testMovement.setup(medical, dischargeType, ward, lotOne, null, false); + firstMovement.setQuantity(100); + MedicalStock firstmedicalStock = testMedicalStock.setup(firstMovement); + Lot lotTwo = testLot.setup(medical, false); + lotTwo.setCode("LOT-001"); + MovementWard wardMovement = testMovementWard.setup(ward, null, medical, ward, destination, lotTwo, false); + wardMovement.setQuantity(100.0); + Lot lotThree = testLot.setup(medical, false); + lotTwo.setCode("LOT-003"); + medicalTypeIoOperationRepository.saveAndFlush(medicalType); + medical = medicalsIoOperationRepository.save(medical); + lotOne = lotIoOperationRepository.save(lotOne); + lotTwo = lotIoOperationRepository.save(lotTwo); + lotThree = lotIoOperationRepository.save(lotThree); + medicalStockIoOperation.newMovement(initialMovement); + medicalStockIoOperationRepository.saveAndFlush(initialMedicalStock); + 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); + medicalStockIoOperation.newMovement(firstMovement); + medicalStockWardIoOperation.newMovementWard(wardMovement); + medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); + movementWardIoOperationRepository.saveAndFlush(wardMovement); + int inventoryId = inventory.getId(); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); + assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows).hasSize(3); + medicalInventoryManager.validateMedicalWardInventoryRow(inventory, medicalInventoryRows); + } } From efb091ee162261771b797159038f91c30df7de74 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 25 Nov 2024 08:10:29 +0100 Subject: [PATCH 06/18] Add the standard license header block --- .../TestMedicalWardInventory.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java b/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java index 0b2aed858..47ab4f25f 100644 --- a/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java +++ b/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java @@ -1,3 +1,24 @@ +/* + * Open Hospital (www.open-hospital.org) + * Copyright © 2006-2024 Informatici Senza Frontiere (info@informaticisenzafrontiere.org) + * + * Open Hospital is a free and open source software for healthcare data management. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * https://www.gnu.org/licenses/gpl-3.0-standalone.html + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ package org.isf.medicalsinventory; import static org.assertj.core.api.Assertions.assertThat; From 6b9925f478d0d7823a1a7ab4eeb699c5eda90899 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 27 Nov 2024 15:59:18 +0100 Subject: [PATCH 07/18] Remove reason attribut --- ...escription_column_in_medical_inventory.sql | 1 - .../model/MedicalInventory.java | 24 ------------------- .../TestMedicalWardInventory.java | 8 +------ .../java/org/isf/medicalsinventory/Tests.java | 1 - 4 files changed, 1 insertion(+), 33 deletions(-) delete mode 100644 sql/step_axxx_add_description_column_in_medical_inventory.sql diff --git a/sql/step_axxx_add_description_column_in_medical_inventory.sql b/sql/step_axxx_add_description_column_in_medical_inventory.sql deleted file mode 100644 index dfae56669..000000000 --- a/sql/step_axxx_add_description_column_in_medical_inventory.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE OH_MEDICALDSRINVENTORY ADD COLUMN MINVT_DESC VARCHAR(100) NULL; \ No newline at end of file diff --git a/src/main/java/org/isf/medicalinventory/model/MedicalInventory.java b/src/main/java/org/isf/medicalinventory/model/MedicalInventory.java index 78fb309e3..add0231f5 100644 --- a/src/main/java/org/isf/medicalinventory/model/MedicalInventory.java +++ b/src/main/java/org/isf/medicalinventory/model/MedicalInventory.java @@ -86,9 +86,6 @@ public class MedicalInventory extends Auditable { @Column(name = "MINVT_DESTINATION") private String destination; - - @Column(name = "MINVT_DESC") - private String reason; @Version @Column(name="MINVT_LOCK") @@ -123,19 +120,6 @@ public MedicalInventory(Integer id, String status, LocalDateTime inventoryDate, this.destination = destination; } - public MedicalInventory(Integer id, String status, LocalDateTime inventoryDate, String user, String inventoryReference, String inventoryType, String ward, - String destination, String reason) { - this.id = id; - this.status = status; - this.inventoryDate = inventoryDate; - this.user = user; - this.inventoryReference = inventoryReference; - this.inventoryType = inventoryType; - this.ward = ward; - this.destination = destination; - this.reason = reason; - } - public Integer getId() { return id; } @@ -239,12 +223,4 @@ public String getDestination() { public void setDestination(String destination) { this.destination = destination; } - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } } diff --git a/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java b/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java index 47ab4f25f..484fca01f 100644 --- a/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java +++ b/src/test/java/org/isf/medicalsinventory/TestMedicalWardInventory.java @@ -42,8 +42,6 @@ public class TestMedicalWardInventory { private String inventoryReference = "REFERENCE"; private String inventoryType = InventoryType.ward.toString(); private String ward = "Z"; - private String destination = "Z"; - private String reason = "reason"; public MedicalInventory setup(Ward ward, boolean usingSet) throws OHException { MedicalInventory medicalInventory; @@ -53,7 +51,7 @@ public MedicalInventory setup(Ward ward, boolean usingSet) throws OHException { setParameters(medicalInventory); } else { // create MedicalInventory with all parameters - medicalInventory = new MedicalInventory(id, status, inventoryDate, user, inventoryReference, inventoryType, ward.getCode(), destination, reason); + medicalInventory = new MedicalInventory(id, status, inventoryDate, user, inventoryReference, inventoryType, ward.getCode()); } return medicalInventory; } @@ -66,8 +64,6 @@ public void setParameters(MedicalInventory medicalInventory) { medicalInventory.setInventoryReference(inventoryReference); medicalInventory.setInventoryType(inventoryType); medicalInventory.setWard(ward); - medicalInventory.setDestination(destination); - medicalInventory.setReason(reason); } public void check(MedicalInventory medicalInventory, int id) { @@ -78,7 +74,5 @@ public void check(MedicalInventory medicalInventory, int id) { assertThat(medicalInventory.getInventoryReference()).isEqualTo(inventoryReference); assertThat(medicalInventory.getInventoryType()).isEqualTo(inventoryType); assertThat(medicalInventory.getWard()).isEqualTo(ward); - assertThat(medicalInventory.getDestination()).isEqualTo(destination); - assertThat(medicalInventory.getReason()).isEqualTo(reason); } } diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 6506cad5c..14516010a 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -865,7 +865,6 @@ void testValidateMedicalWardInventory() throws Exception { dischargeType = medicalDsrStockMovementTypeIoOperationRepository.save(dischargeType); destination = wardIoOperationRepository.save(destination); MedicalInventory inventory = testMedicalWardInventory.setup(ward, false); - inventory.setDestination(destination.getCode()); inventory = medicalInventoryIoOperation.newMedicalInventory(inventory); MedicalType medicalType = testMedicalType.setup(false); Medical medical = testMedical.setup(medicalType, false); From 6d2e1e9bfc0062f63e8e72bade5265a020be9e32 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Thu, 28 Nov 2024 17:25:27 +0100 Subject: [PATCH 08/18] Add actualize inventory row function --- .../manager/MedicalInventoryManager.java | 58 ++++++++++++++++++- 1 file changed, 57 insertions(+), 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 2cfbfcbbf..0fd29d959 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -369,7 +369,7 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { - LocalDateTime movFrom = inventory.getLastModifiedDate(); + LocalDateTime movFrom = inventory.getInventoryDate(); LocalDateTime movTo = TimeTools.getNow(); StringBuilder medDescriptionForLotUpdated = new StringBuilder("\n"); // initial new line StringBuilder medDescriptionForNewLot = new StringBuilder("\n"); // initial new line @@ -619,4 +619,60 @@ public MedicalInventory actualizeMedicalInventoryRow(MedicalInventory inventory) } return this.updateMedicalInventory(inventory, true); } + + /** + * Actualize the {@link MedicalInventory}'s ward. + * + * @param inventory - The {@link MedicalInventory} + * @return {@link MedicalInventory}. It could be {@code null}. + * @throws OHServiceException + */ + public MedicalInventory actualizeMedicalWardInventoryRow(MedicalInventory inventory) throws OHServiceException { + LocalDateTime movFrom = inventory.getInventoryDate(); + LocalDateTime movTo = TimeTools.getNow(); + + List movementWards = new ArrayList<>(movWardBrowserManager.getMovementWard(inventory.getWard(), movFrom, movTo)); + List movementToWards = new ArrayList<>(movBrowserManager.getMovements(inventory.getWard(), movFrom, movTo)); + List inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); + + // Get all the lot of the ward movements + List lotOfMovements = new ArrayList<>(movementWards.stream().map(MovementWard::getLot).toList()); + // Get all the lot of the movements + lotOfMovements.addAll(movementToWards.stream().map(Movement::getLot).toList()); + // Remove duplicates by converting the list to a set + Set uniqueLots = new HashSet<>(lotOfMovements); + // Convert the set back to a list + List uniqueLotList = new ArrayList<>(uniqueLots); + // Cycle fetched movements to see if they impact inventoryRowSearchList + for (Lot lot : uniqueLotList) { + String lotCodeOfMovement = lot.getCode(); + Medical medical = lot.getMedical(); + Integer medicalCode = medical.getCode(); + // Fetch also empty lots because some movements may have discharged them completely + Optional optMedicalWard = movWardBrowserManager.getMedicalsWard(inventory.getWard(), medical.getCode(), false).stream() + .filter(m -> m.getLot().getCode().equals(lotCodeOfMovement)).findFirst(); + double wardStoreQty = optMedicalWard.isPresent() ? optMedicalWard.get().getQty() : 0.0; + + // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should be enough) + Optional matchingRow = inventoryRowList.stream() + .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) && row.getMedical().getCode().equals(medicalCode)) + .findFirst(); + + if (matchingRow.isPresent()) { + MedicalInventoryRow medicalInventoryRow = matchingRow.get(); + double theoQty = medicalInventoryRow.getTheoreticQty(); + if (wardStoreQty != theoQty) { + // Update Lot + medicalInventoryRow.setTheoreticQty(wardStoreQty); + medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow); + } + } else { + // TODO: to decide if to give control to the user about this + double realQty = wardStoreQty; + MedicalInventoryRow newMedicalInventoryRow = new MedicalInventoryRow(null, wardStoreQty, realQty, inventory, medical, lot); + medicalInventoryRowManager.newMedicalInventoryRow(newMedicalInventoryRow); + } + } + return this.updateMedicalInventory(inventory, true); + } } From 10c2d3de132f2c0592f59f410b80f96d54268b48 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 3 Dec 2024 08:56:38 +0100 Subject: [PATCH 09/18] update validateMedicalWardInventoryRow function --- .../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 0fd29d959..a96cea4b6 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -369,7 +369,7 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { - LocalDateTime movFrom = inventory.getInventoryDate(); + LocalDateTime movFrom = inventory.getLastModifiedDate(); LocalDateTime movTo = TimeTools.getNow(); StringBuilder medDescriptionForLotUpdated = new StringBuilder("\n"); // initial new line StringBuilder medDescriptionForNewLot = new StringBuilder("\n"); // initial new line From 5892e905ed19780aed84038414b7a8c7652080d6 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 3 Dec 2024 09:13:02 +0100 Subject: [PATCH 10/18] update validateMedicalWardInventoryRow function --- .../medicalinventory/manager/MedicalInventoryManager.java | 6 +++--- 1 file changed, 3 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 82c557c43..6bd811849 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -369,8 +369,8 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { @@ -671,7 +671,7 @@ public String getStatusByKey(String key) { /** * Actualize the {@link MedicalInventory}'s ward. * - * @param inventory - The {@link MedicalInventory} + * @param inventory the {@link MedicalInventory} * @return {@link MedicalInventory}. It could be {@code null}. * @throws OHServiceException */ From f01faa707a09cbfdbf10b3835ecc6d053f23b347 Mon Sep 17 00:00:00 2001 From: NKONGA Andy <59751611+JantBogard@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:05:02 +0100 Subject: [PATCH 11/18] 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 6bd811849..7ea45a73a 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -387,7 +387,7 @@ public void validateMedicalWardInventoryRow(MedicalInventory inventory, List movementToWards = new ArrayList<>(movBrowserManager.getMovements(inventory.getWard(), movFrom, movTo)); List inventoryMedicalsList = inventoryRowSearchList.stream().map(MedicalInventoryRow::getMedical).distinct().toList(); - // Get all the lot of the ward movements + // Get all the lots from ward movements List lotOfMovements = new ArrayList<>(movementWards.stream().map(MovementWard::getLot).toList()); // Get all the lot of the movements lotOfMovements.addAll(movementToWards.stream().map(Movement::getLot).toList()); From 5415bf9fdf8d59858f7624f74e41dc9ac4499394 Mon Sep 17 00:00:00 2001 From: NKONGA Andy <59751611+JantBogard@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:05:22 +0100 Subject: [PATCH 12/18] 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 7ea45a73a..dc05c9696 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -389,7 +389,7 @@ public void validateMedicalWardInventoryRow(MedicalInventory inventory, List lotOfMovements = new ArrayList<>(movementWards.stream().map(MovementWard::getLot).toList()); - // Get all the lot of the movements + // Get all the lots from main store movements lotOfMovements.addAll(movementToWards.stream().map(Movement::getLot).toList()); // Remove duplicates by converting the list to a set Set uniqueLots = new HashSet<>(lotOfMovements); From 1d9750eeaa8108c1bade780bde86e25711de358f Mon Sep 17 00:00:00 2001 From: NKONGA Andy <59751611+JantBogard@users.noreply.github.com> Date: Mon, 9 Dec 2024 09:06:51 +0100 Subject: [PATCH 13/18] Update src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java Co-authored-by: Alessandro Domanico --- .../isf/medicalinventory/manager/MedicalInventoryManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index dc05c9696..327fae295 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -683,9 +683,9 @@ public MedicalInventory actualizeMedicalWardInventoryRow(MedicalInventory invent List movementToWards = new ArrayList<>(movBrowserManager.getMovements(inventory.getWard(), movFrom, movTo)); List inventoryRowList = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); - // Get all the lot of the ward movements + // Get all the lots from the ward movements List lotOfMovements = new ArrayList<>(movementWards.stream().map(MovementWard::getLot).toList()); - // Get all the lot of the movements + // Get all the lots from the main store movements lotOfMovements.addAll(movementToWards.stream().map(Movement::getLot).toList()); // Remove duplicates by converting the list to a set Set uniqueLots = new HashSet<>(lotOfMovements); From 51f2974b45dbd1897bb60e38eb7a6a42f885b933 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Mon, 9 Dec 2024 15:50:48 +0100 Subject: [PATCH 14/18] Applying suggestion for change --- .../manager/MedicalInventoryManager.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 327fae295..0bb28c493 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -374,7 +374,7 @@ public void validateMedicalInventoryRow(MedicalInventory inventory, List inventoryRowSearchList) throws OHServiceException { - LocalDateTime movFrom = inventory.getLastModifiedDate(); + LocalDateTime movFrom = inventory.getInventoryDate(); LocalDateTime movTo = TimeTools.getNow(); StringBuilder medDescriptionForLotUpdated = new StringBuilder("\n"); // initial new line StringBuilder medDescriptionForNewLot = new StringBuilder("\n"); // initial new line @@ -397,24 +397,20 @@ public void validateMedicalWardInventoryRow(MedicalInventory inventory, List uniqueLotList = new ArrayList<>(uniqueLots); // Cycle fetched movements to see if they impact inventoryRowSearchList for (Lot lot : uniqueLotList) { - String lotCodeOfMovement = lot.getCode(); + String lotCode = lot.getCode(); String lotExpiringDate = TimeTools.formatDateTime(lot.getDueDate(), TimeTools.DD_MM_YYYY); - String lotInfo = GeneralData.AUTOMATICLOT_IN ? lotExpiringDate : lotCodeOfMovement; + String lotInfo = GeneralData.AUTOMATICLOT_IN ? lotExpiringDate : lotCode; Medical medical = lot.getMedical(); String medicalDesc = medical.getDescription(); - Integer medicalCode = medical.getCode(); - double wardStoreQty = 0.0; Optional optMedicalWard = movWardBrowserManager.getMedicalsWard(inventory.getWard(), medical.getCode(), false).stream() - .filter(m -> m.getLot().getCode().equals(lotCodeOfMovement)).findFirst(); + .filter(m -> m.getLot().getCode().equals(lotCode)).findFirst(); - if (optMedicalWard.isPresent()) { - wardStoreQty = optMedicalWard.get().getQty(); - } + double wardStoreQty = optMedicalWard.isPresent() ? optMedicalWard.get().getQty() : 0.0; - // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should be enough) + // Search for the specific Lot and Medical in inventoryRowSearchList Optional matchingRow = inventoryRowSearchList.stream() - .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) && row.getMedical().getCode().equals(medicalCode)).findFirst(); + .filter(row -> row.getLot().getCode().equals(lotCode)).findFirst(); if (matchingRow.isPresent()) { MedicalInventoryRow medicalInventoryRow = matchingRow.get(); @@ -693,17 +689,17 @@ public MedicalInventory actualizeMedicalWardInventoryRow(MedicalInventory invent List uniqueLotList = new ArrayList<>(uniqueLots); // Cycle fetched movements to see if they impact inventoryRowSearchList for (Lot lot : uniqueLotList) { - String lotCodeOfMovement = lot.getCode(); + String lotCode = lot.getCode(); Medical medical = lot.getMedical(); Integer medicalCode = medical.getCode(); // Fetch also empty lots because some movements may have discharged them completely Optional optMedicalWard = movWardBrowserManager.getMedicalsWard(inventory.getWard(), medical.getCode(), false).stream() - .filter(m -> m.getLot().getCode().equals(lotCodeOfMovement)).findFirst(); + .filter(m -> m.getLot().getCode().equals(lotCode)).findFirst(); double wardStoreQty = optMedicalWard.isPresent() ? optMedicalWard.get().getQty() : 0.0; // Search for the specific Lot and Medical in inventoryRowSearchList (Lot should be enough) Optional matchingRow = inventoryRowList.stream() - .filter(row -> row.getLot().getCode().equals(lotCodeOfMovement) && row.getMedical().getCode().equals(medicalCode)) + .filter(row -> row.getLot().getCode().equals(lotCode) && row.getMedical().getCode().equals(medicalCode)) .findFirst(); if (matchingRow.isPresent()) { From 07881cd7291e87b76cef7d459e5e3ce6ed3d30ed Mon Sep 17 00:00:00 2001 From: JantBogard Date: Tue, 10 Dec 2024 10:27:12 +0100 Subject: [PATCH 15/18] Fix test coverage --- .../java/org/isf/medicalsinventory/Tests.java | 166 ++++++++++-------- 1 file changed, 88 insertions(+), 78 deletions(-) diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 14516010a..b5a273903 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -22,6 +22,7 @@ package org.isf.medicalsinventory; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import java.time.LocalDateTime; import java.util.List; @@ -63,6 +64,7 @@ import org.isf.supplier.TestSupplier; import org.isf.supplier.model.Supplier; import org.isf.supplier.service.SupplierIoOperationRepository; +import org.isf.utils.exception.OHDataValidationException; import org.isf.utils.exception.OHException; import org.isf.utils.exception.OHServiceException; import org.isf.utils.time.TimeTools; @@ -831,83 +833,91 @@ void testValidateMedicalInventory() throws Exception { @Test void testValidateMedicalWardInventoryRow() throws Exception { - Ward ward = testWard.setup(false); - wardIoOperationRepository.saveAndFlush(ward); - MedicalInventory inventory = testMedicalWardInventory.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 inventoryRowId = medicalInventoryRow.getId(); - MedicalInventoryRow newMedicalInventoryRow = medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow); - assertThat(newMedicalInventoryRow).isNotNull(); - List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId); - assertThat(medicalInventoryRows).isNotEmpty(); - assertThat(medicalInventoryRows).hasSize(1); - medicalInventoryManager.validateMedicalWardInventoryRow(savedInventory, medicalInventoryRows); - int inventoryId = inventory.getId(); - inventory = medicalInventoryIoOperation.getInventoryById(inventoryId); - assertThat(inventory).isNotNull(); - } - - @Test - void testValidateMedicalWardInventory() 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"); - Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); - chargeType = medicalDsrStockMovementTypeIoOperationRepository.save(chargeType); - dischargeType = medicalDsrStockMovementTypeIoOperationRepository.save(dischargeType); - destination = wardIoOperationRepository.save(destination); - MedicalInventory inventory = testMedicalWardInventory.setup(ward, false); - inventory = medicalInventoryIoOperation.newMedicalInventory(inventory); - MedicalType medicalType = testMedicalType.setup(false); - Medical medical = testMedical.setup(medicalType, false); - Lot lotOne = testLot.setup(medical, false); - Supplier supplier = testSupplier.setup(false); - supplier = supplierIoOperationRepository.saveAndFlush(supplier); - Movement initialMovement = testMovement.setup(medical, chargeType, ward, lotOne, supplier, false); - initialMovement.setQuantity(200); - MedicalStock initialMedicalStock = testMedicalStock.setup(initialMovement); - Movement firstMovement = testMovement.setup(medical, dischargeType, ward, lotOne, null, false); - firstMovement.setQuantity(100); - MedicalStock firstmedicalStock = testMedicalStock.setup(firstMovement); - Lot lotTwo = testLot.setup(medical, false); - lotTwo.setCode("LOT-001"); - MovementWard wardMovement = testMovementWard.setup(ward, null, medical, ward, destination, lotTwo, false); - wardMovement.setQuantity(100.0); - Lot lotThree = testLot.setup(medical, false); - lotTwo.setCode("LOT-003"); - medicalTypeIoOperationRepository.saveAndFlush(medicalType); - medical = medicalsIoOperationRepository.save(medical); - lotOne = lotIoOperationRepository.save(lotOne); - lotTwo = lotIoOperationRepository.save(lotTwo); - lotThree = lotIoOperationRepository.save(lotThree); - medicalStockIoOperation.newMovement(initialMovement); - medicalStockIoOperationRepository.saveAndFlush(initialMedicalStock); - 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); - medicalStockIoOperation.newMovement(firstMovement); - medicalStockWardIoOperation.newMovementWard(wardMovement); - medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); - movementWardIoOperationRepository.saveAndFlush(wardMovement); - int inventoryId = inventory.getId(); - List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); - assertThat(medicalInventoryRows).isNotEmpty(); - assertThat(medicalInventoryRows).hasSize(3); - medicalInventoryManager.validateMedicalWardInventoryRow(inventory, medicalInventoryRows); + assertThatThrownBy(() -> { + Ward ward = testWard.setup(false); + wardIoOperationRepository.saveAndFlush(ward); + MovementType chargeType = new MovementType("inventory+", "Inventory+", "+", "non-operational"); + MovementType dischargeType = new MovementType("inventory-", "Inventory-", "-", "non-operational"); + Ward destination = new Ward("INV", "ward inventory", null, null, null, 8, 1, 1, false, false); + chargeType = medicalDsrStockMovementTypeIoOperationRepository.save(chargeType); + dischargeType = medicalDsrStockMovementTypeIoOperationRepository.save(dischargeType); + destination = wardIoOperationRepository.save(destination); + MedicalInventory inventory = testMedicalWardInventory.setup(ward, false); + MedicalType medicalType = testMedicalType.setup(false); + Medical medical = testMedical.setup(medicalType, false); + Lot lotOne = testLot.setup(medical, false); + Supplier supplier = testSupplier.setup(false); + supplier = supplierIoOperationRepository.saveAndFlush(supplier); + Movement initialMovement = testMovement.setup(medical, chargeType, ward, lotOne, supplier, false); + initialMovement.setQuantity(200); + MedicalStock initialMedicalStock = testMedicalStock.setup(initialMovement); + Movement firstMovement = testMovement.setup(medical, dischargeType, ward, lotOne, null, false); + firstMovement.setQuantity(100); + MedicalStock firstmedicalStock = testMedicalStock.setup(firstMovement); + Lot lotTwo = testLot.setup(medical, false); + lotTwo.setCode("LOT-002"); + MovementWard wardMovement = testMovementWard.setup(ward, null, medical, ward, destination, lotTwo, false); + wardMovement.setQuantity(100.0); + Lot lotThree = testLot.setup(medical, false); + lotThree.setCode("LOT-003"); + medicalTypeIoOperationRepository.saveAndFlush(medicalType); + medical = medicalsIoOperationRepository.save(medical); + lotOne = lotIoOperationRepository.save(lotOne); + lotTwo = lotIoOperationRepository.save(lotTwo); + lotThree = lotIoOperationRepository.save(lotThree); + medicalStockIoOperation.newMovement(initialMovement); + medicalStockIoOperationRepository.saveAndFlush(initialMedicalStock); + inventory = medicalInventoryIoOperation.newMedicalInventory(inventory); + 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); + medicalStockWardIoOperation.newMovementWard(wardMovement); + medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); + movementWardIoOperationRepository.saveAndFlush(wardMovement); + int inventoryId = inventory.getId(); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); + assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows).hasSize(3); + firstMovement.setQuantity(100); + firstMovement.setDate(LocalDateTime.now()); + firstmedicalStock = testMedicalStock.setup(firstMovement); + medicalStockIoOperation.newMovement(firstMovement); + medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); + Lot lotfour = testLot.setup(medical, false); + lotfour.setCode("LOT-004"); + lotfour = lotIoOperationRepository.save(lotfour); + Movement secondMovement = testMovement.setup(medical, dischargeType, ward, lotfour, null, false); + secondMovement.setQuantity(50); + secondMovement.setDate(LocalDateTime.now()); + MedicalStock secondMedicalStock = testMedicalStock.setup(secondMovement); + medicalStockIoOperation.newMovement(secondMovement); + medicalStockIoOperationRepository.saveAndFlush(secondMedicalStock); + Medical secondMedical = testMedical.setup(medicalType,false); + secondMedical.setProdCode("TP2"); + secondMedical.setDescription("test description"); + secondMedical = medicalsIoOperationRepository.save(secondMedical); + Lot lotFive = testLot.setup(secondMedical, false); + lotFive.setCode("LOT-005"); + lotFive = lotIoOperationRepository.save(lotFive); + initialMovement = testMovement.setup(secondMedical, chargeType, ward, lotFive, supplier, false); + initialMovement.setQuantity(200); + initialMedicalStock = testMedicalStock.setup(initialMovement); + medicalStockIoOperation.newMovement(initialMovement); + medicalStockIoOperationRepository.saveAndFlush(initialMedicalStock); + Movement thirdMovement = testMovement.setup(secondMedical, dischargeType, ward, lotFive, null, false); + thirdMovement.setDate(LocalDateTime.now()); + MedicalStock thirdMedicalStock = testMedicalStock.setup(thirdMovement); + medicalStockIoOperation.newMovement(thirdMovement); + medicalStockIoOperationRepository.saveAndFlush(thirdMedicalStock); + medicalInventoryManager.validateMedicalWardInventoryRow(inventory, medicalInventoryRows); + }).isInstanceOf(OHDataValidationException.class); } } From 24489e47afb455b437072ed056dfa92d031ebd7c Mon Sep 17 00:00:00 2001 From: JantBogard Date: Thu, 12 Dec 2024 14:17:41 +0100 Subject: [PATCH 16/18] Update test validation medical ward inventory row --- .../java/org/isf/medicalsinventory/Tests.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index b5a273903..b58a2c34d 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -22,7 +22,7 @@ package org.isf.medicalsinventory; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.catchThrowable; import java.time.LocalDateTime; import java.util.List; @@ -833,7 +833,8 @@ void testValidateMedicalInventory() throws Exception { @Test void testValidateMedicalWardInventoryRow() throws Exception { - assertThatThrownBy(() -> { + Throwable throwable = catchThrowable(() -> { + // Initialize data and create movements Ward ward = testWard.setup(false); wardIoOperationRepository.saveAndFlush(ward); MovementType chargeType = new MovementType("inventory+", "Inventory+", "+", "non-operational"); @@ -867,6 +868,7 @@ void testValidateMedicalWardInventoryRow() throws Exception { lotThree = lotIoOperationRepository.save(lotThree); medicalStockIoOperation.newMovement(initialMovement); medicalStockIoOperationRepository.saveAndFlush(initialMedicalStock); + // Create inventory and inventory rows inventory = medicalInventoryIoOperation.newMedicalInventory(inventory); MedicalInventoryRow medicalInventoryRowOne = testMedicalInventoryRow.setup(inventory, medical, lotOne, false); medicalInventoryRowOne.setRealqty(60); @@ -886,11 +888,15 @@ void testValidateMedicalWardInventoryRow() throws Exception { List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); assertThat(medicalInventoryRows).isNotEmpty(); assertThat(medicalInventoryRows).hasSize(3); + + // test case 1: Create movement from the main to the ward to add quantity for existing lot in the ward firstMovement.setQuantity(100); firstMovement.setDate(LocalDateTime.now()); firstmedicalStock = testMedicalStock.setup(firstMovement); medicalStockIoOperation.newMovement(firstMovement); medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); + + // test case 2: Create movement from the main to the ward to add new lot Lot lotfour = testLot.setup(medical, false); lotfour.setCode("LOT-004"); lotfour = lotIoOperationRepository.save(lotfour); @@ -900,6 +906,8 @@ void testValidateMedicalWardInventoryRow() throws Exception { MedicalStock secondMedicalStock = testMedicalStock.setup(secondMovement); medicalStockIoOperation.newMovement(secondMovement); medicalStockIoOperationRepository.saveAndFlush(secondMedicalStock); + + // test case 3: Create movement from the main to the ward to add new medical Medical secondMedical = testMedical.setup(medicalType,false); secondMedical.setProdCode("TP2"); secondMedical.setDescription("test description"); @@ -917,7 +925,13 @@ void testValidateMedicalWardInventoryRow() throws Exception { MedicalStock thirdMedicalStock = testMedicalStock.setup(thirdMovement); medicalStockIoOperation.newMovement(thirdMovement); medicalStockIoOperationRepository.saveAndFlush(thirdMedicalStock); + + // test validate medical ward inventory row medicalInventoryManager.validateMedicalWardInventoryRow(inventory, medicalInventoryRows); - }).isInstanceOf(OHDataValidationException.class); + }); + // Test if exception is OHDataValidationException instance + assertThat(throwable).isInstanceOf(OHDataValidationException.class); + // Test if size of message list is equal to 3 + assertThat(((OHDataValidationException) throwable).getMessages().size()).isEqualTo(3); } } From 66a157904b6e8f3fd5612dd068ec7f2ac0dcb680 Mon Sep 17 00:00:00 2001 From: JantBogard Date: Thu, 12 Dec 2024 14:21:34 +0100 Subject: [PATCH 17/18] Update test validation medical ward inventory row --- 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 b58a2c34d..92695e25f 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -832,7 +832,7 @@ void testValidateMedicalInventory() throws Exception { } @Test - void testValidateMedicalWardInventoryRow() throws Exception { + void testValidateMedicalWardInventoryRow() { Throwable throwable = catchThrowable(() -> { // Initialize data and create movements Ward ward = testWard.setup(false); From a3084ae61bf90b5ae9043dc254b34b126dceab0e Mon Sep 17 00:00:00 2001 From: JantBogard Date: Wed, 18 Dec 2024 16:50:39 +0100 Subject: [PATCH 18/18] Add actualize inventory row test --- .../manager/MedicalInventoryManager.java | 1 + .../java/org/isf/medicalsinventory/Tests.java | 99 +++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java index 0bb28c493..0311abbe4 100644 --- a/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java +++ b/src/main/java/org/isf/medicalinventory/manager/MedicalInventoryManager.java @@ -708,6 +708,7 @@ public MedicalInventory actualizeMedicalWardInventoryRow(MedicalInventory invent if (wardStoreQty != theoQty) { // Update Lot medicalInventoryRow.setTheoreticQty(wardStoreQty); + medicalInventoryRow.setRealqty(wardStoreQty); medicalInventoryRowManager.updateMedicalInventoryRow(medicalInventoryRow); } } else { diff --git a/src/test/java/org/isf/medicalsinventory/Tests.java b/src/test/java/org/isf/medicalsinventory/Tests.java index 92695e25f..38a2c79e6 100644 --- a/src/test/java/org/isf/medicalsinventory/Tests.java +++ b/src/test/java/org/isf/medicalsinventory/Tests.java @@ -934,4 +934,103 @@ void testValidateMedicalWardInventoryRow() { // Test if size of message list is equal to 3 assertThat(((OHDataValidationException) throwable).getMessages().size()).isEqualTo(3); } + + @Test + void testActualizeMedicalWardInventoryRow() throws Exception { + // Initialize data + Ward ward = testWard.setup(false); + wardIoOperationRepository.saveAndFlush(ward); + MedicalInventory inventory = testMedicalWardInventory.setup(ward, false); + MedicalType medicalType = testMedicalType.setup(false); + Medical medical = testMedical.setup(medicalType, false); + Lot lotOne = testLot.setup(medical, false); + medicalTypeIoOperationRepository.saveAndFlush(medicalType); + medical = medicalsIoOperationRepository.save(medical); + lotOne = lotIoOperationRepository.save(lotOne); + + MovementType chargeType = new MovementType("inventory+", "Inventory+", "+", "non-operational"); + MovementType dischargeType = new MovementType("inventory-", "Inventory-", "-", "non-operational"); + chargeType = medicalDsrStockMovementTypeIoOperationRepository.save(chargeType); + dischargeType = medicalDsrStockMovementTypeIoOperationRepository.save(dischargeType); + Supplier supplier = testSupplier.setup(false); + supplier = supplierIoOperationRepository.saveAndFlush(supplier); + Movement initialMovement = testMovement.setup(medical, chargeType, ward, lotOne, supplier, false); + initialMovement.setQuantity(200); + MedicalStock initialMedicalStock = testMedicalStock.setup(initialMovement); + Movement firstMovement = testMovement.setup(medical, dischargeType, ward, lotOne, null, false); + firstMovement.setDate(LocalDateTime.now()); + firstMovement.setQuantity(10); + MedicalStock firstmedicalStock = testMedicalStock.setup(firstMovement); + medicalStockIoOperation.newMovement(initialMovement); + medicalStockIoOperationRepository.saveAndFlush(initialMedicalStock); + medicalStockIoOperation.newMovement(firstMovement); + medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); + + // Create inventory and inventory rows + inventory = medicalInventoryIoOperation.newMedicalInventory(inventory); + MedicalInventoryRow medicalInventoryRowOne = testMedicalInventoryRow.setup(inventory, medical, lotOne, false); + medicalInventoryRowOne.setRealqty(10); + medicalInventoryRowOne.setTheoreticQty(10); + medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRowOne); + int inventoryId = inventory.getId(); + List medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId); + assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows).hasSize(1); + + // Create movements + Lot lotTwo = testLot.setup(medical, false); + lotTwo.setCode("LOT-002"); + lotTwo = lotIoOperationRepository.save(lotTwo); + medicalStockIoOperation.newMovement(initialMovement); + medicalStockIoOperationRepository.saveAndFlush(initialMedicalStock); + firstMovement.setQuantity(10); + firstMovement.setDate(LocalDateTime.now()); + firstmedicalStock = testMedicalStock.setup(firstMovement); + medicalStockIoOperation.newMovement(firstMovement); + medicalStockIoOperationRepository.saveAndFlush(firstmedicalStock); + Movement secondMovement = testMovement.setup(medical, dischargeType, ward, lotTwo, null, false); + secondMovement.setQuantity(20); + secondMovement.setDate(LocalDateTime.now()); + MedicalStock secondMedicalStock = testMedicalStock.setup(secondMovement); + medicalStockIoOperation.newMovement(secondMovement); + medicalStockIoOperationRepository.saveAndFlush(secondMedicalStock); + Medical secondMedical = testMedical.setup(medicalType,false); + secondMedical.setProdCode("TP2"); + secondMedical.setDescription("test description"); + secondMedical = medicalsIoOperationRepository.save(secondMedical); + Lot lotThree = testLot.setup(secondMedical, false); + lotThree.setCode("LOT-003"); + lotThree = lotIoOperationRepository.save(lotThree); + initialMovement = testMovement.setup(secondMedical, chargeType, ward, lotThree, supplier, false); + initialMovement.setQuantity(40); + initialMedicalStock = testMedicalStock.setup(initialMovement); + medicalStockIoOperation.newMovement(initialMovement); + medicalStockIoOperationRepository.saveAndFlush(initialMedicalStock); + Movement thirdMovement = testMovement.setup(secondMedical, dischargeType, ward, lotThree, null, false); + thirdMovement.setQuantity(30); + thirdMovement.setDate(LocalDateTime.now()); + MedicalStock thirdMedicalStock = testMedicalStock.setup(thirdMovement); + medicalStockIoOperation.newMovement(thirdMovement); + medicalStockIoOperationRepository.saveAndFlush(thirdMedicalStock); + + //Test actualize ward inventory row + inventory = medicalInventoryManager.actualizeMedicalWardInventoryRow(inventory); + + medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventory.getId()); + + assertThat(medicalInventoryRows).isNotEmpty(); + assertThat(medicalInventoryRows).hasSize(3); + + assertThat(medicalInventoryRows.get(0).getLot()).isEqualTo(lotOne); + assertThat(medicalInventoryRows.get(0).getRealQty()).isEqualTo(20); + assertThat(medicalInventoryRows.get(0).getTheoreticQty()).isEqualTo(20); + + assertThat(medicalInventoryRows.get(1).getLot()).isEqualTo(lotTwo); + assertThat(medicalInventoryRows.get(1).getRealQty()).isEqualTo(20); + assertThat(medicalInventoryRows.get(1).getTheoreticQty()).isEqualTo(20); + + assertThat(medicalInventoryRows.get(2).getLot()).isEqualTo(lotThree); + assertThat(medicalInventoryRows.get(2).getRealQty()).isEqualTo(30); + assertThat(medicalInventoryRows.get(2).getTheoreticQty()).isEqualTo(30); + } }