Search in sources :

Example 31 with PrimitiveType

use of org.hl7.fhir.dstu2.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.

the class ProfileDrivenRenderer method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode parent, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path, int indent) throws FHIRException, UnsupportedEncodingException, IOException, EOperationOutcome {
    if (ew == null)
        return;
    Base e = ew.getBase();
    if (e instanceof StringType)
        x.addText(((StringType) e).getValue());
    else if (e instanceof CodeType)
        x.addText(((CodeType) e).getValue());
    else if (e instanceof IdType)
        x.addText(((IdType) e).getValue());
    else if (e instanceof Extension)
        return;
    else if (e instanceof InstantType)
        x.addText(((InstantType) e).toHumanDisplay());
    else if (e instanceof DateTimeType) {
        renderDateTime(x, e);
    } else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.r4b.model.DateType) {
        org.hl7.fhir.r4b.model.DateType dt = ((org.hl7.fhir.r4b.model.DateType) e);
        if (((org.hl7.fhir.r4b.model.DateType) e).hasValue()) {
            x.addText(((org.hl7.fhir.r4b.model.DateType) e).toHumanDisplay());
        }
    } else if (e instanceof Enumeration) {
        Object ev = ((Enumeration<?>) e).getValue();
        // todo: look up a display name if there is one
        x.addText(ev == null ? "" : ev.toString());
    } else if (e instanceof BooleanType) {
        x.addText(((BooleanType) e).getValue().toString());
    } else if (e instanceof CodeableConcept) {
        renderCodeableConcept(x, (CodeableConcept) e, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding(x, (Coding) e, showCodeDetails);
    } else if (e instanceof CodeableReference) {
        renderCodeableReference(x, (CodeableReference) e, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation(x, (Annotation) e);
    } else if (e instanceof Identifier) {
        renderIdentifier(x, (Identifier) e);
    } else if (e instanceof org.hl7.fhir.r4b.model.IntegerType) {
        if (((org.hl7.fhir.r4b.model.IntegerType) e).hasValue()) {
            x.addText(Integer.toString(((org.hl7.fhir.r4b.model.IntegerType) e).getValue()));
        } else {
            x.addText("??");
        }
    } else if (e instanceof org.hl7.fhir.r4b.model.Integer64Type) {
        if (((org.hl7.fhir.r4b.model.Integer64Type) e).hasValue()) {
            x.addText(Long.toString(((org.hl7.fhir.r4b.model.Integer64Type) e).getValue()));
        } else {
            x.addText("??");
        }
    } else if (e instanceof org.hl7.fhir.r4b.model.DecimalType) {
        x.addText(((org.hl7.fhir.r4b.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName(x, (HumanName) e);
    } else if (e instanceof SampledData) {
        renderSampledData(x, (SampledData) e);
    } else if (e instanceof Address) {
        renderAddress(x, (Address) e);
    } else if (e instanceof ContactPoint) {
        renderContactPoint(x, (ContactPoint) e);
    } else if (e instanceof Expression) {
        renderExpression(x, (Expression) e);
    } else if (e instanceof Money) {
        renderMoney(x, (Money) e);
    } else if (e instanceof ContactDetail) {
        ContactDetail cd = (ContactDetail) e;
        if (cd.hasName()) {
            x.tx(cd.getName() + ": ");
        }
        boolean first = true;
        for (ContactPoint c : cd.getTelecom()) {
            if (first)
                first = false;
            else
                x.tx(",");
            renderContactPoint(x, c);
        }
    } else if (e instanceof UriType) {
        renderUri(x, (UriType) e, defn.getPath(), rcontext != null && rcontext.getResourceResource() != null ? rcontext.getResourceResource().getId() : null);
    } else if (e instanceof Timing) {
        renderTiming(x, (Timing) e);
    } else if (e instanceof Range) {
        renderRange(x, (Range) e);
    } else if (e instanceof Quantity) {
        renderQuantity(x, (Quantity) e, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(x, ((Ratio) e).getNumerator(), showCodeDetails);
        x.tx("/");
        renderQuantity(x, ((Ratio) e).getDenominator(), showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        renderPeriod(x, p);
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        if (r.getReference() != null && r.getReference().contains("#")) {
            if (containedIds.contains(r.getReference().substring(1))) {
                x.ah(r.getReference()).tx("See " + r.getReference());
            } else {
                // in this case, we render the resource in line
                ResourceWrapper rw = null;
                for (ResourceWrapper t : res.getContained()) {
                    if (r.getReference().substring(1).equals(t.getId())) {
                        rw = t;
                    }
                }
                if (rw == null) {
                    renderReference(res, x, r);
                } else {
                    x.an(rw.getId());
                    ResourceRenderer rr = RendererFactory.factory(rw, context.copy().setAddGeneratedNarrativeHeader(false));
                    rr.render(parent.blockquote(), rw);
                }
            }
        } else {
            renderReference(res, x, r);
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof DataRequirement) {
        DataRequirement p = (DataRequirement) e;
        renderDataRequirement(x, p);
    } else if (e instanceof PrimitiveType) {
        x.tx(((PrimitiveType) e).primitiveValue());
    } else if (e instanceof ElementDefinition) {
        x.tx("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
        throw new NotImplementedException("type " + e.getClass().getName() + " not handled - should not be here");
    }
}
Also used : ResourceWrapper(org.hl7.fhir.r4b.renderers.utils.BaseWrappers.ResourceWrapper) Meta(org.hl7.fhir.r4b.model.Meta) Address(org.hl7.fhir.r4b.model.Address) StringType(org.hl7.fhir.r4b.model.StringType) Attachment(org.hl7.fhir.r4b.model.Attachment) DataRequirement(org.hl7.fhir.r4b.model.DataRequirement) Identifier(org.hl7.fhir.r4b.model.Identifier) Coding(org.hl7.fhir.r4b.model.Coding) Narrative(org.hl7.fhir.r4b.model.Narrative) SampledData(org.hl7.fhir.r4b.model.SampledData) PrimitiveType(org.hl7.fhir.r4b.model.PrimitiveType) ElementDefinition(org.hl7.fhir.r4b.model.ElementDefinition) InstantType(org.hl7.fhir.r4b.model.InstantType) DomainResource(org.hl7.fhir.r4b.model.DomainResource) Resource(org.hl7.fhir.r4b.model.Resource) Period(org.hl7.fhir.r4b.model.Period) Range(org.hl7.fhir.r4b.model.Range) IdType(org.hl7.fhir.r4b.model.IdType) DateTimeType(org.hl7.fhir.r4b.model.DateTimeType) Timing(org.hl7.fhir.r4b.model.Timing) CodeableConcept(org.hl7.fhir.r4b.model.CodeableConcept) Base64(org.apache.commons.codec.binary.Base64) NotImplementedException(org.apache.commons.lang3.NotImplementedException) UriType(org.hl7.fhir.r4b.model.UriType) HumanName(org.hl7.fhir.r4b.model.HumanName) ContactPoint(org.hl7.fhir.r4b.model.ContactPoint) Money(org.hl7.fhir.r4b.model.Money) Ratio(org.hl7.fhir.r4b.model.Ratio) Enumeration(org.hl7.fhir.r4b.model.Enumeration) CodeableReference(org.hl7.fhir.r4b.model.CodeableReference) ResourceWithReference(org.hl7.fhir.r4b.renderers.utils.Resolver.ResourceWithReference) Reference(org.hl7.fhir.r4b.model.Reference) BooleanType(org.hl7.fhir.r4b.model.BooleanType) Quantity(org.hl7.fhir.r4b.model.Quantity) Base(org.hl7.fhir.r4b.model.Base) Annotation(org.hl7.fhir.r4b.model.Annotation) Extension(org.hl7.fhir.r4b.model.Extension) ContactDetail(org.hl7.fhir.r4b.model.ContactDetail) Expression(org.hl7.fhir.r4b.model.Expression) CodeableReference(org.hl7.fhir.r4b.model.CodeableReference) CodeType(org.hl7.fhir.r4b.model.CodeType) Base64BinaryType(org.hl7.fhir.r4b.model.Base64BinaryType)

Example 32 with PrimitiveType

use of org.hl7.fhir.dstu2.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.r5.model.PrimitiveType) Row(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Row) Cell(org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource)

Example 33 with PrimitiveType

use of org.hl7.fhir.dstu2.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.

the class PrimitiveType method equalsShallow.

@Override
public boolean equalsShallow(Base obj) {
    if (obj == null) {
        return false;
    }
    if (!(obj.getClass() == getClass())) {
        return false;
    }
    PrimitiveType<?> o = (PrimitiveType<?>) obj;
    EqualsBuilder b = new EqualsBuilder();
    b.append(getValue(), o.getValue());
    return b.isEquals();
}
Also used : IPrimitiveType(org.hl7.fhir.instance.model.api.IPrimitiveType) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder)

Example 34 with PrimitiveType

use of org.hl7.fhir.dstu2.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()));
            result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(), "POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
        } else {
            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 tx5 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.r5.model.Parameters.ParametersParameterComponent)

Example 35 with PrimitiveType

use of org.hl7.fhir.dstu2.model.PrimitiveType in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method generateVersionNotice.

@SuppressWarnings("rawtypes")
private void generateVersionNotice(XhtmlNode x, ValueSetExpansionComponent expansion) {
    Map<String, String> versions = new HashMap<String, String>();
    boolean firstVersion = true;
    for (ValueSetExpansionParameterComponent p : expansion.getParameter()) {
        if (p.getName().equals("version")) {
            String[] parts = ((PrimitiveType) p.getValue()).asStringValue().split("\\|");
            if (parts.length == 2)
                versions.put(parts[0], parts[1]);
            if (!versions.isEmpty()) {
                StringBuilder b = new StringBuilder();
                if (firstVersion) {
                    // the first version
                    // set the <p> tag and style attribute
                    x.para().setAttribute("style", "border: black 1px dotted; background-color: #EEEEEE; padding: 8px");
                    firstVersion = false;
                } else {
                    // the second (or greater) version
                    // add line break before the version text
                    x.br();
                }
                b.append("Expansion based on ");
                boolean firstPart = true;
                for (String s : versions.keySet()) {
                    if (firstPart)
                        firstPart = false;
                    else
                        b.append(", ");
                    if (!s.equals("http://snomed.info/sct"))
                        b.append(describeSystem(s) + " version " + versions.get(s));
                    else {
                        parts = versions.get(s).split("\\/");
                        if (parts.length >= 5) {
                            String m = describeModule(parts[4]);
                            if (parts.length == 7)
                                b.append("SNOMED CT " + m + " edition " + formatSCTDate(parts[6]));
                            else
                                b.append("SNOMED CT " + m + " edition");
                        } else
                            b.append(describeSystem(s) + " version " + versions.get(s));
                    }
                }
                // add the version text
                x.addText(b.toString());
            }
        }
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) HashMap(java.util.HashMap) ValueSetExpansionParameterComponent(org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionParameterComponent)

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