use of org.hl7.fhir.r4.model.Enumeration in project quality-measure-and-cohort-service by Alvearie.
the class CohortCLITest method testMainMultipleResultTypes.
@Test
public void testMainMultipleResultTypes() throws Exception {
FhirServerConfig fhirConfig = getFhirServerConfig();
mockFhirResourceRetrieval("/metadata?_format=json", getCapabilityStatement());
Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, "1978-05-06");
patient.setMaritalStatus(new CodeableConcept(new Coding("http://hl7.org/fhir/ValueSet/marital-status", "M", "Married")));
mockFhirResourceRetrieval(patient);
Condition condition = new Condition();
condition.setSubject(new Reference(patient.getId()));
condition.setCode(new CodeableConcept(new Coding("http://snomed.com/snomed/2020", "1234", "Dummy")));
mockFhirResourceRetrieval("/Condition?code%3Ain=http%3A%2F%2Fsome.io%2Fcondition&subject=Patient%2F" + patient.getId() + "&_count=500&_format=json", condition);
File tmpFile = new File("target/fhir-stub.json");
ObjectMapper om = new ObjectMapper();
try (Writer w = new FileWriter(tmpFile)) {
w.write(om.writeValueAsString(fhirConfig));
}
try {
PrintStream originalOut = System.out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (PrintStream captureOut = new PrintStream(baos)) {
System.setOut(captureOut);
CohortCLI.main(new String[] { "-d", tmpFile.getAbsolutePath(), "-f", "src/test/resources/cql/result-types", "-l", "test_result_types", "-c", patient.getId(), "--enable-terminology-optimization", "--search-page-size", "500" });
} finally {
System.setOut(originalOut);
}
String output = new String(baos.toByteArray());
assertTrue(output.contains("Collection: 1"));
assertTrue(output.contains("Patient/123"));
assertTrue(output.contains("false"));
assertTrue(output.contains("DateType[1978-05-06]"));
assertTrue(output.contains("Enumeration[female]"));
String[] lines = output.split("\r?\n");
assertEquals(output, 9, lines.length);
System.out.println(output);
} finally {
tmpFile.delete();
}
}
use of org.hl7.fhir.r4.model.Enumeration in project openmrs-module-fhir2 by openmrs.
the class AllergyIntoleranceFhirResourceProviderIntegrationTest method shouldUpdateExistingAllergyAsXML.
@Test
public void shouldUpdateExistingAllergyAsXML() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
AllergyIntolerance allergy = readResponse(response);
// update the existing record
Enumeration<AllergyIntolerance.AllergyIntoleranceCategory> category = new Enumeration<>(new AllergyIntolerance.AllergyIntoleranceCategoryEnumFactory());
category.setValue(AllergyIntolerance.AllergyIntoleranceCategory.ENVIRONMENT);
allergy.getCategory().set(0, category);
// send the update to the server
response = put("/AllergyIntolerance/" + ALLERGY_UUID).xmlContent(toXML(allergy)).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
// read the updated record
AllergyIntolerance updatedAllergy = readResponse(response);
assertThat(updatedAllergy, notNullValue());
assertThat(updatedAllergy.getIdElement().getIdPart(), equalTo(ALLERGY_UUID));
assertThat(updatedAllergy.getCategory().get(0).getValue().toCode(), equalTo("environment"));
assertThat(updatedAllergy, validResource());
// double-check the record returned via get
response = get("/AllergyIntolerance/" + ALLERGY_UUID).accept(FhirMediaTypes.XML).go();
AllergyIntolerance reReadAllergy = readResponse(response);
assertThat(reReadAllergy.getCategory().get(0).getValue().toCode(), equalTo("environment"));
}
use of org.hl7.fhir.r4.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class ImplementationGuide30_40 method convertImplementationGuide.
public static org.hl7.fhir.dstu3.model.ImplementationGuide convertImplementationGuide(org.hl7.fhir.r4.model.ImplementationGuide src) throws FHIRException {
if (src == null)
return null;
org.hl7.fhir.dstu3.model.ImplementationGuide tgt = new org.hl7.fhir.dstu3.model.ImplementationGuide();
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyDomainResource(src, tgt);
if (src.hasUrl())
tgt.setUrlElement(Uri30_40.convertUri(src.getUrlElement()));
if (src.hasVersion())
tgt.setVersionElement(String30_40.convertString(src.getVersionElement()));
if (src.hasName())
tgt.setNameElement(String30_40.convertString(src.getNameElement()));
if (src.hasStatus())
tgt.setStatusElement(Enumerations30_40.convertPublicationStatus(src.getStatusElement()));
if (src.hasExperimental())
tgt.setExperimentalElement(Boolean30_40.convertBoolean(src.getExperimentalElement()));
if (src.hasDateElement())
tgt.setDateElement(DateTime30_40.convertDateTime(src.getDateElement()));
if (src.hasPublisher())
tgt.setPublisherElement(String30_40.convertString(src.getPublisherElement()));
for (org.hl7.fhir.r4.model.ContactDetail t : src.getContact()) tgt.addContact(ContactDetail30_40.convertContactDetail(t));
if (src.hasDescription())
tgt.setDescriptionElement(MarkDown30_40.convertMarkdown(src.getDescriptionElement()));
for (org.hl7.fhir.r4.model.UsageContext t : src.getUseContext()) tgt.addUseContext(Timing30_40.convertUsageContext(t));
for (org.hl7.fhir.r4.model.CodeableConcept t : src.getJurisdiction()) tgt.addJurisdiction(CodeableConcept30_40.convertCodeableConcept(t));
if (src.hasCopyright())
tgt.setCopyrightElement(MarkDown30_40.convertMarkdown(src.getCopyrightElement()));
if (src.hasFhirVersion())
for (Enumeration<org.hl7.fhir.r4.model.Enumerations.FHIRVersion> v : src.getFhirVersion()) {
tgt.setFhirVersion(v.asStringValue());
break;
}
for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDependsOnComponent t : src.getDependsOn()) tgt.addDependency(convertImplementationGuideDependencyComponent(t));
for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionGroupingComponent t : src.getDefinition().getGrouping()) tgt.addPackage(convertImplementationGuidePackageComponent(t));
for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideDefinitionResourceComponent t : src.getDefinition().getResource()) {
findPackage(tgt.getPackage(), t.getGroupingId()).addResource(convertImplementationGuidePackageResourceComponent(t));
}
for (org.hl7.fhir.r4.model.ImplementationGuide.ImplementationGuideGlobalComponent t : src.getGlobal()) tgt.addGlobal(convertImplementationGuideGlobalComponent(t));
if (src.getDefinition().hasPage())
tgt.setPage(convertImplementationGuidePageComponent(src.getDefinition().getPage()));
return tgt;
}
use of org.hl7.fhir.r4.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class ISO21090Importer method generateValueSet.
private void generateValueSet(EnumValueSet evs) throws Exception {
ValueSet bvs = ctxt.fetchResource(ValueSet.class, evs.getTemplate());
if (bvs == null)
throw new Exception("Did not find template value set " + evs.getTemplate());
ValueSet vs = bvs.copy();
vs.getCompose().getInclude().clear();
vs.getIdentifier().clear();
vs.setName("ISO 20190 " + evs.getName() + " Enumeration");
vs.setId(evs.getName());
vs.setUrl("http://hl7.org/fhir/iso21090/ValueSet/" + vs.getId());
vs.setDate(new Date());
vs.setExperimental(false);
ConceptSetComponent inc = vs.getCompose().addInclude().setSystem(evs.getSystem());
for (String code : evs.getCodes()) {
inc.addConcept().setCode(code);
}
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "iso21090\\ValueSet-" + evs.getName() + ".xml")), vs);
}
use of org.hl7.fhir.r4.model.Enumeration 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