use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method testMaxValueChange.
/**
* Change max value
*/
@Test
void testMaxValueChange() {
// 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.setMaxValue(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.getMaxValue() instanceof IntegerType && ((IntegerType) f.getMaxValue()).getValue() == 1;
if (ok) {
// Can't set maxValue to null so change base maxValue to IntegerType(1)
b.setMaxValue(new IntegerType(1));
}
}
if (!Base.compareDeep(b, f, true)) {
ok = false;
}
}
}
}
Assertions.assertTrue(ok);
}
use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class IntegerTypeNullTest method testToString.
@Test
@DisplayName("Test null value toString()")
void testToString() {
IntegerType nullInteger = new IntegerType();
System.out.println("Value -> " + nullInteger);
}
use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method buildFixedExpression.
private void buildFixedExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
DataType fixed = criteriaElement.getFixed();
if (fixed instanceof CodeableConcept) {
CodeableConcept cc = (CodeableConcept) fixed;
expression.append(" and ");
buildCodeableConceptExpression(ed, expression, discriminator, cc);
} else if (fixed instanceof Identifier) {
Identifier ii = (Identifier) fixed;
expression.append(" and ");
buildIdentifierExpression(ed, expression, discriminator, ii);
} else if (fixed instanceof Coding) {
Coding c = (Coding) fixed;
expression.append(" and ");
buildCodingExpression(ed, expression, discriminator, c);
} else {
expression.append(" and (");
if (fixed instanceof StringType) {
Gson gson = new Gson();
String json = gson.toJson((StringType) fixed);
String escapedString = json.substring(json.indexOf(":") + 2);
escapedString = escapedString.substring(0, escapedString.indexOf(",\"myStringValue") - 1);
expression.append("'" + escapedString + "'");
} else if (fixed instanceof UriType) {
expression.append("'" + ((UriType) fixed).asStringValue() + "'");
} else if (fixed instanceof IntegerType) {
expression.append(((IntegerType) fixed).asStringValue());
} else if (fixed instanceof DecimalType) {
expression.append(((IntegerType) fixed).asStringValue());
} else if (fixed instanceof BooleanType) {
expression.append(((BooleanType) fixed).asStringValue());
} else
throw new DefinitionException(context.formatMessage(I18nConstants.UNSUPPORTED_FIXED_VALUE_TYPE_FOR_DISCRIMINATOR_FOR_SLICE__, discriminator, ed.getId(), fixed.getClass().getName()));
expression.append(" in " + discriminator + ")");
}
}
use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class InstanceValidator method buildPattternExpression.
private void buildPattternExpression(ElementDefinition ed, StringBuilder expression, String discriminator, ElementDefinition criteriaElement) throws DefinitionException {
DataType pattern = criteriaElement.getPattern();
if (pattern instanceof CodeableConcept) {
CodeableConcept cc = (CodeableConcept) pattern;
expression.append(" and ");
buildCodeableConceptExpression(ed, expression, discriminator, cc);
} else if (pattern instanceof Coding) {
Coding c = (Coding) pattern;
expression.append(" and ");
buildCodingExpression(ed, expression, discriminator, c);
} else if (pattern instanceof BooleanType || pattern instanceof IntegerType || pattern instanceof DecimalType) {
expression.append(" and ");
buildPrimitiveExpression(ed, expression, discriminator, pattern, false);
} else if (pattern instanceof PrimitiveType) {
expression.append(" and ");
buildPrimitiveExpression(ed, expression, discriminator, pattern, true);
} else if (pattern instanceof Identifier) {
Identifier ii = (Identifier) pattern;
expression.append(" and ");
buildIdentifierExpression(ed, expression, discriminator, ii);
} else if (pattern instanceof HumanName) {
HumanName name = (HumanName) pattern;
expression.append(" and ");
buildHumanNameExpression(ed, expression, discriminator, name);
} else if (pattern instanceof Address) {
Address add = (Address) pattern;
expression.append(" and ");
buildAddressExpression(ed, expression, discriminator, add);
} else {
throw new DefinitionException(context.formatMessage(I18nConstants.UNSUPPORTED_FIXED_PATTERN_TYPE_FOR_DISCRIMINATOR_FOR_SLICE__, discriminator, ed.getId(), pattern.fhirType()));
}
}
use of org.hl7.fhir.r4.model.IntegerType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method opMinus.
private List<Base> opMinus(List<Base> left, List<Base> right) throws PathEngineException {
if (left.size() == 0)
throw new PathEngineException("Error performing -: left operand has no value");
if (left.size() > 1)
throw new PathEngineException("Error performing -: left operand has more than one value");
if (!left.get(0).isPrimitive())
throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType()));
if (right.size() == 0)
throw new PathEngineException("Error performing -: right operand has no value");
if (right.size() > 1)
throw new PathEngineException("Error performing -: right operand has more than one value");
if (!right.get(0).isPrimitive())
throw new PathEngineException(String.format("Error performing -: right operand has the wrong type (%s)", right.get(0).fhirType()));
List<Base> result = new ArrayList<Base>();
Base l = left.get(0);
Base r = right.get(0);
if (l.hasType("integer") && r.hasType("integer"))
result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) - Integer.parseInt(r.primitiveValue())));
else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer"))
result.add(new DecimalType(new BigDecimal(l.primitiveValue()).subtract(new BigDecimal(r.primitiveValue()))));
else
throw new PathEngineException(String.format("Error performing -: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType()));
return result;
}
Aggregations