Skip to content

Commit

Permalink
(test) patient dao tests
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-jofrancisco committed Jul 19, 2024
1 parent fa21503 commit 4c35de8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

import java.util.List;

import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.param.HasParam;
import org.hibernate.SessionFactory;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.Patient;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.TestFhirSpringConfiguration;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
Expand All @@ -30,19 +37,28 @@ public class FhirPatientDaoImplTest extends BaseModuleContextSensitiveTest {

private static final String BAD_PATIENT_UUID = "282390a6-3608-496d-9025-aecbc1235670";

private static final String GROUP_A = "dfb29c44-2e39-46c4-8cd7-18f21c6d47b1";

private static final String PATIENT_GROUP_A = "61b38324-e2fd-4feb-95b7-9e9a2a4400df";

private static final String[] PATIENT_SEARCH_DATA_FILES = {
"org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_initial_data.xml",
"org/openmrs/module/fhir2/api/dao/impl/FhirPatientDaoImplTest_address_data.xml" };

private FhirPatientDaoImpl dao;

private FhirGroupDaoImpl groupDao;

@Autowired
private SessionFactory sessionFactory;

@Before
public void setup() throws Exception {
groupDao = new FhirGroupDaoImpl();
groupDao.setSessionFactory(sessionFactory);
dao = new FhirPatientDaoImpl();
dao.setSessionFactory(sessionFactory);
dao.setGroupDao(groupDao);
for (String search_data : PATIENT_SEARCH_DATA_FILES) {
executeDataSet(search_data);
}
Expand Down Expand Up @@ -76,4 +92,16 @@ public void getPatientByUuid_shouldReturnNullIfPatientNotFound() {

assertThat(result, nullValue());
}

@Test
public void getSearchResults_shouldReturnPatientSearchResults() {
HasAndListParam groupParam = new HasAndListParam().addAnd(
new HasOrListParam().add(new HasParam(FhirConstants.GROUP, FhirConstants.INCLUDE_MEMBER_PARAM, "id", GROUP_A)));

SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.HAS_SEARCH_HANDLER, groupParam);
List<Patient> result = dao.getSearchResults(theParams);

assertThat(result, notNullValue());
assertThat(result.get(0).getUuid(), equalTo(PATIENT_GROUP_A));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
import org.openmrs.Concept;
import org.openmrs.ConceptDescription;
import org.openmrs.ConceptMap;
import org.openmrs.ConceptMapType;
import org.openmrs.ConceptName;
import org.openmrs.ConceptReferenceTerm;
import org.openmrs.ConceptSet;
import org.openmrs.ConceptSource;
import org.openmrs.ConceptMapType;
import org.openmrs.module.fhir2.FhirTestConstants;
import org.openmrs.module.fhir2.TestFhirSpringConfiguration;
import org.openmrs.module.fhir2.api.FhirConceptSourceService;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void shouldTranslateConceptSetToValueSet() {
ConceptMap conceptMap = mock(ConceptMap.class);
ConceptReferenceTerm conceptReferenceTerm = mock(ConceptReferenceTerm.class);
ConceptSource conceptSource = mock(ConceptSource.class);
ConceptMapType conceptMapType=mock(ConceptMapType.class);
ConceptMapType conceptMapType = mock(ConceptMapType.class);

when(conceptMap.getConceptReferenceTerm()).thenReturn(conceptReferenceTerm);
when(conceptMap.getConceptMapType()).thenReturn(conceptMapType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
Expand All @@ -48,10 +48,10 @@
import org.hl7.fhir.dstu3.model.Patient;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.Group;
import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.Group;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.StringOrListParam;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.param.TokenOrListParam;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.param.HasParam;
import ca.uhn.fhir.rest.param.HasAndListParam;
import ca.uhn.fhir.rest.param.HasOrListParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.model.Enumerations;
import org.hl7.fhir.r4.model.Group;
import org.hl7.fhir.r4.model.HumanName;
import org.hl7.fhir.r4.model.IdType;
import org.hl7.fhir.r4.model.Observation;
import org.hl7.fhir.r4.model.Group;
import org.hl7.fhir.r4.model.Reference;
import org.hl7.fhir.r4.model.OperationOutcome;
import org.hl7.fhir.r4.model.Patient;
import org.hl7.fhir.r4.model.Reference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@
<patient_identifier patient_identifier_id="4" patient_id="4" identifier="5634-1" identifier_type="1" preferred="1" location_id="1" creator="1" date_created="2005-01-01 00:00:00.0" voided="true" uuid="e1bcf220-d116-4d98-93a4-2adf6282f797"/>
<patient_identifier patient_identifier_id="5" patient_id="5" identifier="563422-5" identifier_type="1" preferred="1" location_id="1" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="f4798e60-b9ef-47d8-afa7-54a1dc9e27c1"/>
<patient_identifier patient_identifier_id="6" patient_id="6" identifier="47622-6" identifier_type="1" preferred="1" location_id="1" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="86e0b6d5-0f4f-4acd-8c81-edeb985c0ab3"/>
<cohort cohort_id="1" name="Group A" description="Patients from Group A" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="dfb29c44-2e39-46c4-8cd7-18f21c6d47b1"/>
<cohort_member cohort_member_id="1" cohort_id="1" patient_id="2" start_date="2000-04-16" end_date="2030-04-16" creator="1" date_created="2005-01-01 00:00:00.0" voided="false" uuid="1cf0dc57-ddc2-4f28-8e71-faf30bf2d923"/>
</dataset>

0 comments on commit 4c35de8

Please sign in to comment.