Search in sources :

Example 31 with CodeableReference

use of org.hl7.fhir.r4b.model.CodeableReference 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.r4b.model.DateType) {
        org.hl7.fhir.r4b.model.DateType dt = ((org.hl7.fhir.r4b.model.DateType) e);
        if (((org.hl7.fhir.r4b.model.DateType) e).hasValue()) {
            x.addText(((org.hl7.fhir.r4b.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(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.r4b.model.IntegerType) {
        if (((org.hl7.fhir.r4b.model.IntegerType) e).hasValue()) {
            x.addText(Integer.toString(((org.hl7.fhir.r4b.model.IntegerType) e).getValue()));
        } else {
            x.addText("??");
        }
    } else if (e instanceof org.hl7.fhir.r4b.model.Integer64Type) {
        if (((org.hl7.fhir.r4b.model.Integer64Type) e).hasValue()) {
            x.addText(Long.toString(((org.hl7.fhir.r4b.model.Integer64Type) e).getValue()));
        } else {
            x.addText("??");
        }
    } else if (e instanceof org.hl7.fhir.r4b.model.DecimalType) {
        x.addText(((org.hl7.fhir.r4b.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.r4b.renderers.utils.BaseWrappers.ResourceWrapper) Meta(org.hl7.fhir.r4b.model.Meta) Address(org.hl7.fhir.r4b.model.Address) StringType(org.hl7.fhir.r4b.model.StringType) Attachment(org.hl7.fhir.r4b.model.Attachment) DataRequirement(org.hl7.fhir.r4b.model.DataRequirement) Identifier(org.hl7.fhir.r4b.model.Identifier) Coding(org.hl7.fhir.r4b.model.Coding) Narrative(org.hl7.fhir.r4b.model.Narrative) SampledData(org.hl7.fhir.r4b.model.SampledData) PrimitiveType(org.hl7.fhir.r4b.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) InstantType(org.hl7.fhir.r4b.model.InstantType) DomainResource(org.hl7.fhir.r4b.model.DomainResource) Resource(org.hl7.fhir.r4b.model.Resource) Period(org.hl7.fhir.r4b.model.Period) Range(org.hl7.fhir.r4b.model.Range) IdType(org.hl7.fhir.r4b.model.IdType) DateTimeType(org.hl7.fhir.r4b.model.DateTimeType) Timing(org.hl7.fhir.r4b.model.Timing) CodeableConcept(org.hl7.fhir.r4b.model.CodeableConcept) Base64(org.apache.commons.codec.binary.Base64) NotImplementedException(org.apache.commons.lang3.NotImplementedException) UriType(org.hl7.fhir.r4b.model.UriType) HumanName(org.hl7.fhir.r4b.model.HumanName) ContactPoint(org.hl7.fhir.r4b.model.ContactPoint) Money(org.hl7.fhir.r4b.model.Money) Ratio(org.hl7.fhir.r4b.model.Ratio) Enumeration(org.hl7.fhir.r4b.model.Enumeration) CodeableReference(org.hl7.fhir.r4b.model.CodeableReference) ResourceWithReference(org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference) Reference(org.hl7.fhir.r4b.model.Reference) BooleanType(org.hl7.fhir.r4b.model.BooleanType) Quantity(org.hl7.fhir.r4b.model.Quantity) Base(org.hl7.fhir.r4b.model.Base) Annotation(org.hl7.fhir.r4b.model.Annotation) Extension(org.hl7.fhir.r4b.model.Extension) ContactDetail(org.hl7.fhir.r4b.model.ContactDetail) Expression(org.hl7.fhir.r4b.model.Expression) CodeableReference(org.hl7.fhir.r4b.model.CodeableReference) CodeType(org.hl7.fhir.r4b.model.CodeType) Base64BinaryType(org.hl7.fhir.r4b.model.Base64BinaryType)

Example 32 with CodeableReference

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

the class StructureDefinitionValidator method validateTargetProfile.

private void validateTargetProfile(List<ValidationMessage> errors, Element profile, String code, NodeStack stack, String path) {
    String p = profile.primitiveValue();
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, p);
    if (code.equals("Reference") || code.equals("CodeableReference")) {
        if (warning(errors, IssueType.EXCEPTION, stack.getLiteralPath(), sd != null, I18nConstants.SD_ED_TYPE_PROFILE_UNKNOWN, p)) {
            StructureDefinition t = determineBaseType(sd);
            if (t == null) {
                rule(errors, IssueType.EXCEPTION, stack.getLiteralPath(), false, I18nConstants.SD_ED_TYPE_PROFILE_NOTYPE, p);
            } else {
                rule(errors, IssueType.EXCEPTION, stack.getLiteralPath(), sd.getKind() == StructureDefinitionKind.RESOURCE, I18nConstants.SD_ED_TYPE_PROFILE_WRONG_TARGET, p, t, code, path, "Resource");
            }
        }
    } else if (code.equals("canonical")) {
        if (warning(errors, IssueType.EXCEPTION, stack.getLiteralPath(), sd != null, I18nConstants.SD_ED_TYPE_PROFILE_UNKNOWN, p)) {
            StructureDefinition t = determineBaseType(sd);
            if (t == null) {
                rule(errors, IssueType.EXCEPTION, stack.getLiteralPath(), false, I18nConstants.SD_ED_TYPE_PROFILE_NOTYPE, p);
            } else if (!VersionUtilities.isR5Ver(context.getVersion())) {
                rule(errors, IssueType.EXCEPTION, stack.getLiteralPath(), VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(t.getType()) || "Resource".equals(t.getType()), I18nConstants.SD_ED_TYPE_PROFILE_WRONG_TARGET, p, t, code, path, "Canonical Resource");
            } else {
                rule(errors, IssueType.EXCEPTION, stack.getLiteralPath(), VersionUtilities.getCanonicalResourceNames(context.getVersion()).contains(t.getType()), I18nConstants.SD_ED_TYPE_PROFILE_WRONG_TARGET, p, t, code, path, "Canonical Resource");
            }
        }
    } else {
        rule(errors, IssueType.EXCEPTION, stack.getLiteralPath(), false, I18nConstants.SD_ED_TYPE_NO_TARGET_PROFILE, code);
    }
}
Also used : StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition)

Example 33 with CodeableReference

use of org.hl7.fhir.r4b.model.CodeableReference 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 34 with CodeableReference

use of org.hl7.fhir.r4b.model.CodeableReference in project kindling by HL7.

the class ProfileGenerator method defineElement.

/**
 * note: snapshot implies that we are generating a resource or a data type; for other profiles, the snapshot is generated elsewhere
 * @param isInterface
 */
private ElementDefinition defineElement(Profile ap, StructureDefinition p, List<ElementDefinition> elements, ElementDefn e, String path, Set<String> slices, List<SliceHandle> parentSlices, SnapShotMode snapshot, boolean root, String defType, String inheritedType, boolean defaults) throws Exception {
    boolean handleDiscriminator = true;
    if (!Utilities.noString(e.getProfileName()) && !e.getDiscriminator().isEmpty() && !slices.contains(path)) {
        handleDiscriminator = false;
        // hey, we jumped straight into the slices with setting up the slicing (allowed in the spreadsheets, but not otherwise)
        ElementDefinition slicer = new ElementDefinition();
        elements.add(slicer);
        slicer.setId(path);
        slicer.setPath(path);
        processDiscriminator(e, path, slicer);
        if (e.getMaxCardinality() != null)
            slicer.setMax(e.getMaxCardinality() == Integer.MAX_VALUE ? "*" : e.getMaxCardinality().toString());
        slices.add(path);
    }
    // todo for task 12259
    // if (ap != null) {
    // String base = isImplicitTypeConstraint(path);
    // if (base != null) {
    // ElementDefinition typeConstrainer = new ElementDefinition(ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    // elements.add(typeConstrainer);
    // typeConstrainer.setId(base);
    // typeConstrainer.setPath(base);
    // String type = path.substring(base.length()-3);
    // if (definitions.hasPrimitiveType(Utilities.uncapitalize(type)))
    // type = Utilities.uncapitalize(type);
    // typeConstrainer.addType().setCode(type);
    // }
    // }
    ElementDefinition ce = new ElementDefinition(defaults, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    elements.add(ce);
    if (e.getStandardsStatus() != null)
        ToolingExtensions.setStandardsStatus(ce, e.getStandardsStatus(), e.getNormativeVersion());
    ce.setId(path);
    ce.setPath(path);
    if (e.isXmlAttribute())
        ce.addRepresentation(PropertyRepresentation.XMLATTR);
    List<SliceHandle> myParents = new ArrayList<ProfileGenerator.SliceHandle>();
    myParents.addAll(parentSlices);
    // which holds Slicing information)
    if (e.hasDescriminator() || !Utilities.noString(e.getProfileName())) {
        if (e.getDiscriminator().size() > 0 && !slices.contains(path) && handleDiscriminator) {
            processDiscriminator(e, path, ce);
            slices.add(path);
        }
        if (!Utilities.noString(e.getProfileName())) {
            SliceHandle hnd = new SliceHandle();
            // though this it not used?
            hnd.name = path;
            myParents.add(hnd);
            if (path.contains(".")) {
                // We don't want a slice name on the root
                ce.setSliceName(e.getProfileName());
                ce.setId(ce.getId() + ":" + e.getProfileName());
            }
        }
    }
    if (e.isTranslatable()) {
        ce.addExtension(BuildExtensions.EXT_TRANSLATABLE, new BooleanType(true));
    }
    if (Utilities.existsInList(ce.getPath(), "Element.extension", "DomainResource.extension", "DomainResource.modifierExtension") && !ce.hasSlicing() && !ce.hasSliceName()) {
        ce.getSlicing().setDescription("Extensions are always sliced by (at least) url").setRules(SlicingRules.OPEN).addDiscriminator().setType(DiscriminatorType.VALUE).setPath("url");
    }
    if (!Utilities.noString(inheritedType) && snapshot != SnapShotMode.None) {
        ElementDefn inh = definitions.getElementDefn(inheritedType);
        buildDefinitionFromElement(path, ce, inh, ap, p, inheritedType, definitions.getBaseResources().containsKey(inheritedType) && definitions.getBaseResources().get(inheritedType).isInterface());
    } else if (path.contains(".") && Utilities.noString(e.typeCode()) && snapshot != SnapShotMode.None) {
        addElementConstraints(defType, ce);
    }
    buildDefinitionFromElement(path, ce, e, ap, p, null, false);
    if (!Utilities.noString(e.getStatedType())) {
        ToolingExtensions.addStringExtension(ce, "http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name", e.getStatedType());
    }
    if (e.isNoBindingAllowed()) {
        ToolingExtensions.addBooleanExtension(ce, BuildExtensions.EXT_NO_BINDING, true);
    }
    if (!root) {
        if (e.typeCode().startsWith("@")) {
            ce.setContentReference("#" + getIdForPath(elements, e.typeCode().substring(1)));
        } else if (Utilities.existsInList(path, "Element.id", "Extension.url") || path.endsWith(".id")) {
            TypeRefComponent tr = ce.addType();
            tr.getFormatCommentsPre().add("Note: special primitive values have a FHIRPath system type. e.g. this is compiler magic (j)");
            tr.setCode(Constants.NS_SYSTEM_TYPE + "String");
            if (path.equals("Extension.url")) {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "uri");
            } else if (p.getKind() == StructureDefinitionKind.RESOURCE) {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "id");
            } else {
                ToolingExtensions.addUriExtension(tr, ToolingExtensions.EXT_FHIR_TYPE, "string");
            }
        } else {
            List<TypeRef> expandedTypes = new ArrayList<TypeRef>();
            for (TypeRef t : e.getTypes()) {
                // Expand any Resource(A|B|C) references
                if (t.hasParams() && !Utilities.existsInList(t.getName(), "Reference", "canonical", "CodeableReference")) {
                    throw new Exception("Only resource types can specify parameters.  Path " + path + " in profile " + p.getName());
                }
                if (t.getParams().size() > 1) {
                    if (t.getProfile() != null && t.getParams().size() != 1) {
                        throw new Exception("Cannot declare profile on a resource reference declaring multiple resource types.  Path " + path + " in profile " + p.getName());
                    }
                    for (String param : t.getParams()) {
                        if (definitions.hasLogicalModel(param)) {
                            for (String pn : definitions.getLogicalModel(param).getImplementations()) {
                                TypeRef childType = new TypeRef(t.getName());
                                childType.getParams().add(pn);
                                childType.getAggregations().addAll(t.getAggregations());
                                expandedTypes.add(childType);
                            }
                        } else {
                            TypeRef childType = new TypeRef(t.getName());
                            childType.getParams().add(param);
                            childType.getAggregations().addAll(t.getAggregations());
                            expandedTypes.add(childType);
                        }
                    }
                } else if (t.isWildcardType()) {
                    // this list is filled out manually because it may be running before the types referred to have been loaded
                    for (String n : TypesUtilities.wildcardTypes(version.toString())) expandedTypes.add(new TypeRef(n));
                } else if (!t.getName().startsWith("=")) {
                    if (definitions.isLoaded() && (!definitions.hasResource(t.getName()) && !definitions.hasType(t.getName()) && !definitions.hasElementDefn(t.getName()) && !definitions.getBaseResources().containsKey(t.getName()) && !t.getName().equals("xhtml"))) {
                        throw new Exception("Bad Type '" + t.getName() + "' at " + path + " in profile " + p.getUrl());
                    }
                    expandedTypes.add(t);
                }
            }
            if (expandedTypes.isEmpty()) {
                if (defType != null)
                    ce.addType().setCode(defType);
            } else
                for (TypeRef t : expandedTypes) {
                    String profile = null;
                    String tc = null;
                    if (definitions.getConstraints().containsKey(t.getName())) {
                        ProfiledType pt = definitions.getConstraints().get(t.getName());
                        tc = pt.getBaseType();
                        profile = "http://hl7.org/fhir/StructureDefinition/" + pt.getName();
                    } else {
                        tc = t.getName();
                        profile = t.getProfile();
                    }
                    TypeRefComponent type = ce.getType(tc);
                    if (profile == null && t.hasParams()) {
                        profile = t.getParams().get(0);
                    }
                    if (t.getPatterns() != null) {
                        for (String s : t.getPatterns()) {
                            type.addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-pattern", new CanonicalType("http://hl7.org/fhir/StructureDefinition/" + s));
                        }
                    }
                    if (profile != null) {
                        if (type.getWorkingCode().equals("Extension")) {
                            // check that the extension is being used correctly:
                            StructureDefinition ext = context.getExtensionStructure(null, profile);
                            if (ext == null) {
                                throw new Exception("Unable to resolve extension definition: " + profile);
                            }
                            boolean srcMod = ext.getSnapshot().getElement().get(0).getIsModifier();
                            boolean tgtMod = e.isModifier();
                            if (srcMod && !tgtMod)
                                throw new Exception("The extension '" + profile + "' is a modifier extension, but is being used as if it is not a modifier extension");
                            if (!srcMod && tgtMod)
                                throw new Exception("The extension '" + profile + "' is not a modifier extension, but is being used as if it is a modifier extension");
                        }
                        List<String> pr = new ArrayList<>();
                        if (profile.startsWith("http:") || profile.startsWith("#")) {
                            pr.add(profile);
                        } else if (definitions.hasLogicalModel(profile)) {
                            for (String pn : definitions.getLogicalModel(profile).getImplementations()) pr.add("http://hl7.org/fhir/StructureDefinition/" + pn);
                        } else
                            pr.add("http://hl7.org/fhir/StructureDefinition/" + (profile.equals("Any") ? "Resource" : profile));
                        if (type.getWorkingCode().equals("Reference") || type.getWorkingCode().equals("canonical") || type.getWorkingCode().equals("CodeableReference")) {
                            for (String pn : pr) {
                                type.addTargetProfile(pn);
                                if (e.hasHierarchy())
                                    ToolingExtensions.addBooleanExtension(type, ToolingExtensions.EXT_HIERARCHY, e.getHierarchy());
                            }
                        } else
                            for (String pn : pr) {
                                type.addProfile(pn);
                            }
                    }
                    for (String aggregation : t.getAggregations()) {
                        type.addAggregation(AggregationMode.fromCode(aggregation));
                    }
                }
        }
    }
    String w5 = translateW5(e.getW5());
    if (w5 != null)
        addMapping(p, ce, "http://hl7.org/fhir/fivews", w5, ap);
    if (e.isTranslatable())
        ce.addExtension("http://hl7.org/fhir/StructureDefinition/elementdefinition-translatable", new BooleanType(true));
    if (!Utilities.noString(e.getOrderMeaning()))
        ce.setOrderMeaning(e.getOrderMeaning());
    if (e.hasBinding()) {
        ce.setBinding(generateBinding(e.getBinding()));
    }
    if (snapshot != SnapShotMode.None && !e.getElements().isEmpty()) {
    // makeExtensionSlice("extension", p, c, e, path);
    // if (snapshot == SnapShotMode.Resource) {
    // makeExtensionSlice("modifierExtension", p, c, e, path);
    // if (!path.contains(".")) {
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("Resource").getRoot().getElementByName("language")));
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("DomainResource").getRoot().getElementByName("text")));
    // c.getElement().add(createBaseDefinition(p, path, definitions.getBaseResources().get("DomainResource").getRoot().getElementByName("contained")));
    // }
    // }
    }
    if (defaults)
        ce.makeBase();
    Set<String> containedSlices = new HashSet<String>();
    if (snapshot != SnapShotMode.None) {
        if (!root && Utilities.noString(e.typeCode())) {
            if (snapshot == SnapShotMode.Resource)
                defineAncestorElements("BackboneElement", path, snapshot, containedSlices, p, elements, defType, defaults);
            else
                defineAncestorElements("Element", path, snapshot, containedSlices, p, elements, defType, defaults);
        } else if (root && !Utilities.noString(e.typeCode()))
            defineAncestorElements(e.typeCode(), path, snapshot, containedSlices, p, elements, defType, defaults);
    }
    for (ElementDefn child : e.getElements()) defineElement(ap, p, elements, child, path + "." + child.getName(), containedSlices, myParents, snapshot, false, defType, null, defaults);
    return ce;
}
Also used : ProfiledType(org.hl7.fhir.definitions.model.ProfiledType) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r5.model.BooleanType) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) FHIRException(org.hl7.fhir.exceptions.FHIRException) URISyntaxException(java.net.URISyntaxException) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) List(java.util.List) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) HashSet(java.util.HashSet)

Example 35 with CodeableReference

use of org.hl7.fhir.r4b.model.CodeableReference in project kindling by HL7.

the class ProfileGenerator method createBaseDefinition.

private ElementDefinition createBaseDefinition(StructureDefinition p, String path, ElementDefn src) throws Exception {
    ElementDefinition ce = new ElementDefinition(true, ElementDefinition.NOT_MODIFIER, ElementDefinition.NOT_IN_SUMMARY);
    ce.setId(path + "." + src.getName());
    ce.setPath(path + "." + src.getName());
    ce.setShort(src.getShortDefn());
    ce.setDefinition(preProcessMarkdown(src.getDefinition(), "ELement Definition"));
    ce.setComment(preProcessMarkdown(src.getComments(), "Element Comments"));
    ce.setRequirements(preProcessMarkdown(src.getRequirements(), "Element Reqiurements"));
    for (String a : src.getAliases()) ce.addAlias(a);
    ce.setMin(src.getMinCardinality());
    if (src.getMaxCardinality() != null)
        ce.setMax(src.getMaxCardinality() == Integer.MAX_VALUE ? "*" : src.getMaxCardinality().toString());
    ce.getType(src.typeCode());
    // this one should never be used
    if (!Utilities.noString(src.getTypes().get(0).getProfile())) {
        if (ce.getType().equals("Reference") || ce.getType().equals("canonical") || ce.getType().equals("CodeableReference"))
            throw new Error("Should not happen");
        ce.getType().get(0).addProfile(src.getTypes().get(0).getProfile());
    }
    // todo? conditions, constraints, binding, mapping
    if (src.hasModifier())
        ce.setIsModifier(src.isModifier());
    if (ce.getIsModifier())
        ce.setIsModifierReason(src.getModifierReason());
    if (src.hasSummaryItem())
        ce.setIsSummaryElement(Factory.newBoolean(src.isSummary()));
    for (Invariant id : src.getStatedInvariants()) ce.addCondition(id.getId());
    return ce;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition)

Aggregations

CodeableReference (org.hl7.fhir.r5.model.CodeableReference)58 CodeableConcept (org.hl7.fhir.r5.model.CodeableConcept)5 NotImplementedException (org.apache.commons.lang3.NotImplementedException)4 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)3 Annotation (org.hl7.fhir.r5.model.Annotation)3 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Base64 (org.apache.commons.codec.binary.Base64)2 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)2 Address (org.hl7.fhir.r4b.model.Address)2 Annotation (org.hl7.fhir.r4b.model.Annotation)2 Attachment (org.hl7.fhir.r4b.model.Attachment)2 Base (org.hl7.fhir.r4b.model.Base)2 Base64BinaryType (org.hl7.fhir.r4b.model.Base64BinaryType)2 BooleanType (org.hl7.fhir.r4b.model.BooleanType)2 CodeType (org.hl7.fhir.r4b.model.CodeType)2 CodeableConcept (org.hl7.fhir.r4b.model.CodeableConcept)2 CodeableReference (org.hl7.fhir.r4b.model.CodeableReference)2 Coding (org.hl7.fhir.r4b.model.Coding)2