Search in sources :

Example 36 with ElementDefinitionConstraintComponent

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

the class CSVWriter method itemList.

private String itemList(List l) {
    StringBuilder s = new StringBuilder();
    for (int i = 0; i < l.size(); i++) {
        Object o = l.get(i);
        String val = "";
        if (o instanceof StringType) {
            val = ((StringType) o).getValue();
        } else if (o instanceof UriType) {
            val = ((UriType) o).getValue();
        } else if (o instanceof IdType) {
            val = ((IdType) o).getValue();
        } else if (o instanceof Enumeration<?>) {
            val = o.toString();
        } else if (o instanceof TypeRefComponent) {
            TypeRefComponent t = (TypeRefComponent) o;
            val = t.getWorkingCode() + (t.getProfile() == null ? "" : " {" + t.getProfile() + "}") + (t.getTargetProfile() == null ? "" : " {" + t.getTargetProfile() + "}") + (t.getAggregation() == null || t.getAggregation().isEmpty() ? "" : " (" + itemList(t.getAggregation()) + ")");
        } else if (o instanceof Coding) {
            Coding t = (Coding) o;
            val = (t.getSystem() == null ? "" : t.getSystem()) + (t.getCode() == null ? "" : "#" + t.getCode()) + (t.getDisplay() == null ? "" : " (" + t.getDisplay() + ")");
        } else if (o instanceof ElementDefinitionConstraintComponent) {
            ElementDefinitionConstraintComponent c = (ElementDefinitionConstraintComponent) o;
            val = c.getKey() + ":" + c.getHuman() + " {" + c.getExpression() + "}";
        } else if (o instanceof ElementDefinitionSlicingDiscriminatorComponent) {
            ElementDefinitionSlicingDiscriminatorComponent c = (ElementDefinitionSlicingDiscriminatorComponent) o;
            val = c.getType().toCode() + ":" + c.getPath() + "}";
        } else {
            val = o.toString();
            val = val.substring(val.indexOf("[") + 1);
            val = val.substring(0, val.indexOf("]"));
        }
        s = s.append(val);
        if (i == 0)
            s.append("\n");
    }
    return s.toString();
}
Also used : ElementDefinitionSlicingDiscriminatorComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionSlicingDiscriminatorComponent) StringType(org.hl7.fhir.r4.model.StringType) TypeRefComponent(org.hl7.fhir.r4.model.ElementDefinition.TypeRefComponent) Coding(org.hl7.fhir.r4.model.Coding) ElementDefinitionConstraintComponent(org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent) UriType(org.hl7.fhir.r4.model.UriType) IdType(org.hl7.fhir.r4.model.IdType)

Example 37 with ElementDefinitionConstraintComponent

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

the class ProfileUtilitiesTests method testMinValueChange.

/**
 * Change min value
 */
@Test
void testMinValueChange() {
    // Given
    StructureDefinition focus = new StructureDefinition();
    StructureDefinition base = TestingUtilities.context().fetchResource(StructureDefinition.class, "http://hl7.org/fhir/StructureDefinition/Appointment").copy();
    focus.setUrl(Utilities.makeUuidUrn());
    focus.setBaseDefinition(base.getUrl());
    focus.setType(base.getType());
    focus.setDerivation(TypeDerivationRule.CONSTRAINT);
    ElementDefinition id = focus.getDifferential().addElement();
    id.setPath("Appointment.minutesDuration");
    id.setMinValue(new IntegerType(1));
    List<ValidationMessage> messages = new ArrayList<>();
    // When
    new ProfileUtilities(TestingUtilities.context(), messages, null).generateSnapshot(base, focus, focus.getUrl(), "http://test.org", "Simple Test");
    // Then
    boolean ok = base.getSnapshot().getElement().size() == focus.getSnapshot().getElement().size();
    for (int i = 0; i < base.getSnapshot().getElement().size(); i++) {
        if (ok) {
            ElementDefinition b = base.getSnapshot().getElement().get(i);
            ElementDefinition f = focus.getSnapshot().getElement().get(i);
            b.setRequirements(null);
            f.setRequirements(null);
            for (ElementDefinitionConstraintComponent c : b.getConstraint()) {
                c.setSource(null);
            }
            for (ElementDefinitionConstraintComponent c : f.getConstraint()) {
                c.setSource(null);
            }
            if (!f.hasBase() || !b.getPath().equals(f.getPath())) {
                ok = false;
            } else {
                if (f.getPath().equals("Appointment.minutesDuration")) {
                    ok = f.getMinValue() instanceof IntegerType && ((IntegerType) f.getMinValue()).getValue() == 1;
                    if (ok) {
                        // Can't set minValue to null so change base minValue to IntegerType(1)
                        b.setMinValue(new IntegerType(1));
                    }
                }
                if (!Base.compareDeep(b, f, true)) {
                    ok = false;
                }
            }
        }
    }
    Assertions.assertTrue(ok);
}
Also used : IntegerType(org.hl7.fhir.r4b.model.IntegerType) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage) ProfileUtilities(org.hl7.fhir.r4b.conformance.ProfileUtilities) ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent) Test(org.junit.jupiter.api.Test)

Example 38 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project kindling by HL7.

the class SpreadSheetReloader method parseInvariants.

private void parseInvariants(XSSFSheet invariants, ElementDefinition ed) throws Exception {
    List<ElementDefinitionConstraintComponent> oldInvs = ed.getConstraint();
    ed.setConstraint(new ArrayList<>());
    XSSFRow cols = invariants.getRow(0);
    for (int i = 1; i <= invariants.getLastRowNum(); i++) {
        XSSFRow row = invariants.getRow(i);
        if (row != null && hasValue(row, cols, CN_CONTEXT) && ed.getPath().equals(getValue(row, cols, CN_CONTEXT))) {
            String n = getValue(row, cols, CN_ID);
            ElementDefinitionConstraintComponent inv = getInv(oldInvs, n);
            ed.getConstraint().add(inv);
            readInvariant(row, cols, inv);
        }
    }
}
Also used : XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 39 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project kindling by HL7.

the class SpreadSheetReloader method getInv.

private ElementDefinitionConstraintComponent getInv(List<ElementDefinitionConstraintComponent> list, String n) {
    for (ElementDefinitionConstraintComponent t : list) {
        if (n.equals(t.getKey())) {
            return t;
        }
    }
    ElementDefinitionConstraintComponent t = new ElementDefinitionConstraintComponent();
    t.setKey(n);
    return t;
}
Also used : ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Example 40 with ElementDefinitionConstraintComponent

use of org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent in project kindling by HL7.

the class ProfileGenerator method makeExtensionSlice.

private ElementDefinition makeExtensionSlice(String extensionName, StructureDefinition p, StructureDefinitionSnapshotComponent c, ElementDefn e, String path) throws URISyntaxException, Exception {
    ElementDefinition ex = createBaseDefinition(p, path, definitions.getBaseResources().get("DomainResource").getRoot().getElementByName(definitions, extensionName, false, false, null));
    c.getElement().add(ex);
    if (!ex.hasBase())
        ex.setBase(new ElementDefinitionBaseComponent());
    ex.getBase().setPath("Element.extension");
    ex.getBase().setMin(0);
    ex.getBase().setMax("*");
    ElementDefinitionConstraintComponent inv = ex.addConstraint();
    inv.setKey("ext-1");
    inv.setSeverity(ConstraintSeverity.ERROR);
    inv.setHuman("Must have either extensions or value[x], not both");
    inv.setExpression("extension.exists() != value.exists()");
    inv.setXpath("exists(f:extension)!=exists(f:*[starts-with(local-name(.), 'value')])");
    inv.setSource("http://hl7.org/fhir/StructureDefinition/Extension");
    return ex;
}
Also used : ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionBaseComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBaseComponent) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)

Aggregations

ElementDefinitionConstraintComponent (org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent)31 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)25 ArrayList (java.util.ArrayList)23 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)16 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)15 ElementDefinitionConstraintComponent (org.hl7.fhir.r4b.model.ElementDefinition.ElementDefinitionConstraintComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)10 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)9 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)9 Test (org.junit.jupiter.api.Test)8 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)7 ElementDefinitionConstraintComponent (org.hl7.fhir.r4.model.ElementDefinition.ElementDefinitionConstraintComponent)7 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)7 Rule (org.hl7.fhir.utilities.xml.SchematronWriter.Rule)7 Section (org.hl7.fhir.utilities.xml.SchematronWriter.Section)7 IOException (java.io.IOException)6