Search in sources :

Example 66 with ElementDefinition

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

the class RdfParser method composeElementDefinitionTypeRefComponent.

protected void composeElementDefinitionTypeRefComponent(Complex parent, String parentType, String name, ElementDefinition.TypeRefComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeElement(t, "type", name, element, index);
    if (element.hasCodeElement())
        composeUri(t, "ElementDefinition", "code", element.getCodeElement(), -1);
    if (element.hasProfileElement())
        composeUri(t, "ElementDefinition", "profile", element.getProfileElement(), -1);
    if (element.hasTargetProfileElement())
        composeUri(t, "ElementDefinition", "targetProfile", element.getTargetProfileElement(), -1);
    for (int i = 0; i < element.getAggregation().size(); i++) composeEnum(t, "ElementDefinition", "aggregation", element.getAggregation().get(i), i);
    if (element.hasVersioningElement())
        composeEnum(t, "ElementDefinition", "versioning", element.getVersioningElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Example 67 with ElementDefinition

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

the class StructureDefinition14_40 method convertStructureDefinition.

public static org.hl7.fhir.r4.model.StructureDefinition convertStructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r4.model.StructureDefinition tgt = new org.hl7.fhir.r4.model.StructureDefinition();
    ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyDomainResource(src, tgt);
    if (src.hasUrl())
        tgt.setUrlElement(Uri14_40.convertUri(src.getUrlElement()));
    for (org.hl7.fhir.dstu2016may.model.Identifier t : src.getIdentifier()) tgt.addIdentifier(Identifier14_40.convertIdentifier(t));
    if (src.hasVersion())
        tgt.setVersionElement(String14_40.convertString(src.getVersionElement()));
    if (src.hasNameElement())
        tgt.setNameElement(String14_40.convertString(src.getNameElement()));
    if (src.hasDisplay())
        tgt.setTitleElement(String14_40.convertString(src.getDisplayElement()));
    if (src.hasStatus())
        tgt.setStatusElement(Enumerations14_40.convertConformanceResourceStatus(src.getStatusElement()));
    if (src.hasExperimental())
        tgt.setExperimentalElement(Boolean14_40.convertBoolean(src.getExperimentalElement()));
    if (src.hasPublisher())
        tgt.setPublisherElement(String14_40.convertString(src.getPublisherElement()));
    for (org.hl7.fhir.dstu2016may.model.StructureDefinition.StructureDefinitionContactComponent t : src.getContact()) tgt.addContact(convertStructureDefinitionContactComponent(t));
    if (src.hasDate())
        tgt.setDateElement(DateTime14_40.convertDateTime(src.getDateElement()));
    if (src.hasDescription())
        tgt.setDescription(src.getDescription());
    for (org.hl7.fhir.dstu2016may.model.CodeableConcept t : src.getUseContext()) if (VersionConvertor_14_40.isJurisdiction(t))
        tgt.addJurisdiction(CodeableConcept14_40.convertCodeableConcept(t));
    else
        tgt.addUseContext(CodeableConcept14_40.convertCodeableConceptToUsageContext(t));
    if (src.hasRequirements())
        tgt.setPurpose(src.getRequirements());
    if (src.hasCopyright())
        tgt.setCopyright(src.getCopyright());
    for (org.hl7.fhir.dstu2016may.model.Coding t : src.getCode()) tgt.addKeyword(Coding14_40.convertCoding(t));
    if (src.hasFhirVersion())
        tgt.setFhirVersion(org.hl7.fhir.r4.model.Enumerations.FHIRVersion.fromCode(src.getFhirVersion()));
    for (org.hl7.fhir.dstu2016may.model.StructureDefinition.StructureDefinitionMappingComponent t : src.getMapping()) tgt.addMapping(convertStructureDefinitionMappingComponent(t));
    if (src.hasKind())
        tgt.setKindElement(convertStructureDefinitionKind(src.getKindElement(), src.getName()));
    if (src.hasAbstractElement())
        tgt.setAbstractElement(Boolean14_40.convertBoolean(src.getAbstractElement()));
    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getContext()) {
        org.hl7.fhir.r4.model.StructureDefinition.StructureDefinitionContextComponent ec = tgt.addContext();
        ec.setTypeElement(convertExtensionContext(src.getContextTypeElement()));
        ec.setExpression("*".equals(t.getValue()) ? "Element" : t.getValue());
    }
    if (src.getDerivation() == org.hl7.fhir.dstu2016may.model.StructureDefinition.TypeDerivationRule.CONSTRAINT)
        tgt.setType(src.getBaseType());
    else
        tgt.setType(src.getId());
    if (src.hasBaseDefinition())
        tgt.setBaseDefinition(src.getBaseDefinition());
    if (src.hasDerivation())
        tgt.setDerivationElement(convertTypeDerivationRule(src.getDerivationElement()));
    if (src.hasSnapshot()) {
        if (src.hasSnapshot())
            tgt.setSnapshot(convertStructureDefinitionSnapshotComponent(src.getSnapshot()));
        tgt.getSnapshot().getElementFirstRep().getType().clear();
    }
    if (src.hasDifferential()) {
        if (src.hasDifferential())
            tgt.setDifferential(convertStructureDefinitionDifferentialComponent(src.getDifferential()));
        tgt.getDifferential().getElementFirstRep().getType().clear();
    }
    if (tgt.getDerivation() == TypeDerivationRule.SPECIALIZATION) {
        for (ElementDefinition ed : tgt.getSnapshot().getElement()) {
            if (!ed.hasBase()) {
                ed.getBase().setPath(ed.getPath()).setMin(ed.getMin()).setMax(ed.getMax());
            }
        }
    }
    return tgt;
}
Also used : ElementDefinition(org.hl7.fhir.r4.model.ElementDefinition)

Example 68 with ElementDefinition

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

the class ElementDefinition14_50 method convertElementDefinition.

public static ElementDefinition convertElementDefinition(org.hl7.fhir.r5.model.ElementDefinition src) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    ElementDefinition tgt = new ElementDefinition();
    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
    if (src.hasPathElement())
        tgt.setPathElement(String14_50.convertString(src.getPathElement()));
    tgt.setRepresentation(src.getRepresentation().stream().map(ElementDefinition14_50::convertPropertyRepresentation).collect(Collectors.toList()));
    if (src.hasSliceName())
        tgt.setNameElement(String14_50.convertString(src.getSliceNameElement()));
    if (src.hasLabel())
        tgt.setLabelElement(String14_50.convertString(src.getLabelElement()));
    for (org.hl7.fhir.r5.model.Coding t : src.getCode()) tgt.addCode(Coding14_50.convertCoding(t));
    if (src.hasSlicing())
        tgt.setSlicing(convertElementDefinitionSlicingComponent(src.getSlicing()));
    if (src.hasShort())
        tgt.setShortElement(String14_50.convertString(src.getShortElement()));
    if (src.hasDefinition())
        tgt.setDefinitionElement(MarkDown14_50.convertMarkdown(src.getDefinitionElement()));
    if (src.hasComment())
        tgt.setCommentsElement(MarkDown14_50.convertMarkdown(src.getCommentElement()));
    if (src.hasRequirements())
        tgt.setRequirementsElement(MarkDown14_50.convertMarkdown(src.getRequirementsElement()));
    for (org.hl7.fhir.r5.model.StringType t : src.getAlias()) tgt.addAlias(t.getValue());
    if (src.hasMin())
        tgt.setMin(src.getMin());
    if (src.hasMax())
        tgt.setMaxElement(String14_50.convertString(src.getMaxElement()));
    if (src.hasBase())
        tgt.setBase(convertElementDefinitionBaseComponent(src.getBase()));
    if (src.hasContentReference())
        tgt.setContentReferenceElement(Uri14_50.convertUri(src.getContentReferenceElement()));
    for (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent t : src.getType()) convertTypeRefComponent(t, tgt.getType());
    if (src.hasDefaultValue())
        tgt.setDefaultValue(ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getDefaultValue()));
    if (src.hasMeaningWhenMissing())
        tgt.setMeaningWhenMissingElement(MarkDown14_50.convertMarkdown(src.getMeaningWhenMissingElement()));
    if (src.hasFixed())
        tgt.setFixed(ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getFixed()));
    if (src.hasPattern())
        tgt.setPattern(ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getPattern()));
    if (src.hasExample())
        tgt.setExample(ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getExample().get(0).getValue()));
    if (src.hasMinValue())
        tgt.setMinValue(ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getMinValue()));
    if (src.hasMaxValue())
        tgt.setMaxValue(ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().convertType(src.getMaxValue()));
    if (src.hasMaxLength())
        tgt.setMaxLengthElement(Integer14_50.convertInteger(src.getMaxLengthElement()));
    for (org.hl7.fhir.r5.model.IdType t : src.getCondition()) tgt.addCondition(t.getValue());
    for (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent t : src.getConstraint()) tgt.addConstraint(convertElementDefinitionConstraintComponent(t));
    if (src.hasMustSupport())
        tgt.setMustSupportElement(Boolean14_50.convertBoolean(src.getMustSupportElement()));
    if (src.hasIsModifier())
        tgt.setIsModifierElement(Boolean14_50.convertBoolean(src.getIsModifierElement()));
    if (src.hasIsModifierReason() && !VersionConvertorConstants.MODIFIER_REASON_LEGACY.equals(src.getIsModifierReason()))
        org.hl7.fhir.dstu2016may.utils.ToolingExtensions.setStringExtension(tgt, VersionConvertorConstants.MODIFIER_REASON_EXTENSION, src.getIsModifierReason());
    if (src.hasIsSummary())
        tgt.setIsSummaryElement(Boolean14_50.convertBoolean(src.getIsSummaryElement()));
    if (src.hasBinding())
        tgt.setBinding(convertElementDefinitionBindingComponent(src.getBinding()));
    for (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent t : src.getMapping()) tgt.addMapping(convertElementDefinitionMappingComponent(t));
    return tgt;
}
Also used : ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition)

Example 69 with ElementDefinition

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

the class ElementDefinition14_50 method convertElementDefinitionSlicingComponent.

/*
   * This process deals with the fact that 'exists' slicing didn't have a mechanism to flag it in 2016May.
   * (Pattern and profile both had '@' flags in the discriminator to distinguish this, but exists did not.)
   * 'Exists' can thus only be determined by looking at the available slices - and checking to see that there
   * are exactly two slices, one which is mandatory and one which is prohibited.  We need to do that check
   * at the level where the slices are defined, rather than only inside the 'slicing' element where we don't
   * have access to the slices themselves.
   *
   * This process checks to see if we have a 'value' discriminator (i.e. no '@') and if so, checks for all
   * matching slices.  If there are exactly two and one's required and one's prohibited, then it sets a flag
   * so that the converter will declare a discriminator.type of 'exists'.
   *
   * Note that we only need complex processing on the R2B -> newer release, not on the reverse.  On the reverse,
   * we just strip the discriminator type.  What slices exist is still the same.  In theory, that means that the
   * exists type is unnecessary, but it's far more efficient (and clear) to have it.
   */
public static org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent convertElementDefinitionSlicingComponent(ElementDefinition.ElementDefinitionSlicingComponent src, List<ElementDefinition> context, int pos) throws FHIRException {
    if (src == null || src.isEmpty())
        return null;
    org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent tgt = new org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionSlicingComponent();
    ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
    ElementDefinition slicingElement = context.get(pos);
    for (org.hl7.fhir.dstu2016may.model.StringType t : src.getDiscriminator()) {
        boolean isExists = false;
        if (!t.asStringValue().contains("@")) {
            int slices = 0;
            boolean existsSlicePresent = false;
            boolean notExistsSlicePresent = false;
            String url = null;
            String existsPath = slicingElement.getPath() + "." + t.asStringValue();
            if (existsPath.contains(".extension(")) {
                String suffix = StringUtils.substringAfter(existsPath, "(").substring(1);
                existsPath = StringUtils.substringBefore(existsPath, "(");
                suffix = StringUtils.substringBefore(suffix, ")");
                url = suffix.substring(0, suffix.length() - 1);
            }
            for (int i = pos + 1; i < context.size(); i++) {
                ElementDefinition e = context.get(i);
                if (e.getPath().equals(slicingElement.getPath()))
                    slices++;
                else if (!e.getPath().startsWith(slicingElement.getPath() + "."))
                    break;
                else if (e.getPath().equals(existsPath)) {
                    if (url == null || (e.getType().get(0).hasProfile() && e.getType().get(0).getProfile().get(0).equals(url))) {
                        if (e.hasMin() && e.getMin() > 0 && !e.hasFixed())
                            existsSlicePresent = true;
                        else if (e.hasMax() && e.getMax().equals("0"))
                            notExistsSlicePresent = true;
                    }
                }
            }
            isExists = (slices == 2 && existsSlicePresent && notExistsSlicePresent) || (slices == 1 && existsSlicePresent != notExistsSlicePresent);
        }
        tgt.addDiscriminator(ProfileUtilities.interpretR2Discriminator(t.getValue(), isExists));
    }
    if (src.hasDescription())
        tgt.setDescriptionElement(String14_50.convertString(src.getDescriptionElement()));
    if (src.hasOrdered())
        tgt.setOrderedElement(Boolean14_50.convertBoolean(src.getOrderedElement()));
    if (src.hasRules())
        tgt.setRulesElement(convertSlicingRules(src.getRulesElement()));
    return tgt;
}
Also used : ElementDefinition(org.hl7.fhir.dstu2016may.model.ElementDefinition)

Example 70 with ElementDefinition

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

the class R2016MayToR5Loader method loadResource.

@Override
public org.hl7.fhir.r5.model.Resource loadResource(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2016may = null;
    if (isJson)
        r2016may = new JsonParser().parse(stream);
    else
        r2016may = new XmlParser().parse(stream);
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_14_50.convertResource(r2016may);
    setPath(r5);
    if (!advisor.getCslist().isEmpty()) {
        throw new FHIRException("Error: Cannot have included code systems");
    }
    if (killPrimitives) {
        throw new FHIRException("Cannot kill primitives when using deferred loading");
    }
    if (patchUrls) {
        if (r5 instanceof StructureDefinition) {
            StructureDefinition sd = (StructureDefinition) r5;
            sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
            sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
            for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
        }
    }
    return r5;
}
Also used : XmlParser(org.hl7.fhir.dstu2016may.formats.XmlParser) Resource(org.hl7.fhir.dstu2016may.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException) JsonParser(org.hl7.fhir.dstu2016may.formats.JsonParser)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37