use of org.hl7.fhir.r4b.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.
the class StructureMapUtilities method describeTransformCCorC.
@SuppressWarnings("rawtypes")
private String describeTransformCCorC(StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
if (tgt.getParameter().size() < 2)
return null;
Type p1 = tgt.getParameter().get(0).getValue();
Type p2 = tgt.getParameter().get(1).getValue();
if (p1 instanceof IdType || p2 instanceof IdType)
return null;
if (!(p1 instanceof PrimitiveType) || !(p2 instanceof PrimitiveType))
return null;
String uri = ((PrimitiveType) p1).asStringValue();
String code = ((PrimitiveType) p2).asStringValue();
if (Utilities.noString(uri))
throw new FHIRException("Describe Transform, but the uri is blank");
if (Utilities.noString(code))
throw new FHIRException("Describe Transform, but the code is blank");
Coding c = buildCoding(uri, code);
return NarrativeGenerator.describeSystem(c.getSystem()) + "#" + c.getCode() + (c.hasDisplay() ? "(" + c.getDisplay() + ")" : "");
}
use of org.hl7.fhir.r4b.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.
the class FHIRToolingClient method operateType.
public <T extends Resource> Parameters operateType(Class<T> resourceClass, String name, Parameters params) {
boolean complex = false;
for (ParametersParameterComponent p : params.getParameter()) complex = complex || !(p.getValue() instanceof PrimitiveType);
String ps = "";
try {
if (!complex)
for (ParametersParameterComponent p : params.getParameter()) if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
if (complex) {
byte[] body = ByteUtils.resourceToByteArray(params, false, isJson(getPreferredResourceFormat()));
if (client.getLogger() != null) {
client.getLogger().logRequest("POST", url.toString(), null, body);
}
result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(), "POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
} else {
if (client.getLogger() != null) {
client.getLogger().logRequest("GET", url.toString(), null, null);
}
result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(), "GET " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
}
if (result.isUnsuccessfulRequest()) {
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
}
if (result.getPayload() instanceof Parameters) {
return (Parameters) result.getPayload();
} else {
Parameters p_out = new Parameters();
p_out.addParameter().setName("return").setResource(result.getPayload());
return p_out;
}
} catch (Exception e) {
handleException("Error performing tx3 operation '" + name + ": " + e.getMessage() + "' (parameters = \"" + ps + "\")", e);
}
return null;
}
use of org.hl7.fhir.r4b.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.
the class FHIRPathTests method test.
@SuppressWarnings("deprecation")
@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String name, Element test) throws FileNotFoundException, IOException, FHIRException, org.hl7.fhir.exceptions.FHIRException, UcumException {
fp.setHostServices(new FHIRPathTestEvaluationServices());
String input = test.getAttribute("inputfile");
String expression = XMLUtil.getNamedChild(test, "expression").getTextContent();
boolean fail = Utilities.existsInList(XMLUtil.getNamedChild(test, "expression").getAttribute("invalid"), "true", "semantic");
Resource res = null;
List<Base> outcome = new ArrayList<Base>();
ExpressionNode node = fp.parse(expression);
try {
if (Utilities.noString(input))
fp.check(null, null, node);
else {
res = resources.get(input);
if (res == null) {
res = new XmlParser().parse(new FileInputStream(TestingUtilities.resourceNameToFile(input)));
resources.put(input, res);
}
fp.check(res, res.getResourceType().toString(), res.getResourceType().toString(), node);
}
outcome = fp.evaluate(res, node);
Assertions.assertFalse(fail, String.format("Expected exception parsing %s", expression));
} catch (Exception e) {
Assertions.assertTrue(fail, String.format("Unexpected exception parsing %s: " + e.getMessage(), expression));
}
if ("true".equals(test.getAttribute("predicate"))) {
boolean ok = fp.convertToBoolean(outcome);
outcome.clear();
outcome.add(new BooleanType(ok));
}
if (fp.hasLog())
System.out.println(fp.takeLog());
List<Element> expected = new ArrayList<Element>();
XMLUtil.getNamedChildren(test, "output", expected);
Assertions.assertEquals(outcome.size(), expected.size(), String.format("Expected %d objects but found %d for expression %s", expected.size(), outcome.size(), expression));
if ("false".equals(test.getAttribute("ordered"))) {
for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
String tn = outcome.get(i).fhirType();
String s;
if (outcome.get(i) instanceof Quantity)
s = fp.convertToString(outcome.get(i));
else
s = ((PrimitiveType) outcome.get(i)).asStringValue();
boolean found = false;
for (Element e : expected) {
if ((Utilities.noString(e.getAttribute("type")) || e.getAttribute("type").equals(tn)) && (Utilities.noString(e.getTextContent()) || e.getTextContent().equals(s)))
found = true;
}
Assertions.assertTrue(found, String.format("Outcome %d: Value %s of type %s not expected for %s", i, s, tn, expression));
}
} else {
for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
String tn = expected.get(i).getAttribute("type");
if (!Utilities.noString(tn)) {
Assertions.assertEquals(tn, outcome.get(i).fhirType(), String.format("Outcome %d: Type should be %s but was %s", i, tn, outcome.get(i).fhirType()));
}
String v = expected.get(i).getTextContent();
if (!Utilities.noString(v)) {
if (outcome.get(i) instanceof Quantity) {
Quantity q = fp.parseQuantityString(v);
Assertions.assertTrue(outcome.get(i).equalsDeep(q), String.format("Outcome %d: Value should be %s but was %s", i, v, outcome.get(i).toString()));
} else {
Assertions.assertTrue(outcome.get(i) instanceof PrimitiveType, String.format("Outcome %d: Value should be a primitive type but was %s", i, outcome.get(i).fhirType()));
Assertions.assertEquals(v, ((PrimitiveType) outcome.get(i)).fpValue(), String.format("Outcome %d: Value should be %s but was %s for expression %s", i, v, ((PrimitiveType) outcome.get(i)).fpValue(), expression));
}
}
}
}
}
use of org.hl7.fhir.r4b.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.
the class CapabilityStatementComparer method addPrimitiveTypeRow.
@SuppressWarnings("rawtypes")
private Row addPrimitiveTypeRow(HierarchicalTableGenerator gen, List<Row> rows, StructuralMatch<Element> t, CapabilityStatementComparison comparison) {
Row r = gen.new Row();
rows.add(r);
r.getCells().add(gen.new Cell(null, null, t.getName(), null, null));
PrimitiveType left = t.hasLeft() ? (PrimitiveType) t.getLeft() : null;
PrimitiveType right = t.hasRight() ? (PrimitiveType) t.getRight() : null;
CanonicalResource crL = left == null ? null : (CanonicalResource) session.getContextLeft().fetchResource(Resource.class, left.primitiveValue());
CanonicalResource crR = right == null ? null : (CanonicalResource) session.getContextRight().fetchResource(Resource.class, right.primitiveValue());
String refL = crL != null && crL.hasUserData("path") ? crL.getUserString("path") : null;
String dispL = crL != null && refL != null ? crL.present() : left == null ? "" : left.primitiveValue();
String refR = crR != null && crR.hasUserData("path") ? crR.getUserString("path") : null;
String dispR = crR != null && refR != null ? crR.present() : right == null ? "" : right.primitiveValue();
r.getCells().add(style(gen.new Cell(null, refL, dispL, null, null), left != null ? left.primitiveValue() : null, right != null ? right.primitiveValue() : null, true));
r.getCells().add(gen.new Cell(null, null, "", null, null));
r.getCells().add(style(gen.new Cell(null, refR, dispR, null, null), left != null ? left.primitiveValue() : null, right != null ? right.primitiveValue() : null, false));
r.getCells().add(gen.new Cell(null, null, "", null, null));
r.getCells().add(cellForMessages(gen, t.getMessages()));
return r;
}
use of org.hl7.fhir.r4b.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.
the class CanonicalResourceComparer method comparePrimitives.
@SuppressWarnings("rawtypes")
protected void comparePrimitives(String name, PrimitiveType l, PrimitiveType r, Map<String, StructuralMatch<String>> comp, IssueSeverity level, CanonicalResourceComparison<? extends CanonicalResource> res) {
StructuralMatch<String> match = null;
if (l.isEmpty() && r.isEmpty()) {
match = new StructuralMatch<>(null, null, null);
} else if (l.isEmpty()) {
match = new StructuralMatch<>(null, r.primitiveValue(), vmI(IssueSeverity.INFORMATION, "Added the item '" + r.primitiveValue() + "'", fhirType() + "." + name));
} else if (r.isEmpty()) {
match = new StructuralMatch<>(l.primitiveValue(), null, vmI(IssueSeverity.INFORMATION, "Removed the item '" + l.primitiveValue() + "'", fhirType() + "." + name));
} else if (!l.hasValue() && !r.hasValue()) {
match = new StructuralMatch<>(null, null, vmI(IssueSeverity.INFORMATION, "No Value", fhirType() + "." + name));
} else if (!l.hasValue()) {
match = new StructuralMatch<>(null, r.primitiveValue(), vmI(IssueSeverity.INFORMATION, "No Value on Left", fhirType() + "." + name));
} else if (!r.hasValue()) {
match = new StructuralMatch<>(l.primitiveValue(), null, vmI(IssueSeverity.INFORMATION, "No Value on Right", fhirType() + "." + name));
} else if (l.getValue().equals(r.getValue())) {
match = new StructuralMatch<>(l.primitiveValue(), r.primitiveValue(), null);
} else {
match = new StructuralMatch<>(l.primitiveValue(), r.primitiveValue(), vmI(level, "Values Differ", fhirType() + "." + name));
if (level != IssueSeverity.NULL) {
res.getMessages().add(new ValidationMessage(Source.ProfileComparer, IssueType.INFORMATIONAL, fhirType() + "." + name, "Values for " + name + " differ: '" + l.primitiveValue() + "' vs '" + r.primitiveValue() + "'", level));
}
}
comp.put(name, match);
}
Aggregations