use of org.hl7.fhir.r4.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));
}
use of org.hl7.fhir.r4.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));
}
use of org.hl7.fhir.r4.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;
}
use of org.hl7.fhir.r4.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);
}
}
}
use of org.hl7.fhir.r4.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");
}
Aggregations