Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public List<PatientProgram> getPatientProgramByAttributeNameAndValue(String attr
Query query;
try {
query = sessionFactory.getCurrentSession().createQuery(
"SELECT pp FROM patient_program pp " +
"SELECT pp FROM PatientProgram pp " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change also related to the ticket you were working on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because after my changes, some other tests were failing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this mean that it was some sort of bug that your tests exposed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No! for this particular case, my task was to implement tests for this method getPatientProgramByAttributeNameAndValue from ProgramWorkflowService class. But after implementing the test, I faced an error related to the table mappings patient_program pp is not mapped [select pp from ....
So I applied this changes to deal with the related issue.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still do not get it. If it was not a bug, why do you need to fix it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was, but not related to any code added by me. The sessionfactory query was there, but was not covered by the tests. once I wrote a test, the error came up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, that makes perfect sense. Thanks for the clarification. 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for your time.
I will be pushing the last changes (naming conventions) shortly

"INNER JOIN pp.attributes attr " +
"INNER JOIN attr.attributeType attr_type " +
"WHERE attr.valueReference = :attributeValue " +
Expand Down
39 changes: 35 additions & 4 deletions api/src/test/java/org/openmrs/api/ProgramWorkflowServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,6 +44,7 @@
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;
Expand All @@ -62,7 +65,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
Expand All @@ -82,6 +87,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();
Expand Down Expand Up @@ -733,7 +739,7 @@ public void purgeProgram_shouldPurgeProgramWithPatientsEnrolled() {
}
@Test
public void shouldTestGetAllProgramAttributeTypes() throws Exception {
assertEquals(1, pws.getAllProgramAttributeTypes().size());
assertEquals(3, pws.getAllProgramAttributeTypes().size());
}

@Test
Expand All @@ -751,11 +757,11 @@ public void shouldTestGetProgramAttributeTypeByUuid() throws Exception {

@Test
public void shouldTestSaveProgramAttributeType() throws Exception {
assertEquals(1,pws.getAllProgramAttributeTypes().size());
assertEquals(3,pws.getAllProgramAttributeTypes().size());
ProgramAttributeType programAttributeType = new ProgramAttributeType();
programAttributeType.setName("test");
pws.saveProgramAttributeType(programAttributeType);
assertEquals(2,pws.getAllProgramAttributeTypes().size());
assertEquals(4,pws.getAllProgramAttributeTypes().size());
}

@Test
Expand Down Expand Up @@ -1095,6 +1101,31 @@ public void triggerStateConversion_shouldTestTransitionToState(){
pwsi.triggerStateConversion(patient, trigger, dateConverted);
assertEquals(patientProgram.getStates().size(), (patientStatesSize + 1));
}


@Test
public void getProgramAttributeType_shouldReturnAttributeThatMatchesGivenUuid(){

PatientProgramAttribute patientProgramAttribute = pws.getPatientProgramAttributeByUuid("dd8793dc-e9d2-11ee-9b67-333dbdea27a2");
assertNotNull(patientProgramAttribute);
assertEquals(2, patientProgramAttribute.getId());
}


@Test
public void getProgramAttributeByAttributeName_shouldReturnAttributeThatMatchesGivenName(){
Map<Object, Object> results = pws.getPatientProgramAttributeByAttributeName(
Collections.singletonList(2),"programName");
assertEquals(1,results.size());
}

@Test
public void getPatientProgramByAttributeNameAndValue_shouldReturnProgramsThatMatchesParameters(){

List<PatientProgram> patientPrograms =
pws.getPatientProgramByAttributeNameAndValue("programName", "programReference");
assertEquals(1, patientPrograms.size());
}

// /**
// * This method should be uncommented when you want to examine the actual hibernate
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

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.

-->
<dataset>
<person person_id="2"
gender="M"
birthdate="1998-12-25"
birthdate_estimated="false"
dead="false"
creator="1"
date_created="2006-02-15 00:00:00.0"
voided="false"
uuid="6013a8cd-c6a0-4140-bfac-0af565704420"/>

<patient patient_id="2"
creator="1"
date_created="2016-05-15 00:00:00.0"
voided="false"/>

<patient_program patient_program_id="1"
patient_id="2"
program_id="1"
date_enrolled="2006-10-14 00:00:00.0"
creator="1"
date_created="2007-09-20 00:00:00.0"
voided="false"
uuid="9119b9f8-af3d-4ad8-9e2e-2317c3de91c6"/>

<patient_program_attribute
patient_program_attribute_id = "2"
patient_program_id = "1"
attribute_type_id = "3"
uuid = "dd8793dc-e9d2-11ee-9b67-333dbdea27a2"
creator="1"
date_created="2021-09-20 00:00:00.0"
voided="false"/>

<patient_program_attribute
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"
voided="false"/>

</dataset>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
<dataset>
<program_attribute_type program_attribute_type_id="1" name="ProgramId" min_occurs="1" retired="false"
creator="1" date_created="2008-08-15 17:04:50.0" datatype="org.openmrs.customdatatype.datatype.FreeTextDatatype"
uuid="d7477c21-bfc3-4922-9591-e89d8b9c8efb"/>
uuid="d7477c21-bfc3-4922-9591-e89d8b9c8efb"/>

<program_attribute_type program_attribute_type_id="2" name="programName" min_occurs="1" retired="false"
creator="1" date_created="2018-12-21 17:04:50.0" datatype="org.openmrs.customdatatype.datatype.FreeTextDatatype"
uuid="fac6fd36-e9da-11ee-a4c3-f3841c9b769b"/>

</dataset>
<program_attribute_type program_attribute_type_id="3" name="programName2" min_occurs="1" retired="false"
creator="1" date_created="2018-06-21 00:00:00.0" datatype="org.openmrs.customdatatype.datatype.FreeTextDatatype"
uuid="aaa000b0-eace-11ee-9194-8bb71c2b59e5"/>

</dataset>