use of org.hl7.fhir.r4b.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.r4b.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.r4b.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.r4b.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");
}
use of org.hl7.fhir.r4b.model.Enumeration in project org.hl7.fhir.core by hapifhir.
the class ValueSet method setProperty.
@Override
public void setProperty(String name, Base value) throws FHIRException {
if (name.equals("url"))
// UriType
this.url = castToUri(value);
else if (name.equals("identifier"))
// Identifier
this.identifier = castToIdentifier(value);
else if (name.equals("version"))
// StringType
this.version = castToString(value);
else if (name.equals("name"))
// StringType
this.name = castToString(value);
else if (name.equals("status"))
// Enumeration<ConformanceResourceStatus>
this.status = new ConformanceResourceStatusEnumFactory().fromType(value);
else if (name.equals("experimental"))
// BooleanType
this.experimental = castToBoolean(value);
else if (name.equals("publisher"))
// StringType
this.publisher = castToString(value);
else if (name.equals("contact"))
this.getContact().add((ValueSetContactComponent) value);
else if (name.equals("date"))
// DateTimeType
this.date = castToDateTime(value);
else if (name.equals("lockedDate"))
// DateType
this.lockedDate = castToDate(value);
else if (name.equals("description"))
// StringType
this.description = castToString(value);
else if (name.equals("useContext"))
this.getUseContext().add(castToCodeableConcept(value));
else if (name.equals("immutable"))
// BooleanType
this.immutable = castToBoolean(value);
else if (name.equals("requirements"))
// StringType
this.requirements = castToString(value);
else if (name.equals("copyright"))
// StringType
this.copyright = castToString(value);
else if (name.equals("extensible"))
// BooleanType
this.extensible = castToBoolean(value);
else if (name.equals("compose"))
// ValueSetComposeComponent
this.compose = (ValueSetComposeComponent) value;
else if (name.equals("expansion"))
// ValueSetExpansionComponent
this.expansion = (ValueSetExpansionComponent) value;
else
super.setProperty(name, value);
}
Aggregations