Search in sources :

Example 76 with org.hl7.fhir.r5.model

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

the class FhirConditionServiceImplTest method create_shouldCreateNewCondition.

@Test
public void create_shouldCreateNewCondition() {
    when(translator.toFhirResource(obsCondition)).thenReturn(condition);
    when(dao.createOrUpdate(obsCondition)).thenReturn(obsCondition);
    when(translator.toOpenmrsType(condition)).thenReturn(obsCondition);
    org.hl7.fhir.r4.model.Condition result = fhirConditionService.create(condition);
    assertThat(result, notNullValue());
    assertThat(result.getId(), notNullValue());
    assertThat(result.getId(), equalTo(OBS_UUID));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Test(org.junit.Test)

Example 77 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model 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 78 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model 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 79 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model 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 80 with org.hl7.fhir.r5.model

use of org.hl7.fhir.r5.model 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)

Aggregations

Test (org.junit.jupiter.api.Test)435 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)334 Test (org.junit.Test)289 ArrayList (java.util.ArrayList)112 FHIRException (org.hl7.fhir.exceptions.FHIRException)111 IOException (java.io.IOException)84 List (java.util.List)73 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)70 Date (java.util.Date)68 FileOutputStream (java.io.FileOutputStream)66 File (java.io.File)61 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)61 CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 InputStream (java.io.InputStream)55 TableModel (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.TableModel)51 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 Bundle (org.hl7.fhir.dstu3.model.Bundle)49 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)48 Collectors (java.util.stream.Collectors)48 Arrays (java.util.Arrays)46