Search in sources :

Example 96 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project openmrs-module-fhir2 by openmrs.

the class ConditionTranslatorImpl_2_2Test method shouldTranslateConditionConceptToFhirType.

@Test
public void shouldTranslateConditionConceptToFhirType() {
    Concept concept = new Concept();
    concept.setUuid(CONCEPT_UUID);
    concept.setConceptId(CODE);
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding coding = new Coding();
    coding.setCode(CODE.toString());
    coding.setSystem(SYSTEM);
    codeableConcept.addCoding(coding);
    CodedOrFreeText conceptCodeOrFreeText = new CodedOrFreeText();
    conceptCodeOrFreeText.setCoded(concept);
    openmrsCondition.setCondition(conceptCodeOrFreeText);
    when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept);
    org.hl7.fhir.r4.model.Condition condition = conditionTranslator.toFhirResource(openmrsCondition);
    assertThat(condition, notNullValue());
    assertThat(condition.getCode(), notNullValue());
    assertThat(condition.getCode().getCoding(), not(Collections.emptyList()));
    assertThat(condition.getCode().getCoding().get(0).getCode(), equalTo(CODE.toString()));
    assertThat(condition.getCode().getCoding().get(0).getSystem(), equalTo(SYSTEM));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Coding(org.hl7.fhir.r4.model.Coding) Condition(org.hl7.fhir.r4.model.Condition) CodedOrFreeText(org.openmrs.CodedOrFreeText) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 97 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project openmrs-module-fhir2 by openmrs.

the class ObservationFhirResourceProviderIntegrationTest method shouldReturnExistingObservationAsJson.

@Test
public void shouldReturnExistingObservationAsJson() throws Exception {
    MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Observation observation = readResponse(response);
    assertThat(observation, notNullValue());
    assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID));
    // verify expected codings
    assertThat(observation.getCode().getCoding(), hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID)))));
    assertThat(observation.getCode().getCoding(), hasItem(allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URI)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID)))));
    assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME));
    // verify expected value
    assertThat(observation.getValueQuantity(), notNullValue());
    assertThat(observation.getValueQuantity().getValue(), equalTo(OBS_CONCEPT_VALUE));
    // verify reference ranges
    assertThat(observation.getReferenceRange(), notNullValue());
    assertThat(observation.getReferenceRange(), not(empty()));
    assertThat(observation.getReferenceRange(), hasItem(hasProperty("low", hasProperty("value", equalTo(OBS_LOW_REFERENCE_RANGE)))));
    assertThat(observation.getReferenceRange(), hasItem(hasProperty("high", hasProperty("value", equalTo(OBS_HIGH_REFERENCE_RANGE)))));
    // verify expected patient
    assertThat(observation.getSubject(), notNullValue());
    assertThat(observation.getSubject().getReference(), containsString("Patient/"));
    assertThat(observation.getSubject().getReference(), endsWith("/" + OBS_PATIENT_UUID));
    // verify expected encounter
    assertThat(observation.getContext(), notNullValue());
    assertThat(observation.getContext().getReference(), endsWith("/" + OBS_ENCOUNTER_UUID));
    assertThat(observation, validResource());
}
Also used : Observation(org.hl7.fhir.dstu3.model.Observation) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 98 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project openmrs-module-fhir2 by openmrs.

the class ObservationFhirResourceProviderIntegrationTest method shouldReturnExistingObservationAsXML.

@Test
public void shouldReturnExistingObservationAsXML() throws Exception {
    MockHttpServletResponse response = get("/Observation/" + OBS_UUID).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Observation observation = readResponse(response);
    assertThat(observation, notNullValue());
    assertThat(observation.getIdElement().getIdPart(), equalTo(OBS_UUID));
    // verify expected codings
    assertThat(observation.getCode().getCoding(), hasItem(allOf(hasProperty("system", nullValue()), hasProperty("code", equalTo(OBS_CONCEPT_UUID)))));
    assertThat(observation.getCode().getCoding(), hasItem(allOf(hasProperty("system", equalTo(CIEL_SYSTEM_URN)), hasProperty("code", equalTo(OBS_CONCEPT_CIEL_ID)))));
    assertThat(observation.getCode().getCodingFirstRep().getDisplay(), equalTo(OBS_CONCEPT_DISPLAY_NAME));
    // verify expected value
    assertThat(observation.getValueQuantity(), notNullValue());
    assertThat(observation.getValueQuantity().getValue(), equalTo(OBS_CONCEPT_VALUE));
    // verify reference ranges
    assertThat(observation.getReferenceRange(), notNullValue());
    assertThat(observation.getReferenceRange(), not(empty()));
    assertThat(observation.getReferenceRange(), hasItem(hasProperty("low", hasProperty("value", equalTo(OBS_LOW_REFERENCE_RANGE)))));
    assertThat(observation.getReferenceRange(), hasItem(hasProperty("high", hasProperty("value", equalTo(OBS_HIGH_REFERENCE_RANGE)))));
    // verify expected patient
    assertThat(observation.getSubject(), notNullValue());
    assertThat(observation.getSubject().getType(), equalTo("Patient"));
    assertThat(observation.getSubject().getReference(), endsWith("/" + OBS_PATIENT_UUID));
    // verify expected encounter
    assertThat(observation.getEncounter(), notNullValue());
    assertThat(observation.getEncounter().getReference(), endsWith("/" + OBS_ENCOUNTER_UUID));
    assertThat(observation, validResource());
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 99 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project Gravity-SDOH-Exchange-RI by FHIR.

the class OrganizationToDtoConverter method convert.

@Override
public OrganizationDto convert(Organization org) {
    String orgId = org.getIdElement().getIdPart();
    OrganizationDto orgDto = new OrganizationDto(orgId);
    orgDto.setName(org.getName());
    // We are interested only in CBO/CP types. Other are ignored.
    Coding coding = FhirUtil.findCoding(org.getType(), OrganizationTypeCode.SYSTEM);
    if (coding == null) {
        orgDto.getErrors().add(String.format("Organization with id '%s' has no coding with system '%s' within a 'type' property. Such organizations " + "are " + "not expected in this context.", orgId, OrganizationTypeCode.SYSTEM));
    } else {
        try {
            orgDto.setType(OrganizationTypeCode.fromCode(coding.getCode()));
        } catch (FHIRException exc) {
            orgDto.getErrors().add(String.format("OrganizationTypeCode code '%s' cannot be resolved for Organization with id '%s'.", coding.getCode(), orgId));
        }
    }
    return orgDto;
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) FHIRException(org.hl7.fhir.exceptions.FHIRException) OrganizationDto(org.hl7.gravity.refimpl.sdohexchange.dto.response.OrganizationDto)

Example 100 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project Gravity-SDOH-Exchange-RI by FHIR.

the class TaskValidator method validate.

public List<String> validate(Task task) {
    List<String> errors = new ArrayList<>();
    if (task.hasIdentifier() && task.getIdentifier().size() != 1) {
        errors.add("Task.identifier is not valid.");
    }
    if (!task.getIntent().equals(Task.TaskIntent.ORDER)) {
        errors.add(String.format("Task.intent has wrong value. Supported value is '%s'.", Task.TaskIntent.ORDER.toCode()));
    }
    TaskCode taskCode = TaskCode.FULFILL;
    if (task.getCode().getCoding().stream().noneMatch(coding -> taskCode.getSystem().equals(coding.getSystem()) && taskCode.toCode().equals(coding.getCode()) && taskCode.getDisplay().equals(coding.getDisplay()))) {
        errors.add(String.format("Task.code has no coding with system '%s' and code '%s'.", taskCode.getSystem(), taskCode.toCode()));
    }
    if (!task.hasFocus()) {
        errors.add("Task.focus is missing.");
    }
    if (!task.hasFor()) {
        errors.add("Task.for is missing.");
    }
    if (task.hasFor() && !task.getFor().getReferenceElement().getResourceType().equals(Patient.class.getSimpleName())) {
        errors.add(String.format("Task.for reference is invalid. Supported reference is '%s'.", Patient.class.getSimpleName()));
    }
    if (task.hasRequester() && !task.getRequester().getReferenceElement().getResourceType().equals(Organization.class.getSimpleName())) {
        errors.add(String.format("Task.requester reference is invalid. Supported reference is '%s'.", Organization.class.getSimpleName()));
    }
    if (task.hasOwner() && !task.getOwner().getReferenceElement().getResourceType().equals(Organization.class.getSimpleName())) {
        errors.add(String.format("Task.owner reference is invalid. Supported reference is '%s'.", Organization.class.getSimpleName()));
    }
    return errors;
}
Also used : TaskCode(org.hl7.fhir.r4.model.codesystems.TaskCode) Organization(org.hl7.fhir.r4.model.Organization) ArrayList(java.util.ArrayList) Patient(org.hl7.fhir.r4.model.Patient)

Aggregations

Test (org.junit.jupiter.api.Test)92 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)75 ArrayList (java.util.ArrayList)70 Coding (org.hl7.fhir.r4.model.Coding)70 Identifier (org.hl7.fhir.r4.model.Identifier)62 FHIRException (org.hl7.fhir.exceptions.FHIRException)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)45 Resource (org.hl7.fhir.r4.model.Resource)45 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 Test (org.junit.Test)37 Coding (org.hl7.fhir.dstu3.model.Coding)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 HashMap (java.util.HashMap)30 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)28 List (java.util.List)27 IOException (java.io.IOException)26 Bundle (org.hl7.fhir.r4.model.Bundle)26 Patient (org.hl7.fhir.r4.model.Patient)25 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21