Search in sources :

Example 56 with PrimitiveType

use of org.hl7.fhir.dstu2016may.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() + ")" : "");
}
Also used : NodeType(org.hl7.fhir.utilities.xhtml.NodeType) Type(org.hl7.fhir.dstu3.model.Type) IdType(org.hl7.fhir.dstu3.model.IdType) StringType(org.hl7.fhir.dstu3.model.StringType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) CodeType(org.hl7.fhir.dstu3.model.CodeType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) UriType(org.hl7.fhir.dstu3.model.UriType) StructureMapContextType(org.hl7.fhir.dstu3.model.StructureMap.StructureMapContextType) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) Coding(org.hl7.fhir.dstu3.model.Coding) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 57 with PrimitiveType

use of org.hl7.fhir.dstu2016may.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;
}
Also used : URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent)

Example 58 with PrimitiveType

use of org.hl7.fhir.dstu2016may.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));
                }
            }
        }
    }
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) NotImplementedException(org.apache.commons.lang3.NotImplementedException) UcumException(org.fhir.ucum.UcumException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 59 with PrimitiveType

use of org.hl7.fhir.dstu2016may.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;
}
Also used : PrimitiveType(org.hl7.fhir.r4b.model.PrimitiveType) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource)

Example 60 with PrimitiveType

use of org.hl7.fhir.dstu2016may.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);
}
Also used : ValidationMessage(org.hl7.fhir.utilities.validation.ValidationMessage)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)18 EqualsBuilder (org.apache.commons.lang3.builder.EqualsBuilder)12 IPrimitiveType (org.hl7.fhir.instance.model.api.IPrimitiveType)12 IOException (java.io.IOException)10 NotImplementedException (org.apache.commons.lang3.NotImplementedException)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 PrimitiveType (org.hl7.fhir.r5.model.PrimitiveType)8 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)8 URISyntaxException (java.net.URISyntaxException)6 PrimitiveType (org.hl7.fhir.definitions.model.PrimitiveType)6 FileNotFoundException (java.io.FileNotFoundException)5 ArrayList (java.util.ArrayList)5 PrimitiveType (org.hl7.fhir.dstu3.model.PrimitiveType)5 PrimitiveType (org.hl7.fhir.r4b.model.PrimitiveType)5 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)5 URI (java.net.URI)4 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)4 StringType (org.hl7.fhir.dstu3.model.StringType)4 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3