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();
}
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);
}
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);
}
}
}
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;
}
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;
}
Aggregations