Search in sources :

Example 61 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class FhirConditionServiceImplTest method searchConditions_shouldReturnTranslatedConditionReturnedByDao.

@Test
public void searchConditions_shouldReturnTranslatedConditionReturnedByDao() {
    ReferenceAndListParam patientReference = new ReferenceAndListParam();
    patientReference.addValue(new ReferenceOrListParam().add(new ReferenceParam(org.hl7.fhir.r4.model.Patient.SP_GIVEN, "patient name")));
    TokenAndListParam codeList = new TokenAndListParam();
    codeList.addValue(new TokenOrListParam().add(new TokenParam("test code")));
    TokenAndListParam clinicalList = new TokenAndListParam();
    clinicalList.addValue(new TokenOrListParam().add(new TokenParam("test clinical")));
    DateRangeParam onsetDate = new DateRangeParam().setLowerBound("gt2020-05-01").setUpperBound("lt2021-05-01");
    QuantityAndListParam onsetAge = new QuantityAndListParam();
    onsetAge.addValue(new QuantityOrListParam().add(new QuantityParam(12)));
    DateRangeParam recordDate = new DateRangeParam().setLowerBound("gt2020-05-01").setUpperBound("lt2021-05-01");
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(OBS_UUID));
    DateRangeParam lastUpdated = new DateRangeParam().setLowerBound(LAST_UPDATED_DATE).setUpperBound(LAST_UPDATED_DATE);
    SortSpec sort = new SortSpec("sort param");
    HashSet<Include> includes = new HashSet<>();
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.PATIENT_REFERENCE_SEARCH_HANDLER, patientReference).addParameter(FhirConstants.CODED_SEARCH_HANDLER, codeList).addParameter(FhirConstants.QUANTITY_SEARCH_HANDLER, onsetAge).addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "onsetDate", onsetDate).addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "dateCreated", recordDate).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.ID_PROPERTY, uuid).addParameter(FhirConstants.COMMON_SEARCH_HANDLER, FhirConstants.LAST_UPDATED_PROPERTY, lastUpdated).setSortSpec(sort);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obsCondition));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(translator.toFhirResource(obsCondition)).thenReturn(condition);
    IBundleProvider result = fhirConditionService.searchConditions(patientReference, codeList, clinicalList, onsetDate, onsetAge, recordDate, uuid, lastUpdated, sort, includes);
    List<IBaseResource> resultList = get(result);
    assertThat(result, notNullValue());
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(greaterThanOrEqualTo(1)));
}
Also used : QuantityOrListParam(ca.uhn.fhir.rest.param.QuantityOrListParam) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) SearchQueryInclude(org.openmrs.module.fhir2.api.search.SearchQueryInclude) Include(ca.uhn.fhir.model.api.Include) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) QuantityAndListParam(ca.uhn.fhir.rest.param.QuantityAndListParam) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) TokenOrListParam(ca.uhn.fhir.rest.param.TokenOrListParam) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) QuantityParam(ca.uhn.fhir.rest.param.QuantityParam) SortSpec(ca.uhn.fhir.rest.api.SortSpec) HashSet(java.util.HashSet) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Example 62 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class FhirEncounterServiceImplTest method create_shouldCreateEncounterFromOpenMrsVisit.

@Test
public void create_shouldCreateEncounterFromOpenMrsVisit() {
    CodeableConcept codeableConcept = new CodeableConcept();
    codeableConcept.addCoding().setSystem(FhirConstants.VISIT_TYPE_SYSTEM_URI).setCode("1");
    fhirEncounter.setType(Collections.singletonList(codeableConcept));
    when(visitService.create(fhirEncounter)).thenReturn(fhirEncounter);
    org.hl7.fhir.r4.model.Encounter result = encounterService.create(fhirEncounter);
    assertThat(result, notNullValue());
    assertThat(result.getId(), equalTo(ENCOUNTER_UUID));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 63 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class FhirLocationServiceImplTest method getLocationByUuid_shouldGetLocationByUuid.

@Test
public void getLocationByUuid_shouldGetLocationByUuid() {
    when(locationDao.get(LOCATION_UUID)).thenReturn(location);
    when(locationTranslator.toFhirResource(location)).thenReturn(fhirLocation);
    org.hl7.fhir.r4.model.Location result = fhirLocationService.get(LOCATION_UUID);
    assertThat(result, notNullValue());
    assertThat(result.getId(), equalTo(LOCATION_UUID));
    assertThat(result.getName(), equalTo(LOCATION_NAME));
    assertThat(result.getDescription(), equalTo(LOCATION_DESCRIPTION));
}
Also used : Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Example 64 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class TaskVersionConverter method convertTask.

public static org.hl7.fhir.dstu3.model.Task convertTask(org.hl7.fhir.r4.model.Task src) throws FHIRException {
    org.hl7.fhir.dstu3.model.Task tgt = new org.hl7.fhir.dstu3.model.Task();
    VersionConvertor_30_40.copyDomainResource(src, tgt);
    for (org.hl7.fhir.r4.model.Identifier t : src.getIdentifier()) {
        tgt.addIdentifier(VersionConvertor_30_40.convertIdentifier(t));
    }
    // TODO: check
    if (src.hasInstantiatesUri()) {
        tgt.setDefinition(VersionConvertor_30_40.convertType(src.getInstantiatesUriElement()));
    }
    // TODO: check
    if (src.hasInstantiatesCanonical()) {
        tgt.setDefinition(VersionConvertor_30_40.convertType(src.getInstantiatesCanonicalElement()));
    }
    if (src.hasBasedOn()) {
        for (org.hl7.fhir.r4.model.Reference t : src.getBasedOn()) {
            tgt.addBasedOn(VersionConvertor_30_40.convertReference(t));
        }
    }
    if (src.hasGroupIdentifier()) {
        tgt.setGroupIdentifier(VersionConvertor_30_40.convertIdentifier(src.getGroupIdentifier()));
    }
    if (src.hasPartOf()) {
        for (org.hl7.fhir.r4.model.Reference t : src.getPartOf()) {
            tgt.addPartOf(VersionConvertor_30_40.convertReference(t));
        }
    }
    if (src.hasStatus()) {
        tgt.setStatusElement(convertTaskStatus(src.getStatusElement()));
    }
    if (src.hasStatusReason()) {
        tgt.setStatusReason(VersionConvertor_30_40.convertCodeableConcept(src.getStatusReason()));
    }
    if (src.hasBusinessStatus()) {
        tgt.setBusinessStatus(VersionConvertor_30_40.convertCodeableConcept(src.getBusinessStatus()));
    }
    if (src.hasIntent()) {
        tgt.setIntentElement(convertTaskIntent(src.getIntentElement()));
    }
    if (src.hasPriority()) {
        tgt.setPriorityElement(convertProcedureRequestPriority(src.getPriorityElement()));
    }
    if (src.hasCode()) {
        tgt.setCode(VersionConvertor_30_40.convertCodeableConcept(src.getCode()));
    }
    if (src.hasDescription()) {
        tgt.setDescriptionElement(VersionConvertor_30_40.convertString(src.getDescriptionElement()));
    }
    if (src.hasFocus()) {
        tgt.setFocus(VersionConvertor_30_40.convertReference(src.getFocus()));
    }
    if (src.hasFor()) {
        tgt.setFor(VersionConvertor_30_40.convertReference(src.getFor()));
    }
    if (src.hasEncounter()) {
        tgt.setContext(VersionConvertor_30_40.convertReference(src.getEncounter()));
    }
    if (src.hasExecutionPeriod()) {
        tgt.setExecutionPeriod(VersionConvertor_30_40.convertPeriod(src.getExecutionPeriod()));
    }
    if (src.hasAuthoredOn()) {
        tgt.setAuthoredOnElement(VersionConvertor_30_40.convertDateTime(src.getAuthoredOnElement()));
    }
    if (src.hasLastModified()) {
        tgt.setLastModifiedElement(VersionConvertor_30_40.convertDateTime(src.getLastModifiedElement()));
    }
    if (src.hasRequester()) {
        tgt.getRequester().setAgent(VersionConvertor_30_40.convertReference(src.getRequester()));
    }
    if (src.hasPerformerType()) {
        for (org.hl7.fhir.r4.model.CodeableConcept t : src.getPerformerType()) tgt.addPerformerType(VersionConvertor_30_40.convertCodeableConcept(t));
    }
    if (src.hasOwner()) {
        tgt.setOwner(VersionConvertor_30_40.convertReference(src.getOwner()));
    }
    if (src.hasReasonCode()) {
        tgt.setReason(VersionConvertor_30_40.convertCodeableConcept(src.getReasonCode()));
    }
    if (src.hasNote()) {
        for (org.hl7.fhir.r4.model.Annotation t : src.getNote()) tgt.addNote(VersionConvertor_30_40.convertAnnotation(t));
    }
    if (src.hasRelevantHistory()) {
        for (org.hl7.fhir.r4.model.Reference t : src.getRelevantHistory()) tgt.addRelevantHistory(VersionConvertor_30_40.convertReference(t));
    }
    if (src.hasRestriction()) {
        tgt.setRestriction(convertTaskRestriction(src.getRestriction(), tgt.getRestriction()));
    }
    if (src.hasInput()) {
        convertTaskInput(src, tgt);
    }
    if (src.hasOutput()) {
        convertTaskOutput(src, tgt);
    }
    return tgt;
}
Also used : Task(org.hl7.fhir.dstu3.model.Task) Task(org.hl7.fhir.dstu3.model.Task)

Example 65 with org.hl7.fhir.r5.utils.validation

use of org.hl7.fhir.r5.utils.validation in project openmrs-module-fhir2 by openmrs.

the class PersonSearchQueryTest method shouldAddPersonLinksToResultListWhenIncluded.

@Test
public void shouldAddPersonLinksToResultListWhenIncluded() {
    TokenAndListParam uuid = new TokenAndListParam().addAnd(new TokenParam(PERSON_UUID));
    HashSet<Include> includes = new HashSet<>();
    includes.add(new Include("Person:link:Patient"));
    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, notNullValue());
    assertThat(results.size(), equalTo(1));
    List<IBaseResource> resultList = results.getResources(START_INDEX, END_INDEX);
    assertThat(resultList, not(empty()));
    // included resource added as part of the result list
    assertThat(resultList.size(), equalTo(2));
    assertThat(((org.hl7.fhir.r4.model.Person) resultList.iterator().next()).getIdElement().getIdPart(), equalTo(PERSON_UUID));
    org.hl7.fhir.r4.model.Person returnedPerson = (org.hl7.fhir.r4.model.Person) resultList.iterator().next();
    assertThat(resultList, hasItem(allOf(is(instanceOf(Patient.class)), hasProperty("id", equalTo(returnedPerson.getLinkFirstRep().getTarget().getReferenceElement().getIdPart())))));
}
Also used : Include(ca.uhn.fhir.model.api.Include) TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) Person(org.hl7.fhir.r4.model.Person) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Person(org.hl7.fhir.r4.model.Person) 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)

Aggregations

Test (org.junit.jupiter.api.Test)427 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)241 FHIRException (org.hl7.fhir.exceptions.FHIRException)104 ArrayList (java.util.ArrayList)101 IOException (java.io.IOException)78 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)65 List (java.util.List)64 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 FileOutputStream (java.io.FileOutputStream)59 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 File (java.io.File)57 InputStream (java.io.InputStream)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Bundle (org.hl7.fhir.dstu3.model.Bundle)48 MethodSource (org.junit.jupiter.params.provider.MethodSource)46 Arrays (java.util.Arrays)45 Collectors (java.util.stream.Collectors)45