From 30fdddcee7aaafd93dd2b5271997542238f5fab9 Mon Sep 17 00:00:00 2001 From: FOFOU FONZAM Gui Arnaud Date: Thu, 21 Nov 2024 11:28:01 +0100 Subject: [PATCH] OP-1361 | Fix getMedicalsWard method (#1452) * update the param of getMedicalsWard method * update file step_a104_add_inventory_in_pharmacy.sql * add script to update type of column MINVT_WRD_ID_A of oh_medicaldsrinventory * revert step_a104_add_inventory_in_pharmacy.sql * Update sql/step_a113_alter_table_medicalinventory.sql * update the name of the contraint for foreign key --------- Co-authored-by: ArnaudFofou Co-authored-by: Alessandro Domanico --- sql/step_04_all_following_steps.sql | 1 + ...step_a113_alter_table_medicalinventory.sql | 50 +++++++++++++++++++ .../manager/MovWardBrowserManager.java | 4 +- .../service/MedicalStockWardIoOperations.java | 6 +-- .../java/org/isf/medicalstockward/Tests.java | 10 ++-- 5 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 sql/step_a113_alter_table_medicalinventory.sql diff --git a/sql/step_04_all_following_steps.sql b/sql/step_04_all_following_steps.sql index 89e8d3e28..a52df28d0 100644 --- a/sql/step_04_all_following_steps.sql +++ b/sql/step_04_all_following_steps.sql @@ -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; \ No newline at end of file diff --git a/sql/step_a113_alter_table_medicalinventory.sql b/sql/step_a113_alter_table_medicalinventory.sql new file mode 100644 index 000000000..69c358a4e --- /dev/null +++ b/sql/step_a113_alter_table_medicalinventory.sql @@ -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); + + + diff --git a/src/main/java/org/isf/medicalstockward/manager/MovWardBrowserManager.java b/src/main/java/org/isf/medicalstockward/manager/MovWardBrowserManager.java index e0f2d7977..542bd6fa6 100644 --- a/src/main/java/org/isf/medicalstockward/manager/MovWardBrowserManager.java +++ b/src/main/java/org/isf/medicalstockward/manager/MovWardBrowserManager.java @@ -85,7 +85,7 @@ protected void validateMovementWard(MovementWard mov) throws OHDataValidationExc * @return the retrieved medicals. * @throws OHServiceException */ - public List getMedicalsWard(char wardId, boolean stripeEmpty) throws OHServiceException { + public List getMedicalsWard(String wardId, boolean stripeEmpty) throws OHServiceException { return ioOperations.getMedicalsWard(wardId, stripeEmpty); } @@ -111,7 +111,7 @@ public List getMedicalsWard(String wardId, int medId, boolean strip * @return the retrieved medicals. * @throws OHServiceException */ - public List getMedicalsWardTotalQuantity(char wardId) throws OHServiceException { + public List getMedicalsWardTotalQuantity(String wardId) throws OHServiceException { return ioOperations.getMedicalsWardTotalQuantity(wardId); } diff --git a/src/main/java/org/isf/medicalstockward/service/MedicalStockWardIoOperations.java b/src/main/java/org/isf/medicalstockward/service/MedicalStockWardIoOperations.java index a915d0664..dd58dbc5b 100644 --- a/src/main/java/org/isf/medicalstockward/service/MedicalStockWardIoOperations.java +++ b/src/main/java/org/isf/medicalstockward/service/MedicalStockWardIoOperations.java @@ -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 getMedicalsWard(char wardId, boolean stripeEmpty) throws OHServiceException { - return getMedicalsWard(String.valueOf(wardId), 0, stripeEmpty); + public List getMedicalsWard(String wardId, boolean stripeEmpty) throws OHServiceException { + return getMedicalsWard(wardId, 0, stripeEmpty); } /** @@ -287,7 +287,7 @@ public List getWardMovementsToPatient(Integer patId) { * @return the retrieved medicals. * @throws OHServiceException */ - public List getMedicalsWardTotalQuantity(char wardId) throws OHServiceException { + public List getMedicalsWardTotalQuantity(String wardId) throws OHServiceException { String wardID = String.valueOf(wardId); List medicalWards = getMedicalsWard(wardId, true); diff --git a/src/test/java/org/isf/medicalstockward/Tests.java b/src/test/java/org/isf/medicalstockward/Tests.java index 5f907e86e..f9bbfed9f 100644 --- a/src/test/java/org/isf/medicalstockward/Tests.java +++ b/src/test/java/org/isf/medicalstockward/Tests.java @@ -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 medicalWards = medicalStockWardIoOperations.getMedicalsWard(foundMedicalWard.getWard().getCode().charAt(0), true); + List medicalWards = medicalStockWardIoOperations.getMedicalsWard(foundMedicalWard.getWard().getCode(), true); assertThat(medicalWards.get(0).getQty()).isCloseTo(foundMedicalWard.getIn_quantity() - foundMedicalWard.getOut_quantity(), offset(0.1)); } @@ -412,7 +412,7 @@ void testIoGetMedicalsWardStripEmptyLots() throws Exception { medicalWard.setIn_quantity(10.0f); medicalWard.setOut_quantity(10.0f); medicalStockWardIoOperationRepository.saveAndFlush(medicalWard); - List medicalWards = medicalStockWardIoOperations.getMedicalsWard(medicalWard.getWard().getCode().charAt(0), true); + List medicalWards = medicalStockWardIoOperations.getMedicalsWard(medicalWard.getWard().getCode(), true); assertThat(medicalWards).isEmpty(); } @@ -465,7 +465,7 @@ void testIoGetMedicalsWardTotalQuantity() throws Exception { medicalStockWardIoOperations.newMovementWard(movementWard); - List medicalWards = medicalStockWardIoOperations.getMedicalsWardTotalQuantity('X'); + List medicalWards = medicalStockWardIoOperations.getMedicalsWardTotalQuantity("X"); assertThat(medicalWards).hasSize(1); assertThat(medicalWards.get(0).getWard().getCode()).isEqualTo("X"); } @@ -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 medicalWards = movWardBrowserManager.getMedicalsWard(foundMedicalWard.getWard().getCode().charAt(0), true); + List medicalWards = movWardBrowserManager.getMedicalsWard(foundMedicalWard.getWard().getCode(), true); assertThat(medicalWards.get(0).getQty()).isCloseTo(foundMedicalWard.getIn_quantity() - foundMedicalWard.getOut_quantity(), offset(0.1)); } @@ -689,7 +689,7 @@ void testMgrGetMedicalsWardTotalQuantity() throws Exception { movWardBrowserManager.newMovementWard(movementWard); - List medicalWards = movWardBrowserManager.getMedicalsWardTotalQuantity('X'); + List medicalWards = movWardBrowserManager.getMedicalsWardTotalQuantity("X"); assertThat(medicalWards).hasSize(1); assertThat(medicalWards.get(0).getWard().getCode()).isEqualTo("X"); }