use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.
the class Expression40Test method testAdvisorExpressionConversion40_10.
@Test
@DisplayName("Test Advisor is used in Expression R4 -> DSTU3 conversion.")
public void testAdvisorExpressionConversion40_10() throws IOException {
InputStream r4_stream = this.getClass().getResourceAsStream("/questionnaire_with_expression_40.json");
org.hl7.fhir.r4.model.Questionnaire r4_input = (org.hl7.fhir.r4.model.Questionnaire) new org.hl7.fhir.r4.formats.JsonParser().parse(r4_stream);
InputStream r2_stream = this.getClass().getResourceAsStream("/questionnaire_with_converted_expression_40_10.json");
org.hl7.fhir.dstu2.model.Questionnaire r2_expected_output = (org.hl7.fhir.dstu2.model.Questionnaire) new org.hl7.fhir.dstu2.formats.JsonParser().parse(r2_stream);
org.hl7.fhir.dstu2.model.Questionnaire convertedDstu2Questionnaire = (org.hl7.fhir.dstu2.model.Questionnaire) VersionConvertorFactory_10_40.convertResource(r4_input, new ExpressionAdvisor40());
org.hl7.fhir.dstu2.formats.JsonParser dstu2_parser = new org.hl7.fhir.dstu2.formats.JsonParser();
String composeString1 = dstu2_parser.composeString(convertedDstu2Questionnaire);
String composeString2 = dstu2_parser.composeString(r2_expected_output);
System.out.println("Expected out ->\n" + composeString2 + "\n\nActual out ->\n" + composeString1);
Assertions.assertTrue(r2_expected_output.equalsDeep(convertedDstu2Questionnaire));
}
use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.
the class Expression40Test method testBaseAdvisorExpressionIgore.
@Test
@DisplayName("Ensure base advisor ignores Expression types and doesn't explode.")
public void testBaseAdvisorExpressionIgore() throws IOException {
Expression exp = new Expression();
exp.setExpression("x + y = z");
Extension ext = new Extension();
ext.setValue(exp);
BaseAdvisor_10_40 baseAdvisor1040 = new BaseAdvisor_10_40();
Assertions.assertTrue(baseAdvisor1040.ignoreExtension("", ext));
}
use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeElementDefinitionElementDefinitionConstraintComponent.
protected void composeElementDefinitionElementDefinitionConstraintComponent(Complex parent, String parentType, String name, ElementDefinition.ElementDefinitionConstraintComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeElement(t, "constraint", name, element, index);
if (element.hasKeyElement())
composeId(t, "ElementDefinition", "key", element.getKeyElement(), -1);
if (element.hasRequirementsElement())
composeString(t, "ElementDefinition", "requirements", element.getRequirementsElement(), -1);
if (element.hasSeverityElement())
composeEnum(t, "ElementDefinition", "severity", element.getSeverityElement(), -1);
if (element.hasHumanElement())
composeString(t, "ElementDefinition", "human", element.getHumanElement(), -1);
if (element.hasExpressionElement())
composeString(t, "ElementDefinition", "expression", element.getExpressionElement(), -1);
if (element.hasXpathElement())
composeString(t, "ElementDefinition", "xpath", element.getXpathElement(), -1);
}
use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.
the class FluentPathTests method testWrong.
private void testWrong(Resource resource, String expression) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
try {
ExpressionNode node = fp.parse(expression);
fp.check(null, null, resource.getResourceType().toString(), node);
fp.evaluate(null, null, resource, node);
if (fp.hasLog())
System.out.println(fp.takeLog());
Assertions.fail("Fail expected");
} catch (PathEngineException e) {
// ok
}
}
use of org.hl7.elm.r1.Expression in project org.hl7.fhir.core by hapifhir.
the class FluentPathTests method test.
@SuppressWarnings("deprecation")
private void test(Resource resource, String expression, int count, String... types) throws FileNotFoundException, IOException, FHIRException {
if (TestingUtilities.context == null)
TestingUtilities.context = SimpleWorkerContext.fromPack("C:\\work\\org.hl7.fhir\\build\\publish\\validation-min.xml.zip");
FHIRPathEngine fp = new FHIRPathEngine(TestingUtilities.context);
ExpressionNode node = fp.parse(expression);
fp.check(null, resource.getResourceType().toString(), resource.getResourceType().toString(), node);
List<Base> outcome = fp.evaluate(resource, node);
if (fp.hasLog())
System.out.println(fp.takeLog());
Assertions.assertTrue(outcome.size() == count, String.format("Expected %d objects but found %d", count, outcome.size()));
CommaSeparatedStringBuilder msg = new CommaSeparatedStringBuilder();
for (String t : types) msg.append(t);
for (Base b : outcome) {
boolean found = false;
String type = b.fhirType();
for (String t : types) if (type.equals(t))
found = true;
Assertions.assertTrue(found, String.format("Object type %s not ok from %s", type, msg));
}
}
Aggregations