Search in sources :

Example 56 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationSearchQueryTest method searchForObs_shouldSortObsAsRequested.

@Test
public void searchForObs_shouldSortObsAsRequested() {
    SortSpec sort = new SortSpec();
    sort.setParamName("date");
    sort.setOrder(SortOrderEnum.ASC);
    SearchParameterMap theParams = new SearchParameterMap();
    theParams.setSortSpec(sort);
    IBundleProvider results = search(theParams);
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThan(1)));
    for (int i = 1; i < resultList.size(); i++) {
        assertThat(((Observation) resultList.get(i - 1)).getEffectiveDateTimeType().getValue(), sameOrBefore(((Observation) resultList.get(i)).getEffectiveDateTimeType().getValue()));
    }
    sort.setOrder(SortOrderEnum.DESC);
    theParams.setSortSpec(sort);
    results = search(theParams);
    resultList = get(results);
    assertThat(results, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThan(1)));
    for (int i = 1; i < resultList.size(); i++) {
        assertThat(((Observation) resultList.get(i - 1)).getEffectiveDateTimeType().getValue(), sameOrAfter(((Observation) resultList.get(i)).getEffectiveDateTimeType().getValue()));
    }
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SortSpec(ca.uhn.fhir.rest.api.SortSpec) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 57 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationSearchQueryTest method searchForObs_shouldAddNotNullGroupMembersToReturnedResultsR3.

@Test
public void searchForObs_shouldAddNotNullGroupMembersToReturnedResultsR3() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(OBS_GROUP_UUID));
    HashSet<Include> includes = new HashSet<>();
    Include include = new Include("Observation:related-type");
    includes.add(include);
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.INCLUDE_SEARCH_HANDLER, includes);
    IBundleProvider results = search(theParams);
    assertThat(results.size(), equalTo(1));
    List<IBaseResource> resultList = get(results);
    assertThat(results, notNullValue());
    // included resource added as part of the result list
    assertThat(resultList.size(), equalTo(2));
    Observation returnedObservation = (Observation) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Observation.class)), hasProperty("id", equalTo(returnedObservation.getHasMemberFirstRep().getReferenceElement().getIdPart())))));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) Observation(org.hl7.fhir.r4.model.Observation) Include(ca.uhn.fhir.model.api.Include) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 58 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationSearchQueryTest method searchForObs_shouldSearchForObsByValueDate.

@Test
public void searchForObs_shouldSearchForObsByValueDate() {
    SearchParameterMap theParams = new SearchParameterMap();
    theParams.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "valueDatetime", new DateRangeParam(new DateParam(VALUE_DATE)));
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    List<IBaseResource> resultList = get(results);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(OBS_VALUE_CONCEPT_UUID))));
    assertThat(((Observation) resultList.get(0)).getIssued().toString(), startsWith(VALUE_DATE));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) Observation(org.hl7.fhir.r4.model.Observation) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) DateParam(ca.uhn.fhir.rest.param.DateParam) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 59 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class ObservationSearchQueryTest method searchForObs_shouldSearchByObsDateAndTime.

@Test
public void searchForObs_shouldSearchByObsDateAndTime() {
    SearchParameterMap theParams = new SearchParameterMap();
    theParams.addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "obsDatetime", new DateRangeParam(new DateParam(OBS_DATE_AND_TIME)));
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(12));
    List<IBaseResource> resultList = get(results);
    assertThat(resultList, not(empty()));
    assertThat(resultList.size(), equalTo(10));
    assertThat(resultList, hasItem(hasProperty("id", equalTo(OBS_VALUE_CONCEPT_UUID))));
    assertThat(((Observation) resultList.get(0)).getEffectiveDateTimeType().getValue().toString(), equalTo(EXPECTED_OBS_DATE_AND_TIME));
}
Also used : DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) DateParam(ca.uhn.fhir.rest.param.DateParam) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 60 with Observation

use of org.hl7.fhir.r4.model.Observation in project openmrs-module-fhir2 by openmrs.

the class DiagnosticReportTranslatorImplTest method setup.

@Before
public void setup() {
    translator = new DiagnosticReportTranslatorImpl();
    translator.setObservationReferenceTranslator(observationReferenceTranslator);
    translator.setConceptTranslator(conceptTranslator);
    translator.setEncounterReferenceTranslator(encounterReferenceTranslator);
    translator.setPatientReferenceTranslator(patientReferenceTranslator);
    // OpenMRS setup
    fhirDiagnosticReport = new FhirDiagnosticReport();
    Obs childObs = new Obs();
    childObs.setUuid(CHILD_UUID);
    fhirDiagnosticReport.setUuid(PARENT_UUID);
    fhirDiagnosticReport.getResults().add(childObs);
    // FHIR setup
    Reference obsReference = new Reference().setType("Observation").setReference("Observation/" + CHILD_UUID);
    diagnosticReport = new DiagnosticReport();
    diagnosticReport.setId(PARENT_UUID);
    diagnosticReport.addResult(obsReference);
    // Mocks for DiagnosticReport.result
    when(observationReferenceTranslator.toFhirResource(childObs)).thenReturn(obsReference);
    when(observationReferenceTranslator.toOpenmrsType(obsReference)).thenReturn(childObs);
}
Also used : Obs(org.openmrs.Obs) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) Reference(org.hl7.fhir.r4.model.Reference) DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) Before(org.junit.Before)

Aggregations

Observation (org.hl7.fhir.r4.model.Observation)237 Test (org.junit.Test)235 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)114 Test (org.junit.jupiter.api.Test)107 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)106 Observation (org.hl7.fhir.dstu3.model.Observation)94 Bundle (org.hl7.fhir.r4.model.Bundle)88 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)64 ArrayList (java.util.ArrayList)62 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)59 Resource (org.hl7.fhir.r4.model.Resource)55 Bundle (org.hl7.fhir.dstu3.model.Bundle)53 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)47 Coding (org.hl7.fhir.r4.model.Coding)46 Reference (org.hl7.fhir.r4.model.Reference)41 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)37 TokenParam (ca.uhn.fhir.rest.param.TokenParam)37 Date (java.util.Date)34 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)32 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)32