Search in sources :

Example 36 with Address

use of com.adobe.target.delivery.v1.model.Address 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)

Example 37 with Address

use of com.adobe.target.delivery.v1.model.Address in project org.hl7.fhir.core by hapifhir.

the class InstanceValidator method checkAddress.

private void checkAddress(List<ValidationMessage> errors, String path, Element focus, Address fixed, String fixedSource, boolean pattern) {
    checkFixedValue(errors, path + ".use", focus.getNamedChild("use"), fixed.getUseElement(), fixedSource, "use", focus, pattern);
    checkFixedValue(errors, path + ".text", focus.getNamedChild("text"), fixed.getTextElement(), fixedSource, "text", focus, pattern);
    checkFixedValue(errors, path + ".city", focus.getNamedChild("city"), fixed.getCityElement(), fixedSource, "city", focus, pattern);
    checkFixedValue(errors, path + ".state", focus.getNamedChild("state"), fixed.getStateElement(), fixedSource, "state", focus, pattern);
    checkFixedValue(errors, path + ".country", focus.getNamedChild("country"), fixed.getCountryElement(), fixedSource, "country", focus, pattern);
    checkFixedValue(errors, path + ".zip", focus.getNamedChild("zip"), fixed.getPostalCodeElement(), fixedSource, "postalCode", focus, pattern);
    List<Element> lines = new ArrayList<Element>();
    focus.getNamedChildren("line", lines);
    boolean lineSizeCheck;
    if (pattern) {
        lineSizeCheck = lines.size() >= fixed.getLine().size();
        if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, lineSizeCheck, I18nConstants.FIXED_TYPE_CHECKS_DT_ADDRESS_LINE, Integer.toString(fixed.getLine().size()), Integer.toString(lines.size()))) {
            for (int i = 0; i < fixed.getLine().size(); i++) {
                StringType fixedLine = fixed.getLine().get(i);
                boolean found = false;
                List<ValidationMessage> allErrorsFixed = new ArrayList<>();
                List<ValidationMessage> errorsFixed = null;
                for (int j = 0; j < lines.size() && !found; ++j) {
                    errorsFixed = new ArrayList<>();
                    checkFixedValue(errorsFixed, path + ".line", lines.get(j), fixedLine, fixedSource, "line", focus, pattern);
                    if (!hasErrors(errorsFixed)) {
                        found = true;
                    } else {
                        errorsFixed.stream().filter(t -> t.getLevel().ordinal() >= IssueSeverity.ERROR.ordinal()).forEach(t -> allErrorsFixed.add(t));
                    }
                }
                if (!found) {
                    rule(errorsFixed, IssueType.VALUE, focus.line(), focus.col(), path, false, I18nConstants.PATTERN_CHECK_STRING, fixedLine.getValue(), fixedSource, allErrorsFixed);
                }
            }
        }
    } else if (!pattern) {
        lineSizeCheck = lines.size() == fixed.getLine().size();
        if (rule(errors, IssueType.VALUE, focus.line(), focus.col(), path, lineSizeCheck, I18nConstants.FIXED_TYPE_CHECKS_DT_ADDRESS_LINE, Integer.toString(fixed.getLine().size()), Integer.toString(lines.size()))) {
            for (int i = 0; i < lines.size(); i++) {
                checkFixedValue(errors, path + ".line", lines.get(i), fixed.getLine().get(i), fixedSource, "line", focus, pattern);
            }
        }
    }
}
Also used : TypedElementDefinition(org.hl7.fhir.r5.utils.FHIRPathEngine.TypedElementDefinition) XmlParser(org.hl7.fhir.r5.elementmodel.XmlParser) IntegerType(org.hl7.fhir.r5.model.IntegerType) VersionUtilities(org.hl7.fhir.utilities.VersionUtilities) ExtensionContextType(org.hl7.fhir.r5.model.StructureDefinition.ExtensionContextType) TimeType(org.hl7.fhir.r5.model.TimeType) TerminologyServiceErrorClass(org.hl7.fhir.r5.terminologies.ValueSetExpander.TerminologyServiceErrorClass) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) ConstraintSeverity(org.hl7.fhir.r5.model.ElementDefinition.ConstraintSeverity) StringUtils(org.apache.commons.lang3.StringUtils) SearchParameterValidator(org.hl7.fhir.validation.instance.type.SearchParameterValidator) BigDecimal(java.math.BigDecimal) Document(org.w3c.dom.Document) Map(java.util.Map) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) JsonParser(org.hl7.fhir.r5.elementmodel.JsonParser) ImplementationGuide(org.hl7.fhir.r5.model.ImplementationGuide) Resource(org.hl7.fhir.r5.model.Resource) Source(org.hl7.fhir.utilities.validation.ValidationMessage.Source) ObjectConverter(org.hl7.fhir.r5.elementmodel.ObjectConverter) ConceptDefinitionComponent(org.hl7.fhir.r5.model.CodeSystem.ConceptDefinitionComponent) FormatUtilities(org.hl7.fhir.r5.formats.FormatUtilities) VersionURLInfo(org.hl7.fhir.utilities.VersionUtilities.VersionURLInfo) XVerExtensionManager(org.hl7.fhir.r5.utils.XVerExtensionManager) IssueSeverity(org.hl7.fhir.utilities.validation.ValidationMessage.IssueSeverity) Timing(org.hl7.fhir.r5.model.Timing) ValidatorHostContext(org.hl7.fhir.validation.instance.utils.ValidatorHostContext) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Set(java.util.Set) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) ResourceValidationTracker(org.hl7.fhir.validation.instance.utils.ResourceValidationTracker) StandardCharsets(java.nio.charset.StandardCharsets) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) PropertyRepresentation(org.hl7.fhir.r5.model.ElementDefinition.PropertyRepresentation) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) Coding(org.hl7.fhir.r5.model.Coding) Utilities(org.hl7.fhir.utilities.Utilities) BooleanType(org.hl7.fhir.r5.model.BooleanType) ParserBase(org.hl7.fhir.r5.elementmodel.ParserBase) NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) BindingStrength(org.hl7.fhir.r5.model.Enumerations.BindingStrength) StructureDefinitionContextComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent) BaseValidator(org.hl7.fhir.validation.BaseValidator) BundleValidator(org.hl7.fhir.validation.instance.type.BundleValidator) ArrayList(java.util.ArrayList) ValidationPolicy(org.hl7.fhir.r5.elementmodel.ParserBase.ValidationPolicy) QuestionnaireValidator(org.hl7.fhir.validation.instance.type.QuestionnaireValidator) Calendar(java.util.Calendar) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) Decimal(org.fhir.ucum.Decimal) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ValidationLevel(org.hl7.fhir.validation.cli.utils.ValidationLevel) DataType(org.hl7.fhir.r5.model.DataType) IOException(java.io.IOException) InstantType(org.hl7.fhir.r5.model.InstantType) File(java.io.File) Base(org.hl7.fhir.r5.model.Base) Manager(org.hl7.fhir.r5.elementmodel.Manager) ElementInfo(org.hl7.fhir.validation.instance.utils.ElementInfo) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept) FHIRException(org.hl7.fhir.exceptions.FHIRException) ExpressionNode(org.hl7.fhir.r5.model.ExpressionNode) TypeDetails(org.hl7.fhir.r5.model.TypeDetails) JsonObject(com.google.gson.JsonObject) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) FHIRPathEngine(org.hl7.fhir.r5.utils.FHIRPathEngine) StructureDefinitionKind(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind) SampledData(org.hl7.fhir.r5.model.SampledData) Range(org.hl7.fhir.r5.model.Range) QuestionnaireMode(org.hl7.fhir.validation.cli.utils.QuestionnaireMode) I18nConstants(org.hl7.fhir.utilities.i18n.I18nConstants) ByteArrayInputStream(java.io.ByteArrayInputStream) StructureDefinitionMappingComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent) Gson(com.google.gson.Gson) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) Identifier(org.hl7.fhir.r5.model.Identifier) AggregationMode(org.hl7.fhir.r5.model.ElementDefinition.AggregationMode) Period(org.hl7.fhir.r5.model.Period) ToolingExtensions(org.hl7.fhir.r5.utils.ToolingExtensions) Collection(java.util.Collection) Reference(org.hl7.fhir.r5.model.Reference) StructureDefinitionSnapshotComponent(org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionSnapshotComponent) UUID(java.util.UUID) Quantity(org.hl7.fhir.r5.model.Quantity) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) ChildIterator(org.hl7.fhir.validation.instance.utils.ChildIterator) List(java.util.List) ValueSetExpansionContainsComponent(org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) DateType(org.hl7.fhir.r5.model.DateType) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) Enumeration(org.hl7.fhir.r5.model.Enumeration) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) DecimalStatus(org.hl7.fhir.utilities.Utilities.DecimalStatus) ValidationResult(org.hl7.fhir.r5.context.IWorkerContext.ValidationResult) ImplementationGuideGlobalComponent(org.hl7.fhir.r5.model.ImplementationGuide.ImplementationGuideGlobalComponent) ResolvedReference(org.hl7.fhir.validation.instance.utils.ResolvedReference) NotImplementedException(org.apache.commons.lang3.NotImplementedException) org.hl7.fhir.r5.utils.validation.constants(org.hl7.fhir.r5.utils.validation.constants) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent) ElementDefinitionSlicingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent) ValueSet(org.hl7.fhir.r5.model.ValueSet) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) HashMap(java.util.HashMap) TypeDerivationRule(org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule) NodeStack(org.hl7.fhir.validation.instance.utils.NodeStack) DataRenderer(org.hl7.fhir.r5.renderers.DataRenderer) CodeSystemValidator(org.hl7.fhir.validation.instance.type.CodeSystemValidator) HashSet(java.util.HashSet) UriType(org.hl7.fhir.r5.model.UriType) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StructureDefinitionValidator(org.hl7.fhir.validation.instance.type.StructureDefinitionValidator) BuildExtensions(org.hl7.fhir.r5.utils.BuildExtensions) SearchParameter(org.hl7.fhir.r5.model.SearchParameter) ValidationOptions(org.hl7.fhir.utilities.validation.ValidationOptions) DiscriminatorType(org.hl7.fhir.r5.model.ElementDefinition.DiscriminatorType) MeasureValidator(org.hl7.fhir.validation.instance.type.MeasureValidator) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) Ratio(org.hl7.fhir.r5.model.Ratio) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) Attachment(org.hl7.fhir.r5.model.Attachment) IWorkerContext(org.hl7.fhir.r5.context.IWorkerContext) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) StringType(org.hl7.fhir.r5.model.StringType) Address(org.hl7.fhir.r5.model.Address) SIDUtilities(org.hl7.fhir.utilities.SIDUtilities) FhirFormat(org.hl7.fhir.r5.elementmodel.Manager.FhirFormat) Element(org.hl7.fhir.r5.elementmodel.Element) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) Extension(org.hl7.fhir.r5.model.Extension) UnicodeUtilities(org.hl7.fhir.utilities.UnicodeUtilities) org.hl7.fhir.r5.utils.validation(org.hl7.fhir.r5.utils.validation) IEvaluationContext(org.hl7.fhir.r5.utils.FHIRPathEngine.IEvaluationContext) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) DecimalType(org.hl7.fhir.r5.model.DecimalType) ValueSetValidator(org.hl7.fhir.validation.instance.type.ValueSetValidator) FHIRLexerException(org.hl7.fhir.r5.utils.FHIRLexer.FHIRLexerException) InputStream(java.io.InputStream) HumanName(org.hl7.fhir.r5.model.HumanName) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) StringType(org.hl7.fhir.r5.model.StringType) NamedElement(org.hl7.fhir.r5.elementmodel.ParserBase.NamedElement) IndexedElement(org.hl7.fhir.validation.instance.utils.IndexedElement) SpecialElement(org.hl7.fhir.r5.elementmodel.Element.SpecialElement) Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) ContactPoint(org.hl7.fhir.r5.model.ContactPoint)

Example 38 with Address

use of com.adobe.target.delivery.v1.model.Address 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, String path) 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)
        return;
    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.dstu3.model.DateType)
        x.addText(((org.hl7.fhir.dstu3.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.dstu3.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu3.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.dstu3.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu3.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.tx("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.tx(" --> ");
        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.ah(tr.getReference());
                else
                    c = x.ah(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 && tr.getResource() != null) {
                c.tx(". Generated Summary: ");
                generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
            }
        } else if (tr != null && tr.getResource() != 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.tx("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
        StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
        if (sd == null)
            throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
        else
            generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails);
    }
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Base64(org.apache.commons.codec.binary.Base64) Address(org.hl7.fhir.dstu3.model.Address) StringType(org.hl7.fhir.dstu3.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu3.model.Attachment) UriType(org.hl7.fhir.dstu3.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) Narrative(org.hl7.fhir.dstu3.model.Narrative) SampledData(org.hl7.fhir.dstu3.model.SampledData) Ratio(org.hl7.fhir.dstu3.model.Ratio) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) InstantType(org.hl7.fhir.dstu3.model.InstantType) Enumeration(org.hl7.fhir.dstu3.model.Enumeration) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) Resource(org.hl7.fhir.dstu3.model.Resource) Quantity(org.hl7.fhir.dstu3.model.Quantity) Period(org.hl7.fhir.dstu3.model.Period) Range(org.hl7.fhir.dstu3.model.Range) Base(org.hl7.fhir.dstu3.model.Base) Annotation(org.hl7.fhir.dstu3.model.Annotation) IdType(org.hl7.fhir.dstu3.model.IdType) Extension(org.hl7.fhir.dstu3.model.Extension) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) CodeType(org.hl7.fhir.dstu3.model.CodeType) EventTiming(org.hl7.fhir.dstu3.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu3.model.Timing) Base64BinaryType(org.hl7.fhir.dstu3.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 39 with Address

use of com.adobe.target.delivery.v1.model.Address in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode parent, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
    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)
        return;
    else if (e instanceof InstantType)
        x.addText(((InstantType) e).toHumanDisplay());
    else if (e instanceof DateTimeType) {
        renderDateTime(x, e);
    } else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.r5.model.DateType) {
        org.hl7.fhir.r5.model.DateType dt = ((org.hl7.fhir.r5.model.DateType) e);
        renderDate(x, dt);
    } 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(x, (CodeableConcept) e, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding(x, (Coding) e, showCodeDetails);
    } else if (e instanceof CodeableReference) {
        renderCodeableReference(x, (CodeableReference) e, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation(x, (Annotation) e);
    } else if (e instanceof Identifier) {
        renderIdentifier(x, (Identifier) e);
    } else if (e instanceof org.hl7.fhir.r5.model.IntegerType) {
        if (((org.hl7.fhir.r5.model.IntegerType) e).hasValue()) {
            x.addText(Integer.toString(((org.hl7.fhir.r5.model.IntegerType) e).getValue()));
        } else {
            x.addText("??");
        }
    } else if (e instanceof org.hl7.fhir.r5.model.Integer64Type) {
        if (((org.hl7.fhir.r5.model.Integer64Type) e).hasValue()) {
            x.addText(Long.toString(((org.hl7.fhir.r5.model.Integer64Type) e).getValue()));
        } else {
            x.addText("??");
        }
    } else if (e instanceof org.hl7.fhir.r5.model.DecimalType) {
        x.addText(((org.hl7.fhir.r5.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName(x, (HumanName) e);
    } else if (e instanceof SampledData) {
        renderSampledData(x, (SampledData) e);
    } else if (e instanceof Address) {
        renderAddress(x, (Address) e);
    } else if (e instanceof ContactPoint) {
        renderContactPoint(x, (ContactPoint) e);
    } else if (e instanceof Expression) {
        renderExpression(x, (Expression) e);
    } else if (e instanceof Money) {
        renderMoney(x, (Money) e);
    } else if (e instanceof ContactDetail) {
        ContactDetail cd = (ContactDetail) e;
        if (cd.hasName()) {
            x.tx(cd.getName() + ": ");
        }
        boolean first = true;
        for (ContactPoint c : cd.getTelecom()) {
            if (first)
                first = false;
            else
                x.tx(",");
            renderContactPoint(x, c);
        }
    } else if (e instanceof UriType) {
        renderUri(x, (UriType) e, defn.getPath(), rcontext != null && rcontext.getResourceResource() != null ? rcontext.getResourceResource().getId() : null);
    } else if (e instanceof Timing) {
        renderTiming(x, (Timing) e);
    } else if (e instanceof Range) {
        renderRange(x, (Range) e);
    } else if (e instanceof Quantity) {
        renderQuantity(x, (Quantity) e, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails);
        x.tx("/");
        renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        renderPeriod(x, p);
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        if (r.getReference() != null && r.getReference().contains("#")) {
            if (containedIds.contains(r.getReference().substring(1))) {
                x.ah(r.getReference()).tx("See " + r.getReference());
            } else {
                // in this case, we render the resource in line
                ResourceWrapper rw = null;
                for (ResourceWrapper t : res.getContained()) {
                    if (r.getReference().substring(1).equals(t.getId())) {
                        rw = t;
                    }
                }
                if (rw == null) {
                    renderReference(res, x, r);
                } else {
                    x.an(rw.getId());
                    ResourceRenderer rr = RendererFactory.factory(rw, context.copy().setAddGeneratedNarrativeHeader(false));
                    rr.render(parent.blockquote(), rw);
                }
            }
        } else {
            renderReference(res, x, r);
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof DataRequirement) {
        DataRequirement p = (DataRequirement) e;
        renderDataRequirement(x, p);
    } else if (e instanceof PrimitiveType) {
        x.tx(((PrimitiveType) e).primitiveValue());
    } else if (e instanceof ElementDefinition) {
        x.tx("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled - should not be here");
    }
}
Also used : ResourceWrapper(org.hl7.fhir.r5.renderers.utils.BaseWrappers.ResourceWrapper) Meta(org.hl7.fhir.r5.model.Meta) Address(org.hl7.fhir.r5.model.Address) StringType(org.hl7.fhir.r5.model.StringType) Attachment(org.hl7.fhir.r5.model.Attachment) DataRequirement(org.hl7.fhir.r5.model.DataRequirement) Identifier(org.hl7.fhir.r5.model.Identifier) Coding(org.hl7.fhir.r5.model.Coding) Narrative(org.hl7.fhir.r5.model.Narrative) SampledData(org.hl7.fhir.r5.model.SampledData) PrimitiveType(org.hl7.fhir.r5.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) InstantType(org.hl7.fhir.r5.model.InstantType) Resource(org.hl7.fhir.r5.model.Resource) DomainResource(org.hl7.fhir.r5.model.DomainResource) Period(org.hl7.fhir.r5.model.Period) Range(org.hl7.fhir.r5.model.Range) IdType(org.hl7.fhir.r5.model.IdType) DateTimeType(org.hl7.fhir.r5.model.DateTimeType) Timing(org.hl7.fhir.r5.model.Timing) CodeableConcept(org.hl7.fhir.r5.model.CodeableConcept) Base64(org.apache.commons.codec.binary.Base64) NotImplementedException(org.apache.commons.lang3.NotImplementedException) UriType(org.hl7.fhir.r5.model.UriType) HumanName(org.hl7.fhir.r5.model.HumanName) ContactPoint(org.hl7.fhir.r5.model.ContactPoint) Money(org.hl7.fhir.r5.model.Money) Ratio(org.hl7.fhir.r5.model.Ratio) Enumeration(org.hl7.fhir.r5.model.Enumeration) Reference(org.hl7.fhir.r5.model.Reference) ResourceWithReference(org.hl7.fhir.r5.renderers.utils.Resolver.ResourceWithReference) CodeableReference(org.hl7.fhir.r5.model.CodeableReference) BooleanType(org.hl7.fhir.r5.model.BooleanType) Quantity(org.hl7.fhir.r5.model.Quantity) Base(org.hl7.fhir.r5.model.Base) Annotation(org.hl7.fhir.r5.model.Annotation) Extension(org.hl7.fhir.r5.model.Extension) ContactDetail(org.hl7.fhir.r5.model.ContactDetail) Expression(org.hl7.fhir.r5.model.Expression) CodeableReference(org.hl7.fhir.r5.model.CodeableReference) CodeType(org.hl7.fhir.r5.model.CodeType) Base64BinaryType(org.hl7.fhir.r5.model.Base64BinaryType)

Example 40 with Address

use of com.adobe.target.delivery.v1.model.Address in project eCRNow by drajer-health.

the class CdaHeaderGenerator method getPatientDetails.

public static String getPatientDetails(Patient p, LaunchDetails details) {
    StringBuilder patientDetails = new StringBuilder();
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.RECORD_TARGET_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.PATIENT_ROLE_EL_NAME));
    List<Identifier> ids = CdaFhirUtilities.getIdentifierForType(p.getIdentifier(), CdaFhirEnumConstants.FHIR_ID_TYPE_MR);
    Boolean addOnce = true;
    if (ids != null && !ids.isEmpty()) {
        for (Identifier id : ids) {
            if (!StringUtils.isEmpty(id.getSystem()) && !StringUtils.isEmpty(id.getValue())) {
                logger.debug("Found Identifier with Type MR");
                String system = CdaGeneratorUtils.getRootOid(id.getSystem(), details.getAssigningAuthorityId());
                patientDetails.append(CdaGeneratorUtils.getXmlForII(system, id.getValue()));
            } else {
                logger.debug("Using Resource Identifier as id");
                if (addOnce) {
                    patientDetails.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), p.getId()));
                    addOnce = false;
                }
            }
        }
    } else {
        logger.debug("Using Resource Identifier as id");
        patientDetails.append(CdaGeneratorUtils.getXmlForII(details.getAssigningAuthorityId(), p.getId()));
    }
    // Add Address.
    patientDetails.append(CdaFhirUtilities.getAddressXml(p.getAddress()));
    // Add Telecom (Phone)
    patientDetails.append(CdaFhirUtilities.getTelecomXml(p.getTelecom(), false));
    // Add Telecom (Email)
    patientDetails.append(CdaFhirUtilities.getEmailXml(p.getTelecom()));
    // Add patient
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.PATIENT_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
    patientDetails.append(CdaFhirUtilities.getNameXml(p.getName()));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
    patientDetails.append(CdaFhirUtilities.getGenderXml(p.getGenderElement().getValue()));
    patientDetails.append(CdaFhirUtilities.getDateTypeXml(p.getBirthDateElement(), CdaGeneratorConstants.BIRTH_TIME_EL_NAME));
    if (p.getDeceased() == null || (p.getDeceased() != null && p.getDeceased().isEmpty())) {
        patientDetails.append(CdaGeneratorUtils.getXmlForValue(CdaGeneratorConstants.SDTC_DECEASED_IND, CdaGeneratorConstants.CCDA_FALSE));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForValue(CdaGeneratorConstants.SDTC_DECEASED_IND, CdaGeneratorConstants.CCDA_TRUE));
        if (p.getDeceased() instanceof DateTimeType) {
            DateTimeType d = (DateTimeType) p.getDeceased();
            patientDetails.append(CdaFhirUtilities.getDateTimeTypeXml(d, CdaGeneratorConstants.SDTC_DECEASED_TIME));
        } else {
            patientDetails.append(CdaGeneratorUtils.getXmlForNullEffectiveTime(CdaGeneratorConstants.SDTC_DECEASED_TIME, CdaGeneratorConstants.NF_NI));
        }
    }
    Coding race = CdaFhirUtilities.getCodingExtension(p.getExtension(), CdaGeneratorConstants.FHIR_USCORE_RACE_EXT_URL, CdaGeneratorConstants.OMB_RACE_CATEGORY_URL);
    if (race != null && race.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.RACE_CODE_EL_NAME, race.getCode(), CdaGeneratorConstants.RACE_CODE_SYSTEM, CdaGeneratorConstants.RACE_CODE_SYSTEM_NAME, race.getDisplay()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.RACE_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    Coding ethnicity = CdaFhirUtilities.getCodingExtension(p.getExtension(), CdaGeneratorConstants.FHIR_USCORE_ETHNICITY_EXT_URL, CdaGeneratorConstants.OMB_RACE_CATEGORY_URL);
    if (ethnicity != null && ethnicity.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.ETHNIC_CODE_EL_NAME, ethnicity.getCode(), CdaGeneratorConstants.RACE_CODE_SYSTEM, CdaGeneratorConstants.RACE_CODE_SYSTEM_NAME, ethnicity.getDisplay()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.ETHNIC_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    // Adding Guardian
    if (p.getContact() != null && !p.getContact().isEmpty()) {
        ContactComponent guardianContact = CdaFhirUtilities.getGuardianContact(p.getContact());
        if (guardianContact != null) {
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.GUARDIAN_EL_NAME));
            // Add address if found
            if (guardianContact.getAddress() != null) {
                logger.debug("Adding Address for Guardian");
                List<Address> addrs = new ArrayList<>();
                addrs.add(guardianContact.getAddress());
                patientDetails.append(CdaFhirUtilities.getAddressXml(addrs));
            }
            // Add Telecom
            patientDetails.append(CdaFhirUtilities.getTelecomXml(guardianContact.getTelecom(), false));
            patientDetails.append(CdaFhirUtilities.getEmailXml(guardianContact.getTelecom()));
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.GUARDIAN_PERSON_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.NAME_EL_NAME));
            List<HumanName> names = new ArrayList<>();
            names.add(guardianContact.getName());
            patientDetails.append(CdaFhirUtilities.getNameXml(names));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.NAME_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.GUARDIAN_PERSON_EL_NAME));
            patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.GUARDIAN_EL_NAME));
        }
    }
    patientDetails.append(CdaGeneratorUtils.getXmlForStartElement(CdaGeneratorConstants.LANGUAGE_COMM_EL_NAME));
    Coding language = CdaFhirUtilities.getLanguageForCodeSystem(p.getCommunication(), CdaGeneratorConstants.FHIR_LANGUAGE_CODESYSTEM_URL);
    if (language != null && language.getCode() != null) {
        patientDetails.append(CdaGeneratorUtils.getXmlForCD(CdaGeneratorConstants.LANGUAGE_CODE_EL_NAME, language.getCode()));
    } else {
        patientDetails.append(CdaGeneratorUtils.getXmlForNullCD(CdaGeneratorConstants.LANGUAGE_CODE_EL_NAME, CdaGeneratorConstants.NF_NI));
    }
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.LANGUAGE_COMM_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.PATIENT_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.PATIENT_ROLE_EL_NAME));
    patientDetails.append(CdaGeneratorUtils.getXmlForEndElement(CdaGeneratorConstants.RECORD_TARGET_EL_NAME));
    return patientDetails.toString();
}
Also used : Address(org.hl7.fhir.r4.model.Address) ArrayList(java.util.ArrayList) HumanName(org.hl7.fhir.r4.model.HumanName) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) ContactComponent(org.hl7.fhir.r4.model.Patient.ContactComponent)

Aggregations

Address (org.hl7.fhir.r4.model.Address)75 Test (org.junit.Test)35 Address (org.hl7.fhir.dstu3.model.Address)22 PersonAddress (org.openmrs.PersonAddress)21 HumanName (org.hl7.fhir.r4.model.HumanName)20 Patient (org.hl7.fhir.r4.model.Patient)18 ArrayList (java.util.ArrayList)17 Identifier (org.hl7.fhir.r4.model.Identifier)17 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)16 Test (org.junit.jupiter.api.Test)13 Organization (org.hl7.fhir.r4.model.Organization)12 Address (com.amazonaws.services.ec2.model.Address)7 HumanName (org.hl7.fhir.dstu3.model.HumanName)7 PatientCommunicationComponent (org.hl7.fhir.r4.model.Patient.PatientCommunicationComponent)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DescribeAddressesResult (com.amazonaws.services.ec2.model.DescribeAddressesResult)5 HashSet (java.util.HashSet)5 Coding (org.hl7.fhir.r4.model.Coding)5 StringType (org.hl7.fhir.r4.model.StringType)5 Before (org.junit.Before)5