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-1361 | Fix getMedicalsWard method #1452

Merged
merged 10 commits into from
Nov 21, 2024
1 change: 1 addition & 0 deletions sql/step_04_all_following_steps.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,4 @@ source step_a109_update_user_settings_table_constraints_and_add_usergroups_permi
source step_a110_update_operations_table_change_ope_for_to_enum.sql;
source step_a111_add_missing_lock_columns.sql;
source step_a112_users_and_groups_soft_deletion.sql;
source step_a113_alter_table_medicalinventory.sql;
50 changes: 50 additions & 0 deletions sql/step_a113_alter_table_medicalinventory.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Step 1: Drop the foreign key constraint
ALTER TABLE OH_MEDICALDSRINVENTORY
DROP CONSTRAINT oh_medicaldsrinventory_ibfk_2;

ALTER TABLE OH_MEDICALDSRINVENTORY
DROP CONSTRAINT oh_medicaldsrinventory_ibfk_1;

ALTER TABLE OH_MEDICALDSRINVENTORY
DROP CONSTRAINT oh_medicaldsrinventory_ibfk_3;

ALTER TABLE OH_MEDICALDSRINVENTORY
DROP CONSTRAINT oh_medicaldsrinventory_ibfk_4;

ALTER TABLE OH_MEDICALDSRINVENTORY
DROP CONSTRAINT oh_medicaldsrinventory_ibfk_5;

ALTER TABLE OH_MEDICALDSRINVENTORY
DROP CONSTRAINT oh_medicaldsrinventory_ibfk_6;

-- Step 2: Change the data type of the foreign key column
ALTER TABLE OH_MEDICALDSRINVENTORY
MODIFY COLUMN MINVT_WRD_ID_A CHAR(3);

-- Step 3: Recreate the foreign key constraint
ALTER TABLE OH_MEDICALDSRINVENTORY
ADD CONSTRAINT FK_MEDICALDSRINVENTORY_WARD_1
FOREIGN KEY (MINVT_WRD_ID_A) REFERENCES OH_WARD (WRD_ID_A);

ALTER TABLE OH_MEDICALDSRINVENTORY
ADD CONSTRAINT FK_MEDICALDSRINVENTORY_USER
FOREIGN KEY (MINVT_US_ID_A) REFERENCES OH_USER (US_ID_A);

ALTER TABLE OH_MEDICALDSRINVENTORY
ADD CONSTRAINT FK_MEDICALDSRINVENTORY_MEDICALDSRSTOCKMOVTYPE_1
FOREIGN KEY (MINVT_CHARGE_TYPE) REFERENCES OH_MEDICALDSRSTOCKMOVTYPE (MMVT_ID_A);

ALTER TABLE OH_MEDICALDSRINVENTORY
ADD CONSTRAINT FK_MEDICALDSRINVENTORY_MEDICALDSRSTOCKMOVTYPE_2
FOREIGN KEY (MINVT_DISCHARGE_TYPE) REFERENCES OH_MEDICALDSRSTOCKMOVTYPE (MMVT_ID_A);

ALTER TABLE OH_MEDICALDSRINVENTORY
ADD CONSTRAINT FK_MEDICALDSRINVENTORY_SUPPLIER
FOREIGN KEY (MINVT_SUPPLIER) REFERENCES OH_SUPPLIER (SUP_ID);

ALTER TABLE OH_MEDICALDSRINVENTORY
ADD CONSTRAINT FK_MEDICALDSRINVENTORY_WARD_2
FOREIGN KEY (MINVT_DESTINATION) REFERENCES OH_WARD (WRD_ID_A);



Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected void validateMovementWard(MovementWard mov) throws OHDataValidationExc
* @return the retrieved medicals.
* @throws OHServiceException
*/
public List<MedicalWard> getMedicalsWard(char wardId, boolean stripeEmpty) throws OHServiceException {
public List<MedicalWard> getMedicalsWard(String wardId, boolean stripeEmpty) throws OHServiceException {
return ioOperations.getMedicalsWard(wardId, stripeEmpty);
}

Expand All @@ -111,7 +111,7 @@ public List<MedicalWard> getMedicalsWard(String wardId, int medId, boolean strip
* @return the retrieved medicals.
* @throws OHServiceException
*/
public List<MedicalWard> getMedicalsWardTotalQuantity(char wardId) throws OHServiceException {
public List<MedicalWard> getMedicalsWardTotalQuantity(String wardId) throws OHServiceException {
return ioOperations.getMedicalsWardTotalQuantity(wardId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ protected void updateStockWardQuantity(MovementWard movement) throws OHServiceEx
* @return the retrieved medicals.
* @throws OHServiceException if an error occurs during the medical retrieving.
*/
public List<MedicalWard> getMedicalsWard(char wardId, boolean stripeEmpty) throws OHServiceException {
return getMedicalsWard(String.valueOf(wardId), 0, stripeEmpty);
public List<MedicalWard> getMedicalsWard(String wardId, boolean stripeEmpty) throws OHServiceException {
return getMedicalsWard(wardId, 0, stripeEmpty);
}

/**
Expand Down Expand Up @@ -287,7 +287,7 @@ public List<MovementWard> getWardMovementsToPatient(Integer patId) {
* @return the retrieved medicals.
* @throws OHServiceException
*/
public List<MedicalWard> getMedicalsWardTotalQuantity(char wardId) throws OHServiceException {
public List<MedicalWard> getMedicalsWardTotalQuantity(String wardId) throws OHServiceException {
String wardID = String.valueOf(wardId);
List<MedicalWard> medicalWards = getMedicalsWard(wardId, true);

Expand Down
10 changes: 5 additions & 5 deletions src/test/java/org/isf/medicalstockward/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ void testIoDeleteMovementWard() throws Exception {
void testIoGetMedicalsWard() throws Exception {
MedicalWardId code = setupTestMedicalWard(false);
MedicalWard foundMedicalWard = medicalStockWardIoOperationRepository.findOneWhereCodeAndMedical(code.getWard().getCode(), code.getMedical().getCode());
List<MedicalWard> medicalWards = medicalStockWardIoOperations.getMedicalsWard(foundMedicalWard.getWard().getCode().charAt(0), true);
List<MedicalWard> medicalWards = medicalStockWardIoOperations.getMedicalsWard(foundMedicalWard.getWard().getCode(), true);
assertThat(medicalWards.get(0).getQty()).isCloseTo(foundMedicalWard.getIn_quantity() - foundMedicalWard.getOut_quantity(), offset(0.1));
}

Expand All @@ -412,7 +412,7 @@ void testIoGetMedicalsWardStripEmptyLots() throws Exception {
medicalWard.setIn_quantity(10.0f);
medicalWard.setOut_quantity(10.0f);
medicalStockWardIoOperationRepository.saveAndFlush(medicalWard);
List<MedicalWard> medicalWards = medicalStockWardIoOperations.getMedicalsWard(medicalWard.getWard().getCode().charAt(0), true);
List<MedicalWard> medicalWards = medicalStockWardIoOperations.getMedicalsWard(medicalWard.getWard().getCode(), true);
assertThat(medicalWards).isEmpty();
}

Expand Down Expand Up @@ -465,7 +465,7 @@ void testIoGetMedicalsWardTotalQuantity() throws Exception {

medicalStockWardIoOperations.newMovementWard(movementWard);

List<MedicalWard> medicalWards = medicalStockWardIoOperations.getMedicalsWardTotalQuantity('X');
List<MedicalWard> medicalWards = medicalStockWardIoOperations.getMedicalsWardTotalQuantity("X");
assertThat(medicalWards).hasSize(1);
assertThat(medicalWards.get(0).getWard().getCode()).isEqualTo("X");
}
Expand All @@ -491,7 +491,7 @@ void testIoListenerShouldUpdatePatientToMergedWhenPatientMergedEventArrive() thr
void testMgrGetMedicalsWard() throws Exception {
MedicalWardId code = setupTestMedicalWard(false);
MedicalWard foundMedicalWard = medicalStockWardIoOperationRepository.findOneWhereCodeAndMedical(code.getWard().getCode(), code.getMedical().getCode());
List<MedicalWard> medicalWards = movWardBrowserManager.getMedicalsWard(foundMedicalWard.getWard().getCode().charAt(0), true);
List<MedicalWard> medicalWards = movWardBrowserManager.getMedicalsWard(foundMedicalWard.getWard().getCode(), true);
assertThat(medicalWards.get(0).getQty()).isCloseTo(foundMedicalWard.getIn_quantity() - foundMedicalWard.getOut_quantity(), offset(0.1));
}

Expand Down Expand Up @@ -689,7 +689,7 @@ void testMgrGetMedicalsWardTotalQuantity() throws Exception {

movWardBrowserManager.newMovementWard(movementWard);

List<MedicalWard> medicalWards = movWardBrowserManager.getMedicalsWardTotalQuantity('X');
List<MedicalWard> medicalWards = movWardBrowserManager.getMedicalsWardTotalQuantity("X");
assertThat(medicalWards).hasSize(1);
assertThat(medicalWards.get(0).getWard().getCode()).isEqualTo("X");
}
Expand Down