Search in sources :

Example 26 with DefinitionNavigator

use of org.hl7.fhir.dstu3.utils.DefinitionNavigator in project org.hl7.fhir.core by hapifhir.

the class DefinitionNavigator method loadTypedChildren.

private void loadTypedChildren(TypeRefComponent type) throws DefinitionException {
    typeOfChildren = null;
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, type.hasProfile() ? type.getProfile().get(0).getValue() : type.getCode());
    if (sd != null) {
        DefinitionNavigator dn = new DefinitionNavigator(context, sd, 0, path, names, sd.getBaseType());
        typeChildren = dn.children();
    } else
        throw new DefinitionException("Unable to find definition for " + type.getCode() + (type.hasProfile() ? "(" + type.getProfile() + ")" : ""));
    typeOfChildren = type;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 27 with DefinitionNavigator

use of org.hl7.fhir.dstu3.utils.DefinitionNavigator in project org.hl7.fhir.core by hapifhir.

the class DefinitionNavigator method loadTypedChildren.

private void loadTypedChildren(TypeRefComponent type) throws DefinitionException {
    typeOfChildren = null;
    StructureDefinition sd = context.fetchResource(StructureDefinition.class, /* GF#13465 : this somehow needs to be revisited type.hasProfile() ? type.getProfile() : */
    type.getWorkingCode());
    if (sd != null) {
        DefinitionNavigator dn = new DefinitionNavigator(context, sd, 0, path, names, sd.getType());
        typeChildren = dn.children();
    } else
        throw new DefinitionException("Unable to find definition for " + type.getWorkingCode() + (type.hasProfile() ? "(" + type.getProfile() + ")" : ""));
    typeOfChildren = type;
}
Also used : StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 28 with DefinitionNavigator

use of org.hl7.fhir.dstu3.utils.DefinitionNavigator in project org.hl7.fhir.core by hapifhir.

the class DefinitionNavigator method loadChildren.

private void loadChildren() throws DefinitionException {
    children = new ArrayList<DefinitionNavigator>();
    String prefix = current().getPath() + ".";
    Map<String, DefinitionNavigator> nameMap = new HashMap<String, DefinitionNavigator>();
    for (int i = index + 1; i < structure.getSnapshot().getElement().size(); i++) {
        String path = structure.getSnapshot().getElement().get(i).getPath();
        if (path.startsWith(prefix) && !path.substring(prefix.length()).contains(".")) {
            DefinitionNavigator dn = new DefinitionNavigator(context, structure, i, this.path + "." + tail(path), names, null);
            if (nameMap.containsKey(path)) {
                DefinitionNavigator master = nameMap.get(path);
                if (!master.current().hasSlicing())
                    throw new DefinitionException("Found slices with no slicing details at " + dn.current().getPath());
                if (master.slices == null)
                    master.slices = new ArrayList<DefinitionNavigator>();
                master.slices.add(dn);
            } else {
                nameMap.put(path, dn);
                children.add(dn);
            }
        } else if (path.length() < prefix.length())
            break;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 29 with DefinitionNavigator

use of org.hl7.fhir.dstu3.utils.DefinitionNavigator in project org.hl7.fhir.core by hapifhir.

the class ProfileComparer method compareProfiles.

/**
 * Compare left and right structure definitions to see whether they are consistent or not
 *
 * Note that left and right are arbitrary choices. In one respect, left
 * is 'preferred' - the left's example value and data sets will be selected
 * over the right ones in the common structure definition
 * @throws DefinitionException
 * @throws IOException
 *
 * @
 */
public ProfileComparison compareProfiles(StructureDefinition left, StructureDefinition right) throws DefinitionException, IOException {
    ProfileComparison outcome = new ProfileComparison();
    outcome.left = left;
    outcome.right = right;
    if (left == null)
        throw new DefinitionException("No StructureDefinition provided (left)");
    if (right == null)
        throw new DefinitionException("No StructureDefinition provided (right)");
    if (!left.hasSnapshot())
        throw new DefinitionException("StructureDefinition has no snapshot (left: " + outcome.leftName() + ")");
    if (!right.hasSnapshot())
        throw new DefinitionException("StructureDefinition has no snapshot (right: " + outcome.rightName() + ")");
    if (left.getSnapshot().getElement().isEmpty())
        throw new DefinitionException("StructureDefinition snapshot is empty (left: " + outcome.leftName() + ")");
    if (right.getSnapshot().getElement().isEmpty())
        throw new DefinitionException("StructureDefinition snapshot is empty (right: " + outcome.rightName() + ")");
    for (ProfileComparison pc : comparisons) if (pc.left.getUrl().equals(left.getUrl()) && pc.right.getUrl().equals(right.getUrl()))
        return pc;
    outcome.id = Integer.toString(comparisons.size() + 1);
    comparisons.add(outcome);
    DefinitionNavigator ln = new DefinitionNavigator(context, left);
    DefinitionNavigator rn = new DefinitionNavigator(context, right);
    // from here on in, any issues go in messages
    outcome.superset = new StructureDefinition();
    outcome.subset = new StructureDefinition();
    if (outcome.ruleEqual(ln.path(), null, ln.path(), rn.path(), "Base Type is not compatible", false)) {
        if (compareElements(outcome, ln.path(), ln, rn)) {
            outcome.subset.setName("intersection of " + outcome.leftName() + " and " + outcome.rightName());
            outcome.subset.setStatus(ConformanceResourceStatus.DRAFT);
            outcome.subset.setKind(outcome.left.getKind());
            outcome.subset.setConstrainedType(outcome.left.getConstrainedType());
            outcome.subset.setBase("http://hl7.org/fhir/StructureDefinition/" + outcome.subset.getConstrainedType());
            outcome.subset.setAbstract(false);
            outcome.superset.setName("union of " + outcome.leftName() + " and " + outcome.rightName());
            outcome.superset.setStatus(ConformanceResourceStatus.DRAFT);
            outcome.superset.setKind(outcome.left.getKind());
            outcome.superset.setConstrainedType(outcome.left.getConstrainedType());
            outcome.superset.setBase("http://hl7.org/fhir/StructureDefinition/" + outcome.subset.getConstrainedType());
            outcome.superset.setAbstract(false);
        } else {
            outcome.subset = null;
            outcome.superset = null;
        }
    }
    return outcome;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 30 with DefinitionNavigator

use of org.hl7.fhir.dstu3.utils.DefinitionNavigator in project org.hl7.fhir.core by hapifhir.

the class ProfileComparer method compareProfiles.

/**
 * Compare left and right structure definitions to see whether they are consistent or not
 *
 * Note that left and right are arbitrary choices. In one respect, left
 * is 'preferred' - the left's example value and data sets will be selected
 * over the right ones in the common structure definition
 * @throws DefinitionException
 * @throws IOException
 *
 * @
 */
public ProfileComparison compareProfiles(StructureDefinition left, StructureDefinition right) throws DefinitionException, IOException {
    ProfileComparison outcome = new ProfileComparison();
    outcome.left = left;
    outcome.right = right;
    if (left == null)
        throw new DefinitionException("No StructureDefinition provided (left)");
    if (right == null)
        throw new DefinitionException("No StructureDefinition provided (right)");
    if (!left.hasSnapshot())
        throw new DefinitionException("StructureDefinition has no snapshot (left: " + outcome.leftName() + ")");
    if (!right.hasSnapshot())
        throw new DefinitionException("StructureDefinition has no snapshot (right: " + outcome.rightName() + ")");
    if (left.getSnapshot().getElement().isEmpty())
        throw new DefinitionException("StructureDefinition snapshot is empty (left: " + outcome.leftName() + ")");
    if (right.getSnapshot().getElement().isEmpty())
        throw new DefinitionException("StructureDefinition snapshot is empty (right: " + outcome.rightName() + ")");
    for (ProfileComparison pc : comparisons) if (pc.left.getUrl().equals(left.getUrl()) && pc.right.getUrl().equals(right.getUrl()))
        return pc;
    outcome.id = Integer.toString(comparisons.size() + 1);
    comparisons.add(outcome);
    DefinitionNavigator ln = new DefinitionNavigator(context, left);
    DefinitionNavigator rn = new DefinitionNavigator(context, right);
    // from here on in, any issues go in messages
    outcome.superset = new StructureDefinition();
    outcome.subset = new StructureDefinition();
    if (outcome.ruleEqual(ln.path(), null, ln.path(), rn.path(), "Base Type is not compatible", false)) {
        if (compareElements(outcome, ln.path(), ln, rn)) {
            outcome.subset.setName("intersection of " + outcome.leftName() + " and " + outcome.rightName());
            outcome.subset.setStatus(ConformanceResourceStatus.DRAFT);
            outcome.subset.setKind(outcome.left.getKind());
            outcome.subset.setBaseType(outcome.left.getBaseType());
            outcome.subset.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + outcome.subset.getBaseType());
            outcome.subset.setDerivation(TypeDerivationRule.CONSTRAINT);
            outcome.subset.setAbstract(false);
            outcome.superset.setName("union of " + outcome.leftName() + " and " + outcome.rightName());
            outcome.superset.setStatus(ConformanceResourceStatus.DRAFT);
            outcome.superset.setKind(outcome.left.getKind());
            outcome.superset.setBaseType(outcome.left.getBaseType());
            outcome.superset.setBaseDefinition("http://hl7.org/fhir/StructureDefinition/" + outcome.subset.getBaseType());
            outcome.superset.setAbstract(false);
            outcome.superset.setDerivation(TypeDerivationRule.CONSTRAINT);
        } else {
            outcome.subset = null;
            outcome.superset = null;
        }
    }
    return outcome;
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)20 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)4 Date (java.util.Date)2 StructureDefinition (org.hl7.fhir.dstu2.model.StructureDefinition)2 StructureDefinition (org.hl7.fhir.dstu2016may.model.StructureDefinition)2 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)2 DefinitionNavigator (org.hl7.fhir.dstu3.utils.DefinitionNavigator)2 StructureDefinition (org.hl7.fhir.r4.model.StructureDefinition)2 DefinitionNavigator (org.hl7.fhir.r4.utils.DefinitionNavigator)2 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)2 DefinitionNavigator (org.hl7.fhir.r4b.utils.DefinitionNavigator)2 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)2 DefinitionNavigator (org.hl7.fhir.r5.utils.DefinitionNavigator)2 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)1 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)1 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)1 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)1 ElementDefinitionSlicingComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionSlicingComponent)1