Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

OP-1305 | Add confirm inventory method #1430

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

Filter by extension

Filter by extension

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

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

private MovBrowserManager movBrowserManager;

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

private SupplierBrowserManager supplierManager;

private WardBrowserManager wardManager;

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

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

/**
* Confirm the Inventory rows of inventory.
*
* @param inventory - The {@link MedicalInventory}
* @param inventoryRowSearchList- The list of {@link MedicalInventory}
* @throws OHDataValidationException
*/
@Transactional(rollbackFor = OHServiceException.class)
public void confirmMedicalInventoryRow(MedicalInventory inventory, List<MedicalInventoryRow> inventoryRowSearchList) throws OHServiceException {
// validate the inventory
this.validateMedicalInventoryRow(inventory, inventoryRowSearchList);
// create Movements
String dischargeCode = inventory.getDischargeType();
String chargeCode = inventory.getChargeType();
Integer supplierId = inventory.getSupplier();
String wardCode = inventory.getDestination();
MovementType chargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(chargeCode);
MovementType dischargeType = medicalDsrStockMovementTypeBrowserManager.getMovementType(dischargeCode);
Supplier supplier = supplierManager.getByID(supplierId);
Ward ward = wardManager.findWard(wardCode);
LocalDateTime now = TimeTools.getNow();
for (Iterator<MedicalInventoryRow> iterator = inventoryRowSearchList.iterator(); iterator.hasNext();) {
MedicalInventoryRow medicalInventoryRow = (MedicalInventoryRow) iterator.next();
StringBuilder referenceBuilder = new StringBuilder();
referenceBuilder.append(inventory.getInventoryReference())
.append("-")
.append(now);
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
double theoQty = medicalInventoryRow.getTheoreticQty();
double realQty = medicalInventoryRow.getRealQty();
Double ajustQty = theoQty - realQty;
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
Medical medical = medicalInventoryRow.getMedical();
String lotCode = medicalInventoryRow.getLot().getCode();
Lot currentLot = movStockInsertingManager.getLot(lotCode);
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
if (realQty > theoQty) { // charge movement when realQty > theoQty
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
referenceBuilder.append("-charge");
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
String reference = referenceBuilder.toString();
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
Movement movement = new Movement(medical, chargeType, null, currentLot, now, -(ajustQty.intValue()), supplier, reference);
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
List<Movement> chargeMovement = new ArrayList<>();
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
chargeMovement.add(movement);
chargeMovement = movStockInsertingManager.newMultipleChargingMovements(chargeMovement, reference);
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
} else if (realQty < theoQty) { // discharge movement when realQty < theoQty
referenceBuilder.append("-discharge");
String reference = referenceBuilder.toString();
Movement movement = new Movement(medical, dischargeType, ward, currentLot, now, ajustQty.intValue(), null, reference);
List<Movement> dischargeMovement = new ArrayList<>();
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
dischargeMovement.add(movement);
dischargeMovement = movStockInsertingManager.newMultipleDischargingMovements(dischargeMovement, reference);
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

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

public class TestMedicalInventory {

private int id = 1;
private String status = "STATUS";
private LocalDateTime inventoryDate = LocalDateTime.now();
private String user = "USER";
private String status = InventoryStatus.draft.toString();
private LocalDateTime inventoryDate = TimeTools.getNow();
private String user = "admin";
private String inventoryReference = "REFERENCE";
private String inventoryType = "TYPE";
private String inventoryType = InventoryType.main.toString();
private String ward = "Z";
private int supplier = 3;
private String destination = "INV";
Expand Down
66 changes: 64 additions & 2 deletions src/test/java/org/isf/medicalsinventory/Tests.java
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;

import org.isf.OHCoreTestCase;
import org.isf.generaldata.GeneralData;
import org.isf.medicalinventory.manager.MedicalInventoryManager;
import org.isf.medicalinventory.manager.MedicalInventoryRowManager;
import org.isf.medicalinventory.model.InventoryStatus;
Expand Down Expand Up @@ -96,6 +97,9 @@ class Tests extends OHCoreTestCase {

@Autowired
LotIoOperationRepository lotIoOperationRepository;

@Autowired
MedicalInventoryRowIoOperationRepository medicalInventoryRowIoOperationRepository;

@BeforeAll
static void setUpClass() {
Expand Down Expand Up @@ -520,8 +524,7 @@ void testMgrGetMedicalInventoryRowByInventoryId() throws Exception {
assertThat(newMedicalInventoryRow).isNotNull();
List<MedicalInventoryRow> medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryId);
assertThat(medicalInventoryRows).isNotEmpty();
assertThat(medicalInventoryRows).hasSize(1);

assertThat(medicalInventoryRows).hasSize(1);
}

private int setupTestMedicalInventory(boolean usingSet) throws OHException, OHServiceException {
Expand Down Expand Up @@ -572,4 +575,63 @@ void testDeleteInventory() throws Exception {
assertThat(deletedInventory).isNotNull();
assertThat(deletedInventory.getStatus()).isEqualTo(InventoryStatus.canceled.toString());
}

@Test
void testValidateMedicalInventory() throws Exception {
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
Ward ward = testWard.setup(false);
wardIoOperationRepository.saveAndFlush(ward);
MedicalInventory inventory = testMedicalInventory.setup(ward, false);
MedicalInventory savedInventory = medicalInventoryIoOperation.newMedicalInventory(inventory);
MedicalType medicalType = testMedicalType.setup(false);
medicalTypeIoOperationRepository.saveAndFlush(medicalType);
Medical medical = testMedical.setup(medicalType, false);
medicalsIoOperationRepository.saveAndFlush(medical);
Lot lot = testLot.setup(medical, false);
lotIoOperationRepository.saveAndFlush(lot);
MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false);
int inventoryRowId = medicalInventoryRow.getId();
MedicalInventoryRow newMedicalInventoryRow = medicalInventoryRowManager.newMedicalInventoryRow(medicalInventoryRow);
assertThat(newMedicalInventoryRow).isNotNull();
List<MedicalInventoryRow> medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId);
assertThat(medicalInventoryRows).isNotEmpty();
assertThat(medicalInventoryRows).hasSize(1);
medicalInventoryManager.validateMedicalInventoryRow(savedInventory, medicalInventoryRows);
int inventoryId = inventory.getId();
inventory = medicalInventoryIoOperation.getInventoryById(inventoryId);
assertThat(inventory).isNotNull();
String status = InventoryStatus.validated.toString();
inventory.setStatus(status);
inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory);
assertThat(inventory).isNotNull();
assertThat(inventory.getStatus()).isEqualTo(status);
}

@Test
void testConfirmMedicalInventory() throws Exception {
Ward ward = testWard.setup(false);
wardIoOperationRepository.saveAndFlush(ward);
MedicalInventory inventory = testMedicalInventory.setup(ward, false);
mwithi marked this conversation as resolved.
Show resolved Hide resolved
MedicalInventory savedInventory = medicalInventoryIoOperation.newMedicalInventory(inventory);
MedicalType medicalType = testMedicalType.setup(false);
Medical medical = testMedical.setup(medicalType, false);
Lot lot = testLot.setup(medical, false);
MedicalInventoryRow medicalInventoryRow = testMedicalInventoryRow.setup(savedInventory, medical, lot, false);
medicalInventoryRow.setRealqty(60);
ArnaudFonzam marked this conversation as resolved.
Show resolved Hide resolved
medicalTypeIoOperationRepository.saveAndFlush(medicalType);
medicalsIoOperationRepository.saveAndFlush(medical);
lotIoOperationRepository.saveAndFlush(lot);
medicalInventoryRowIoOperationRepository.saveAndFlush(medicalInventoryRow);
int inventoryRowId = medicalInventoryRow.getId();
List<MedicalInventoryRow> medicalInventoryRows = medicalInventoryRowManager.getMedicalInventoryRowByInventoryId(inventoryRowId);
assertThat(medicalInventoryRows).isNotEmpty();
medicalInventoryManager.confirmMedicalInventoryRow(savedInventory, medicalInventoryRows);
int inventoryId = savedInventory.getId();
inventory = medicalInventoryIoOperation.getInventoryById(inventoryId);
assertThat(inventory).isNotNull();
String status = InventoryStatus.done.toString();
inventory.setStatus(status);
inventory = medicalInventoryIoOperation.updateMedicalInventory(inventory);
assertThat(inventory).isNotNull();
assertThat(inventory.getStatus()).isEqualTo(status);
}
}
Loading