From 944602330c66399090c56dc39662a763119f895b Mon Sep 17 00:00:00 2001 From: helderjosue Date: Sun, 24 Mar 2024 14:07:04 +0200 Subject: [PATCH 01/11] TRUNK-5068: adding test for Patient Program Attribute Type by Uuid --- .../api/ProgramWorkflowServiceTest.java | 32 +++++++++------- .../PatientProgramAttributeTestDataset.xml | 38 +++++++++++++++++++ 2 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index 8b4fef4d74ce..2a6f2937a393 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -29,19 +29,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.openmrs.Cohort; -import org.openmrs.Concept; -import org.openmrs.ConceptName; -import org.openmrs.ConceptStateConversion; -import org.openmrs.Encounter; -import org.openmrs.Patient; -import org.openmrs.PatientProgram; -import org.openmrs.PatientState; -import org.openmrs.Program; -import org.openmrs.ProgramAttributeType; -import org.openmrs.ProgramWorkflow; -import org.openmrs.ProgramWorkflowState; -import org.openmrs.User; +import org.openmrs.*; import org.openmrs.api.context.Context; import org.openmrs.api.db.ProgramWorkflowDAO; import org.openmrs.api.impl.ProgramWorkflowServiceImpl; @@ -62,7 +50,9 @@ public class ProgramWorkflowServiceTest extends BaseContextSensitiveTest { protected static final String PROGRAM_ATTRIBUTES_XML = "org/openmrs/api/include/ProgramAttributesDataset.xml"; protected static final String OTHER_PROGRAM_WORKFLOWS = "org/openmrs/api/include/ProgramWorkflowServiceTest-otherProgramWorkflows.xml"; - + + protected static final String PATIENT_PROGRAM_ATTRIBUTE_DATASET = "org/openmrs/api/include/PatientProgramAttributeTestDataset.xml"; + protected ProgramWorkflowService pws = null; @Autowired @@ -82,6 +72,7 @@ public void runBeforeEachTest() { executeDataSet(CREATE_PATIENT_PROGRAMS_XML); executeDataSet(PROGRAM_ATTRIBUTES_XML); executeDataSet(OTHER_PROGRAM_WORKFLOWS); + executeDataSet(PATIENT_PROGRAM_ATTRIBUTE_DATASET); if (pws == null) { pws = Context.getProgramWorkflowService(); @@ -1095,6 +1086,19 @@ public void triggerStateConversion_shouldTestTransitionToState(){ pwsi.triggerStateConversion(patient, trigger, dateConverted); assertEquals(patientProgram.getStates().size(), (patientStatesSize + 1)); } + + /** + * Test to check the implementation of Patient Program Attribute Type by Uuid + * from Program Workflow Service + * @see ProgramWorkflowService#getPatientProgramAttributeByUuid(String) + */ + @Test + public void getProgramAttributeTypeShouldPass(){ + + PatientProgramAttribute patientProgramAttribute = pws.getPatientProgramAttributeByUuid("dd8793dc-e9d2-11ee-9b67-333dbdea27a2"); + assertNotNull(patientProgramAttribute); + assertEquals(2, patientProgramAttribute.getId()); + } // /** // * This method should be uncommented when you want to examine the actual hibernate diff --git a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml new file mode 100644 index 000000000000..ba15ede1396e --- /dev/null +++ b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + From d3e735cf45a430f9bdbfeefed2c30466e5d239d4 Mon Sep 17 00:00:00 2001 From: helderjosue Date: Mon, 25 Mar 2024 22:02:11 +0200 Subject: [PATCH 02/11] TRUNK-5068: adding header to xml file --- .../include/PatientProgramAttributeTestDataset.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml index ba15ede1396e..e2159ed490ec 100644 --- a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml +++ b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml @@ -1,6 +1,15 @@ + + This Source Code Form is subject to the terms of the Mozilla Public License, + v. 2.0. If a copy of the MPL was not distributed with this file, You can + obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + + Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + graphic logo is a trademark of OpenMRS Inc. + +--> Date: Sun, 24 Mar 2024 15:39:24 +0200 Subject: [PATCH 03/11] TRUNK-5068: adding test for Patient Program Attribute Type by name --- .../org/openmrs/api/ProgramWorkflowServiceTest.java | 11 +++++++++++ .../include/PatientProgramAttributeTestDataset.xml | 9 +++++++++ .../openmrs/api/include/ProgramAttributesDataset.xml | 8 ++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index 2a6f2937a393..83f213606fe8 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -1099,6 +1099,17 @@ public void getProgramAttributeTypeShouldPass(){ assertNotNull(patientProgramAttribute); assertEquals(2, patientProgramAttribute.getId()); } + + /** + * Test to check the number of Patient Program attributes by given name + * @see ProgramWorkflowService#getPatientProgramAttributeByAttributeName(List, String) + */ + @Test + public void getProgramAttributeByAttributeNameShouldPass(){ + Map results = pws.getPatientProgramAttributeByAttributeName( + Collections.singletonList(2),"programName"); + assertEquals(1,results.size()); + } // /** // * This method should be uncommented when you want to examine the actual hibernate diff --git a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml index e2159ed490ec..a21b63bf0779 100644 --- a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml +++ b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml @@ -43,5 +43,14 @@ creator="1" date_created="2021-09-20 00:00:00.0" voided="false"/> + + diff --git a/api/src/test/resources/org/openmrs/api/include/ProgramAttributesDataset.xml b/api/src/test/resources/org/openmrs/api/include/ProgramAttributesDataset.xml index 2dd16ec5b050..e0ce12b6f335 100644 --- a/api/src/test/resources/org/openmrs/api/include/ProgramAttributesDataset.xml +++ b/api/src/test/resources/org/openmrs/api/include/ProgramAttributesDataset.xml @@ -13,6 +13,10 @@ + uuid="d7477c21-bfc3-4922-9591-e89d8b9c8efb"/> + + - \ No newline at end of file + From 9146080bba0b23178f323a3a11cc12bb5b72e7b1 Mon Sep 17 00:00:00 2001 From: helderjosue Date: Mon, 25 Mar 2024 15:18:24 +0200 Subject: [PATCH 04/11] TRUNK-5068: correcting old tests failling --- .../java/org/openmrs/api/ProgramWorkflowServiceTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index 83f213606fe8..ebac094d750b 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -724,7 +724,7 @@ public void purgeProgram_shouldPurgeProgramWithPatientsEnrolled() { } @Test public void shouldTestGetAllProgramAttributeTypes() throws Exception { - assertEquals(1, pws.getAllProgramAttributeTypes().size()); + assertEquals(2, pws.getAllProgramAttributeTypes().size()); } @Test @@ -742,11 +742,11 @@ public void shouldTestGetProgramAttributeTypeByUuid() throws Exception { @Test public void shouldTestSaveProgramAttributeType() throws Exception { - assertEquals(1,pws.getAllProgramAttributeTypes().size()); + assertEquals(2,pws.getAllProgramAttributeTypes().size()); ProgramAttributeType programAttributeType = new ProgramAttributeType(); programAttributeType.setName("test"); pws.saveProgramAttributeType(programAttributeType); - assertEquals(2,pws.getAllProgramAttributeTypes().size()); + assertEquals(3,pws.getAllProgramAttributeTypes().size()); } @Test From 40d259265442309bd48a4a71022169f6d93a07ee Mon Sep 17 00:00:00 2001 From: helderjosue Date: Mon, 25 Mar 2024 19:27:12 +0200 Subject: [PATCH 05/11] TRUNK-5068: adding test for Patient Program By Attribute Name And Value --- .../db/hibernate/HibernateProgramWorkflowDAO.java | 2 +- .../org/openmrs/api/ProgramWorkflowServiceTest.java | 13 +++++++++++++ .../include/PatientProgramAttributeTestDataset.xml | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/org/openmrs/api/db/hibernate/HibernateProgramWorkflowDAO.java b/api/src/main/java/org/openmrs/api/db/hibernate/HibernateProgramWorkflowDAO.java index 6da4177e94d7..2ca182e81edc 100644 --- a/api/src/main/java/org/openmrs/api/db/hibernate/HibernateProgramWorkflowDAO.java +++ b/api/src/main/java/org/openmrs/api/db/hibernate/HibernateProgramWorkflowDAO.java @@ -465,7 +465,7 @@ public List getPatientProgramByAttributeNameAndValue(String attr Query query; try { query = sessionFactory.getCurrentSession().createQuery( - "SELECT pp FROM patient_program pp " + + "SELECT pp FROM PatientProgram pp " + "INNER JOIN pp.attributes attr " + "INNER JOIN attr.attributeType attr_type " + "WHERE attr.valueReference = :attributeValue " + diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index ebac094d750b..42a9f5648320 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -26,6 +26,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.Collections; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -1110,6 +1112,17 @@ public void getProgramAttributeByAttributeNameShouldPass(){ Collections.singletonList(2),"programName"); assertEquals(1,results.size()); } + + /** + * Test to get a patient Program by its Attribute Name and Value Reference + */ + @Test + public void getPatientProgramByAttributeNameAndValue_shouldPass(){ + + List patientPrograms = + pws.getPatientProgramByAttributeNameAndValue("programName", "programReference"); + assertEquals(1, patientPrograms.size()); + } // /** // * This method should be uncommented when you want to examine the actual hibernate diff --git a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml index a21b63bf0779..36675e0468c8 100644 --- a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml +++ b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml @@ -48,6 +48,7 @@ patient_program_attribute_id = "3" patient_program_id = "1" attribute_type_id = "2" + value_reference = "programReference" uuid = "da88c81a-e9da-11ee-8b19-6f54994ac15c" creator="1" date_created="2021-12-20 00:00:00.0" From b60abc144d163edc188d137b24c89d3c6bf10ac0 Mon Sep 17 00:00:00 2001 From: helderjosue Date: Mon, 25 Mar 2024 19:29:14 +0200 Subject: [PATCH 06/11] TRUNK-5068: renaming test to match tests naming conventions --- .../java/org/openmrs/api/ProgramWorkflowServiceTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index 42a9f5648320..b6764e72bd7b 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -1095,7 +1095,7 @@ public void triggerStateConversion_shouldTestTransitionToState(){ * @see ProgramWorkflowService#getPatientProgramAttributeByUuid(String) */ @Test - public void getProgramAttributeTypeShouldPass(){ + public void getProgramAttributeType_shouldPass(){ PatientProgramAttribute patientProgramAttribute = pws.getPatientProgramAttributeByUuid("dd8793dc-e9d2-11ee-9b67-333dbdea27a2"); assertNotNull(patientProgramAttribute); @@ -1107,7 +1107,7 @@ public void getProgramAttributeTypeShouldPass(){ * @see ProgramWorkflowService#getPatientProgramAttributeByAttributeName(List, String) */ @Test - public void getProgramAttributeByAttributeNameShouldPass(){ + public void getProgramAttributeByAttributeName_shouldPass(){ Map results = pws.getPatientProgramAttributeByAttributeName( Collections.singletonList(2),"programName"); assertEquals(1,results.size()); @@ -1115,6 +1115,7 @@ public void getProgramAttributeByAttributeNameShouldPass(){ /** * Test to get a patient Program by its Attribute Name and Value Reference + * @see ProgramWorkflowService#getPatientProgramByAttributeNameAndValue(String, String) */ @Test public void getPatientProgramByAttributeNameAndValue_shouldPass(){ From 83a75bdc213360380f248742f9863293f7982785 Mon Sep 17 00:00:00 2001 From: helderjosue Date: Mon, 25 Mar 2024 19:45:53 +0200 Subject: [PATCH 07/11] TRUNK-5068: adding new program_attribute_type to avoid constraint violation on purge program_attribute_type --- .../api/include/PatientProgramAttributeTestDataset.xml | 2 +- .../org/openmrs/api/include/ProgramAttributesDataset.xml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml index 36675e0468c8..19d4910a22a5 100644 --- a/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml +++ b/api/src/test/resources/org/openmrs/api/include/PatientProgramAttributeTestDataset.xml @@ -38,7 +38,7 @@ + + From bd48688b994f7679da35c8668e8a3e58fad0049f Mon Sep 17 00:00:00 2001 From: helderjosue Date: Mon, 25 Mar 2024 19:46:15 +0200 Subject: [PATCH 08/11] TRUNK-5068: update old test with new amount of program_attribute_types --- .../java/org/openmrs/api/ProgramWorkflowServiceTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index b6764e72bd7b..ced060ed4081 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -726,7 +726,7 @@ public void purgeProgram_shouldPurgeProgramWithPatientsEnrolled() { } @Test public void shouldTestGetAllProgramAttributeTypes() throws Exception { - assertEquals(2, pws.getAllProgramAttributeTypes().size()); + assertEquals(3, pws.getAllProgramAttributeTypes().size()); } @Test @@ -744,11 +744,11 @@ public void shouldTestGetProgramAttributeTypeByUuid() throws Exception { @Test public void shouldTestSaveProgramAttributeType() throws Exception { - assertEquals(2,pws.getAllProgramAttributeTypes().size()); + assertEquals(3,pws.getAllProgramAttributeTypes().size()); ProgramAttributeType programAttributeType = new ProgramAttributeType(); programAttributeType.setName("test"); pws.saveProgramAttributeType(programAttributeType); - assertEquals(3,pws.getAllProgramAttributeTypes().size()); + assertEquals(4,pws.getAllProgramAttributeTypes().size()); } @Test From 3e219505aab833bb0f7c2cab414fa939ebb65d76 Mon Sep 17 00:00:00 2001 From: helderjosue Date: Mon, 25 Mar 2024 20:29:28 +0200 Subject: [PATCH 09/11] TRUNK-5068: correcting imports --- .../openmrs/api/ProgramWorkflowServiceTest.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index ced060ed4081..3be0792d9834 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -31,7 +31,20 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.openmrs.*; +import org.openmrs.Cohort; +import org.openmrs.Concept; +import org.openmrs.ConceptName; +import org.openmrs.ConceptStateConversion; +import org.openmrs.Encounter; +import org.openmrs.Patient; +import org.openmrs.PatientProgram; +import org.openmrs.PatientState; +import org.openmrs.Program; +import org.openmrs.ProgramAttributeType; +import org.openmrs.ProgramWorkflow; +import org.openmrs.ProgramWorkflowState; +import org.openmrs.User; +import org.openmrs.PatientProgramAttribute; import org.openmrs.api.context.Context; import org.openmrs.api.db.ProgramWorkflowDAO; import org.openmrs.api.impl.ProgramWorkflowServiceImpl; From 8740c3321f59abb2d0708c1cae6a043270d2265e Mon Sep 17 00:00:00 2001 From: helderjosue Date: Tue, 26 Mar 2024 00:20:40 +0200 Subject: [PATCH 10/11] TRUNK-5068: renaming test --- .../java/org/openmrs/api/ProgramWorkflowServiceTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index 3be0792d9834..43f79d595069 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -1108,7 +1108,7 @@ public void triggerStateConversion_shouldTestTransitionToState(){ * @see ProgramWorkflowService#getPatientProgramAttributeByUuid(String) */ @Test - public void getProgramAttributeType_shouldPass(){ + public void getProgramAttributeType_shouldReturnAttributeThatMatchesGivenUuid(){ PatientProgramAttribute patientProgramAttribute = pws.getPatientProgramAttributeByUuid("dd8793dc-e9d2-11ee-9b67-333dbdea27a2"); assertNotNull(patientProgramAttribute); @@ -1120,7 +1120,7 @@ public void getProgramAttributeType_shouldPass(){ * @see ProgramWorkflowService#getPatientProgramAttributeByAttributeName(List, String) */ @Test - public void getProgramAttributeByAttributeName_shouldPass(){ + public void getProgramAttributeByAttributeName_shouldReturnAttributeThatMatchesGivenName(){ Map results = pws.getPatientProgramAttributeByAttributeName( Collections.singletonList(2),"programName"); assertEquals(1,results.size()); @@ -1131,7 +1131,7 @@ public void getProgramAttributeByAttributeName_shouldPass(){ * @see ProgramWorkflowService#getPatientProgramByAttributeNameAndValue(String, String) */ @Test - public void getPatientProgramByAttributeNameAndValue_shouldPass(){ + public void getPatientProgramByAttributeNameAndValue_shouldReturnProgramsThatMatchesParameters(){ List patientPrograms = pws.getPatientProgramByAttributeNameAndValue("programName", "programReference"); From 596c5c71fa70112de01fefd74fe8cc63c6104b8c Mon Sep 17 00:00:00 2001 From: helderjosue Date: Wed, 27 Mar 2024 22:18:55 +0200 Subject: [PATCH 11/11] TRUNK-5068: removing javadocs for tests --- .../openmrs/api/ProgramWorkflowServiceTest.java | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java index 43f79d595069..9d81c0d21fba 100644 --- a/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java +++ b/api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java @@ -1102,11 +1102,7 @@ public void triggerStateConversion_shouldTestTransitionToState(){ assertEquals(patientProgram.getStates().size(), (patientStatesSize + 1)); } - /** - * Test to check the implementation of Patient Program Attribute Type by Uuid - * from Program Workflow Service - * @see ProgramWorkflowService#getPatientProgramAttributeByUuid(String) - */ + @Test public void getProgramAttributeType_shouldReturnAttributeThatMatchesGivenUuid(){ @@ -1115,21 +1111,14 @@ public void getProgramAttributeType_shouldReturnAttributeThatMatchesGivenUuid(){ assertEquals(2, patientProgramAttribute.getId()); } - /** - * Test to check the number of Patient Program attributes by given name - * @see ProgramWorkflowService#getPatientProgramAttributeByAttributeName(List, String) - */ + @Test public void getProgramAttributeByAttributeName_shouldReturnAttributeThatMatchesGivenName(){ Map results = pws.getPatientProgramAttributeByAttributeName( Collections.singletonList(2),"programName"); assertEquals(1,results.size()); } - - /** - * Test to get a patient Program by its Attribute Name and Value Reference - * @see ProgramWorkflowService#getPatientProgramByAttributeNameAndValue(String, String) - */ + @Test public void getPatientProgramByAttributeNameAndValue_shouldReturnProgramsThatMatchesParameters(){