Search in sources :

Example 16 with BooleanType

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

the class ObservationValueTranslatorImplTest method toFhirResource_shouldConvertObsWithBooleanValueToBoolean.

@Test
public void toFhirResource_shouldConvertObsWithBooleanValueToBoolean() {
    mockStatic(Context.class);
    Concept trueConcept = new Concept();
    trueConcept.setId(1046);
    ConceptService conceptService = mock(ConceptService.class);
    when(Context.getConceptService()).thenReturn(conceptService);
    when(conceptService.getTrueConcept()).thenReturn(trueConcept);
    ConceptDatatype booleanDatatype = mock(ConceptDatatype.class);
    when(booleanDatatype.isBoolean()).thenReturn(true);
    Concept obsConcept = new Concept();
    obsConcept.setDatatype(booleanDatatype);
    obs.setConcept(obsConcept);
    obs.setValueBoolean(true);
    Type result = obsValueTranslator.toFhirResource(obs);
    assertThat(result, notNullValue());
    assertThat(result, instanceOf(BooleanType.class));
    assertThat(((BooleanType) result).booleanValue(), is(true));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) StringType(org.hl7.fhir.r4.model.StringType) IntegerType(org.hl7.fhir.r4.model.IntegerType) BooleanType(org.hl7.fhir.r4.model.BooleanType) BooleanType(org.hl7.fhir.r4.model.BooleanType) ConceptService(org.openmrs.api.ConceptService) ConceptDatatype(org.openmrs.ConceptDatatype) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 17 with BooleanType

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

the class PatientTranslatorImplTest method shouldTranslateDeceasedPatientToDeceased.

@Test
public void shouldTranslateDeceasedPatientToDeceased() {
    Patient patient = new Patient();
    patient.setDeceased(new BooleanType(true));
    assertThat(patientTranslator.toOpenmrsType(patient).getDead(), is(true));
}
Also used : BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) Test(org.junit.Test)

Example 18 with BooleanType

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

the class PatientTranslatorImpl method toFhirResource.

@Override
public Patient toFhirResource(@Nonnull org.openmrs.Patient openmrsPatient) {
    notNull(openmrsPatient, "The Openmrs Patient object should not be null");
    Patient patient = new Patient();
    patient.setId(openmrsPatient.getUuid());
    patient.setActive(!openmrsPatient.getVoided());
    for (PatientIdentifier identifier : openmrsPatient.getActiveIdentifiers()) {
        patient.addIdentifier(identifierTranslator.toFhirResource(identifier));
    }
    for (PersonName name : openmrsPatient.getNames()) {
        patient.addName(nameTranslator.toFhirResource(name));
    }
    if (openmrsPatient.getGender() != null) {
        patient.setGender(genderTranslator.toFhirResource(openmrsPatient.getGender()));
    }
    patient.setBirthDateElement(birthDateTranslator.toFhirResource(openmrsPatient));
    if (openmrsPatient.getDead()) {
        if (openmrsPatient.getDeathDate() != null) {
            patient.setDeceased(new DateTimeType(openmrsPatient.getDeathDate()));
        } else {
            patient.setDeceased(new BooleanType(true));
        }
    } else {
        patient.setDeceased(new BooleanType(false));
    }
    for (PersonAddress address : openmrsPatient.getAddresses()) {
        patient.addAddress(addressTranslator.toFhirResource(address));
    }
    patient.setTelecom(getPatientContactDetails(openmrsPatient));
    patient.getMeta().setLastUpdated(openmrsPatient.getDateChanged());
    patient.addContained(provenanceTranslator.getCreateProvenance(openmrsPatient));
    patient.addContained(provenanceTranslator.getUpdateProvenance(openmrsPatient));
    return patient;
}
Also used : PersonName(org.openmrs.PersonName) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) PersonAddress(org.openmrs.PersonAddress) BooleanType(org.hl7.fhir.r4.model.BooleanType) Patient(org.hl7.fhir.r4.model.Patient) PatientIdentifier(org.openmrs.PatientIdentifier)

Example 19 with BooleanType

use of org.hl7.fhir.r4b.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class ICD11Generator method processMMSEntity.

private void processMMSEntity(CodeSystem cs, String base, String ref, org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent cc, String dest) throws IOException {
    System.out.print(".");
    JsonObject entity = fetchJson(url(base, ref));
    cc.setId(tail(ref));
    if (entity.has("code") && !Utilities.noString(entity.get("code").getAsString())) {
        cc.setCode(entity.get("code").getAsString());
    } else if (entity.has("blockId") && !Utilities.noString(entity.get("blockId").getAsString())) {
        cc.setCode(entity.get("blockId").getAsString());
    } else {
        cc.setCode(cc.getId());
        cc.addProperty().setCode("abstract").setValue(new BooleanType(true));
    }
    if (entity.has("classKind") && !Utilities.noString(entity.get("classKind").getAsString()) && !"category".equals(entity.get("classKind").getAsString())) {
        cc.addProperty().setCode("kind").setValue(new CodeType(entity.get("classKind").getAsString()));
    }
    cc.setDisplay(readString(entity, "title"));
    StringBuilder defn = new StringBuilder();
    String d = readString(entity, "definition");
    if (d != null) {
        defn.append(d);
    }
    if (d == null && (entity.has("inclusion") || entity.has("exclusion"))) {
        defn.append(cc.getDisplay());
    }
    if (entity.has("inclusion")) {
        defn.append(". Includes: ");
        boolean first = true;
        for (JsonElement child : entity.getAsJsonArray("inclusion")) {
            if (first)
                first = false;
            else
                defn.append(", ");
            defn.append(readString((JsonObject) child, "label"));
        }
    }
    if (entity.has("exclusion")) {
        defn.append(". Excludes: ");
        boolean first = true;
        for (JsonElement child : entity.getAsJsonArray("exclusion")) {
            if (first)
                first = false;
            else
                defn.append(", ");
            JsonObject co = (JsonObject) child;
            String v = readString(co, "label");
            if (v != null) {
                defn.append(v);
                if (co.has("linearizationReference")) {
                    cc.addProperty().setValue(new Coding().setSystem("http://id.who.int/icd11/mms").setCode(tail(co.get("linearizationReference").getAsString())).setDisplay(v)).setCode("exclusion");
                }
            }
        }
    }
    cc.setDefinition(defn.toString());
    addDesignation(readString(entity, "longDefinition"), cc, "http://id.who.int/icd11/mms/designation", "longDefinition");
    addDesignation(readString(entity, "fullySpecifiedName"), cc, "http://snomed.info/sct", "900000000000003001");
    addProperty(readString(entity, "codingNote"), cc, "codingNote");
    if (entity.has("indexTerm")) {
        // }
        for (JsonElement child : entity.getAsJsonArray("indexTerm")) {
            processIndexTerm(cc, (JsonObject) child);
        }
    }
    if (entity.has("postcoordinationScale")) {
        for (JsonElement child : entity.getAsJsonArray("postcoordinationScale")) {
            JsonObject o = (JsonObject) child;
            String name = tail(o.get("axisName").getAsString());
            ConceptPropertyComponent prop = cc.addProperty();
            prop.setCode("postcoordinationScale");
            prop.setValue(new CodeType(name));
            ToolingExtensions.addBooleanExtension(prop, "http://id.who.int/icd11/extensions/required", o.get("requiredPostcoordination").getAsBoolean());
            ToolingExtensions.addBooleanExtension(prop, "http://id.who.int/icd11/extensions/repeats", o.get("allowMultipleValues").getAsBoolean());
            if (o.has("scaleEntity")) {
                ToolingExtensions.addUriExtension(prop, "http://id.who.int/icd11/extensions/valueSet", buildValueSet(cs, cc.getCode(), name, o, dest));
            }
        }
    }
    if (entity.has("child")) {
        for (JsonElement child : entity.getAsJsonArray("child")) {
            processMMSEntity(cs, base, child.getAsString(), cc.addConcept(), dest);
        }
    }
}
Also used : ConceptPropertyComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptPropertyComponent) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 20 with BooleanType

use of org.hl7.fhir.r4b.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints) throws FHIRException, UnsupportedEncodingException, IOException {
    if (ew == null)
        return;
    Base e = ew.getBase();
    if (e instanceof StringType)
        x.addText(((StringType) e).getValue());
    else if (e instanceof CodeType)
        x.addText(((CodeType) e).getValue());
    else if (e instanceof IdType)
        x.addText(((IdType) e).getValue());
    else if (e instanceof Extension)
        x.addText("Extensions: Todo");
    else if (e instanceof InstantType)
        x.addText(((InstantType) e).toHumanDisplay());
    else if (e instanceof DateTimeType)
        x.addText(((DateTimeType) e).toHumanDisplay());
    else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.dstu2.model.DateType)
        x.addText(((org.hl7.fhir.dstu2.model.DateType) e).toHumanDisplay());
    else if (e instanceof Enumeration) {
        Object ev = ((Enumeration<?>) e).getValue();
        // todo: look up a display name if there is one
        x.addText(ev == null ? "" : ev.toString());
    } else if (e instanceof BooleanType)
        x.addText(((BooleanType) e).getValue().toString());
    else if (e instanceof CodeableConcept) {
        renderCodeableConcept((CodeableConcept) e, x, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding((Coding) e, x, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation((Annotation) e, x);
    } else if (e instanceof Identifier) {
        renderIdentifier((Identifier) e, x);
    } else if (e instanceof org.hl7.fhir.dstu2.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu2.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.dstu2.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu2.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName((HumanName) e, x);
    } else if (e instanceof SampledData) {
        renderSampledData((SampledData) e, x);
    } else if (e instanceof Address) {
        renderAddress((Address) e, x);
    } else if (e instanceof ContactPoint) {
        renderContactPoint((ContactPoint) e, x);
    } else if (e instanceof UriType) {
        renderUri((UriType) e, x);
    } else if (e instanceof Timing) {
        renderTiming((Timing) e, x);
    } else if (e instanceof Range) {
        renderRange((Range) e, x);
    } else if (e instanceof Quantity) {
        renderQuantity((Quantity) e, x, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
        x.addText("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.addText(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        XhtmlNode c = x;
        ResourceWithReference tr = null;
        if (r.hasReferenceElement()) {
            tr = resolveReference(res, r.getReference());
            if (!r.getReference().startsWith("#")) {
                if (tr != null && tr.getReference() != null)
                    c = x.addTag("a").attribute("href", tr.getReference());
                else
                    c = x.addTag("a").attribute("href", r.getReference());
            }
        }
        // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
        if (r.hasDisplayElement()) {
            c.addText(r.getDisplay());
            if (tr != null) {
                c.addText(". Generated Summary: ");
                generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
            }
        } else if (tr != null) {
            generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
        } else {
            c.addText(r.getReference());
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof ElementDefinition) {
        x.addText("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta))
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet");
}
Also used : Meta(org.hl7.fhir.dstu2.model.Meta) Base64(org.apache.commons.codec.binary.Base64) Address(org.hl7.fhir.dstu2.model.Address) StringType(org.hl7.fhir.dstu2.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu2.model.Attachment) UriType(org.hl7.fhir.dstu2.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu2.model.HumanName) ContactPoint(org.hl7.fhir.dstu2.model.ContactPoint) Identifier(org.hl7.fhir.dstu2.model.Identifier) Coding(org.hl7.fhir.dstu2.model.Coding) Narrative(org.hl7.fhir.dstu2.model.Narrative) SampledData(org.hl7.fhir.dstu2.model.SampledData) Ratio(org.hl7.fhir.dstu2.model.Ratio) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) InstantType(org.hl7.fhir.dstu2.model.InstantType) Enumeration(org.hl7.fhir.dstu2.model.Enumeration) Reference(org.hl7.fhir.dstu2.model.Reference) BooleanType(org.hl7.fhir.dstu2.model.BooleanType) Resource(org.hl7.fhir.dstu2.model.Resource) DomainResource(org.hl7.fhir.dstu2.model.DomainResource) Quantity(org.hl7.fhir.dstu2.model.Quantity) Period(org.hl7.fhir.dstu2.model.Period) Range(org.hl7.fhir.dstu2.model.Range) Base(org.hl7.fhir.dstu2.model.Base) Annotation(org.hl7.fhir.dstu2.model.Annotation) IdType(org.hl7.fhir.dstu2.model.IdType) Extension(org.hl7.fhir.dstu2.model.Extension) DateTimeType(org.hl7.fhir.dstu2.model.DateTimeType) CodeType(org.hl7.fhir.dstu2.model.CodeType) EventTiming(org.hl7.fhir.dstu2.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu2.model.Timing) Base64BinaryType(org.hl7.fhir.dstu2.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.dstu2.model.CodeableConcept)

Aggregations

ArrayList (java.util.ArrayList)59 BooleanType (org.hl7.fhir.r5.model.BooleanType)38 BooleanType (org.hl7.fhir.r4.model.BooleanType)37 FHIRException (org.hl7.fhir.exceptions.FHIRException)33 BooleanType (org.hl7.fhir.r4b.model.BooleanType)27 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)19 NotImplementedException (org.apache.commons.lang3.NotImplementedException)18 Base (org.hl7.fhir.r5.model.Base)17 Test (org.junit.Test)16 StringType (org.hl7.fhir.r4.model.StringType)15 Base (org.hl7.fhir.r4b.model.Base)15 BooleanType (org.hl7.fhir.dstu2016may.model.BooleanType)13 IOException (java.io.IOException)12 HashMap (java.util.HashMap)11 BooleanType (org.hl7.fhir.dstu2.model.BooleanType)11 Base (org.hl7.fhir.dstu2.model.Base)10 StringType (org.hl7.fhir.dstu3.model.StringType)10 StringType (org.hl7.fhir.r5.model.StringType)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 Coding (org.hl7.fhir.r4.model.Coding)9