Search in sources :

Example 71 with BooleanType

use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method renderLeaf.

private void renderLeaf(ResourceWrapper res, BaseWrapper ew, ElementDefinition defn, XhtmlNode x, boolean title, boolean showCodeDetails, Map<String, String> displayHints, String path) throws FHIRException, UnsupportedEncodingException, IOException {
    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)
        x.addText(((DateTimeType) e).toHumanDisplay());
    else if (e instanceof Base64BinaryType)
        x.addText(new Base64().encodeAsString(((Base64BinaryType) e).getValue()));
    else if (e instanceof org.hl7.fhir.dstu3.model.DateType)
        x.addText(((org.hl7.fhir.dstu3.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((CodeableConcept) e, x, showCodeDetails);
    } else if (e instanceof Coding) {
        renderCoding((Coding) e, x, showCodeDetails);
    } else if (e instanceof Annotation) {
        renderAnnotation((Annotation) e, x);
    } else if (e instanceof Identifier) {
        renderIdentifier((Identifier) e, x);
    } else if (e instanceof org.hl7.fhir.dstu3.model.IntegerType) {
        x.addText(Integer.toString(((org.hl7.fhir.dstu3.model.IntegerType) e).getValue()));
    } else if (e instanceof org.hl7.fhir.dstu3.model.DecimalType) {
        x.addText(((org.hl7.fhir.dstu3.model.DecimalType) e).getValue().toString());
    } else if (e instanceof HumanName) {
        renderHumanName((HumanName) e, x);
    } else if (e instanceof SampledData) {
        renderSampledData((SampledData) e, x);
    } else if (e instanceof Address) {
        renderAddress((Address) e, x);
    } else if (e instanceof ContactPoint) {
        renderContactPoint((ContactPoint) e, x);
    } else if (e instanceof UriType) {
        renderUri((UriType) e, x);
    } else if (e instanceof Timing) {
        renderTiming((Timing) e, x);
    } else if (e instanceof Range) {
        renderRange((Range) e, x);
    } else if (e instanceof Quantity) {
        renderQuantity((Quantity) e, x, showCodeDetails);
    } else if (e instanceof Ratio) {
        renderQuantity(((Ratio) e).getNumerator(), x, showCodeDetails);
        x.tx("/");
        renderQuantity(((Ratio) e).getDenominator(), x, showCodeDetails);
    } else if (e instanceof Period) {
        Period p = (Period) e;
        x.addText(!p.hasStart() ? "??" : p.getStartElement().toHumanDisplay());
        x.tx(" --> ");
        x.addText(!p.hasEnd() ? "(ongoing)" : p.getEndElement().toHumanDisplay());
    } else if (e instanceof Reference) {
        Reference r = (Reference) e;
        XhtmlNode c = x;
        ResourceWithReference tr = null;
        if (r.hasReferenceElement()) {
            tr = resolveReference(res, r.getReference());
            if (!r.getReference().startsWith("#")) {
                if (tr != null && tr.getReference() != null)
                    c = x.ah(tr.getReference());
                else
                    c = x.ah(r.getReference());
            }
        }
        // what to display: if text is provided, then that. if the reference was resolved, then show the generated narrative
        if (r.hasDisplayElement()) {
            c.addText(r.getDisplay());
            if (tr != null && tr.getResource() != null) {
                c.tx(". Generated Summary: ");
                generateResourceSummary(c, tr.getResource(), true, r.getReference().startsWith("#"));
            }
        } else if (tr != null && tr.getResource() != null) {
            generateResourceSummary(c, tr.getResource(), r.getReference().startsWith("#"), r.getReference().startsWith("#"));
        } else {
            c.addText(r.getReference());
        }
    } else if (e instanceof Resource) {
        return;
    } else if (e instanceof ElementDefinition) {
        x.tx("todo-bundle");
    } else if (e != null && !(e instanceof Attachment) && !(e instanceof Narrative) && !(e instanceof Meta)) {
        StructureDefinition sd = context.fetchTypeDefinition(e.fhirType());
        if (sd == null)
            throw new NotImplementedException("type " + e.getClass().getName() + " not handled yet, and no structure found");
        else
            generateByProfile(res, sd, ew, sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep(), getChildrenForPath(sd.getSnapshot().getElement(), sd.getSnapshot().getElementFirstRep().getPath()), x, path, showCodeDetails);
    }
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) Base64(org.apache.commons.codec.binary.Base64) Address(org.hl7.fhir.dstu3.model.Address) StringType(org.hl7.fhir.dstu3.model.StringType) NotImplementedException(org.apache.commons.lang3.NotImplementedException) Attachment(org.hl7.fhir.dstu3.model.Attachment) UriType(org.hl7.fhir.dstu3.model.UriType) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) Identifier(org.hl7.fhir.dstu3.model.Identifier) Coding(org.hl7.fhir.dstu3.model.Coding) Narrative(org.hl7.fhir.dstu3.model.Narrative) SampledData(org.hl7.fhir.dstu3.model.SampledData) Ratio(org.hl7.fhir.dstu3.model.Ratio) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) InstantType(org.hl7.fhir.dstu3.model.InstantType) Enumeration(org.hl7.fhir.dstu3.model.Enumeration) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) MetadataResource(org.hl7.fhir.dstu3.model.MetadataResource) Resource(org.hl7.fhir.dstu3.model.Resource) Quantity(org.hl7.fhir.dstu3.model.Quantity) Period(org.hl7.fhir.dstu3.model.Period) Range(org.hl7.fhir.dstu3.model.Range) Base(org.hl7.fhir.dstu3.model.Base) Annotation(org.hl7.fhir.dstu3.model.Annotation) IdType(org.hl7.fhir.dstu3.model.IdType) Extension(org.hl7.fhir.dstu3.model.Extension) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) CodeType(org.hl7.fhir.dstu3.model.CodeType) EventTiming(org.hl7.fhir.dstu3.model.Timing.EventTiming) Timing(org.hl7.fhir.dstu3.model.Timing) Base64BinaryType(org.hl7.fhir.dstu3.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 72 with BooleanType

use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method validateOnServer.

private ValidationResult validateOnServer(ValueSet vs, Parameters pin) throws FHIRException {
    if (vs != null)
        pin.addParameter().setName("valueSet").setResource(vs);
    for (ParametersParameterComponent pp : pin.getParameter()) if (pp.getName().equals("profile"))
        throw new Error("Can only specify profile in the context");
    if (expParameters == null)
        throw new Error("No ExpansionProfile provided");
    pin.addParameter().setName("profile").setResource(expParameters);
    txLog.clearLastId();
    Parameters pOut;
    if (vs == null)
        pOut = txClient.validateCS(pin);
    else
        pOut = txClient.validateVS(pin);
    boolean ok = false;
    String message = "No Message returned";
    String display = null;
    TerminologyServiceErrorClass err = TerminologyServiceErrorClass.UNKNOWN;
    for (ParametersParameterComponent p : pOut.getParameter()) {
        if (p.getName().equals("result"))
            ok = ((BooleanType) p.getValue()).getValue().booleanValue();
        else if (p.getName().equals("message"))
            message = ((StringType) p.getValue()).getValue();
        else if (p.getName().equals("display"))
            display = ((StringType) p.getValue()).getValue();
        else if (p.getName().equals("cause")) {
            try {
                IssueType it = IssueType.fromCode(((StringType) p.getValue()).getValue());
                if (it == IssueType.UNKNOWN)
                    err = TerminologyServiceErrorClass.UNKNOWN;
                else if (it == IssueType.NOTSUPPORTED)
                    err = TerminologyServiceErrorClass.VALUESET_UNSUPPORTED;
            } catch (FHIRException e) {
            }
        }
    }
    if (!ok)
        return new ValidationResult(IssueSeverity.ERROR, message, err).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else if (message != null && !message.equals("No Message returned"))
        return new ValidationResult(IssueSeverity.WARNING, message, new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else if (display != null)
        return new ValidationResult(new ConceptDefinitionComponent().setDisplay(display)).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
    else
        return new ValidationResult(new ConceptDefinitionComponent()).setTxLink(txLog.getLastId()).setTxLink(txLog.getLastId());
}
Also used : TerminologyServiceErrorClass(org.hl7.fhir.r4.terminologies.ValueSetExpander.TerminologyServiceErrorClass) ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) IssueType(org.hl7.fhir.utilities.validation.ValidationMessage.IssueType) FHIRException(org.hl7.fhir.exceptions.FHIRException) ParametersParameterComponent(org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent)

Example 73 with BooleanType

use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method doValidateCode.

public ValidationResult doValidateCode(ValidationOptions options, Coding code, ValueSet vs, boolean implySystem) {
    CacheToken cacheToken = txCache != null ? txCache.generateValidationToken(options, code, vs) : null;
    ValidationResult res = null;
    if (txCache != null)
        res = txCache.getValidation(cacheToken);
    if (res != null)
        return res;
    // ok, first we try to validate locally
    try {
        ValueSetCheckerSimple vsc = new ValueSetCheckerSimple(options, vs, this);
        res = vsc.validateCode(code);
        if (txCache != null)
            txCache.cacheValidation(cacheToken, res, TerminologyCache.TRANSIENT);
        return res;
    } catch (Exception e) {
    }
    // if that failed, we try to validate on the server
    if (noTerminologyServer)
        return new ValidationResult(IssueSeverity.ERROR, "Error validating code: running without terminology services", TerminologyServiceErrorClass.NOSERVICE);
    String csumm = txCache != null ? txCache.summary(code) : null;
    if (txCache != null)
        tlog("$validate " + csumm + " for " + txCache.summary(vs));
    else
        tlog("$validate " + csumm + " before cache exists");
    try {
        Parameters pIn = new Parameters();
        pIn.addParameter().setName("coding").setValue(code);
        if (implySystem)
            pIn.addParameter().setName("implySystem").setValue(new BooleanType(true));
        if (options != null)
            setTerminologyOptions(options, pIn);
        res = validateOnServer(vs, pIn);
    } catch (Exception e) {
        res = new ValidationResult(IssueSeverity.ERROR, e.getMessage() == null ? e.getClass().getName() : e.getMessage()).setTxLink(txLog == null ? null : txLog.getLastId());
    }
    if (txCache != null)
        txCache.cacheValidation(cacheToken, res, TerminologyCache.PERMANENT);
    return res;
}
Also used : CacheToken(org.hl7.fhir.r4.context.TerminologyCache.CacheToken) ValueSetCheckerSimple(org.hl7.fhir.r4.terminologies.ValueSetCheckerSimple) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 74 with BooleanType

use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method runTransform.

private Base runTransform(String ruleId, TransformContext context, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, Variables vars, Base dest, String element, String srcVar, boolean root) throws FHIRException {
    try {
        switch(tgt.getTransform()) {
            case CREATE:
                String tn;
                if (tgt.getParameter().isEmpty()) {
                    // we have to work out the type. First, we see if there is a single type for the target. If there is, we use that
                    String[] types = dest.getTypesForProperty(element.hashCode(), element);
                    if (types.length == 1 && !"*".equals(types[0]) && !types[0].equals("Resource"))
                        tn = types[0];
                    else if (srcVar != null) {
                        tn = determineTypeFromSourceType(map, group, vars.get(VariableMode.INPUT, srcVar), types);
                    } else
                        throw new Error("Cannot determine type implicitly because there is no single input variable");
                } else {
                    tn = getParamStringNoNull(vars, tgt.getParameter().get(0), tgt.toString());
                    // ok, now we resolve the type name against the import statements
                    for (StructureMapStructureComponent uses : map.getStructure()) {
                        if (uses.getMode() == StructureMapModelMode.TARGET && uses.hasAlias() && tn.equals(uses.getAlias())) {
                            tn = uses.getUrl();
                            break;
                        }
                    }
                }
                Base res = services != null ? services.createType(context.getAppInfo(), tn) : ResourceFactory.createResourceOrType(tn);
                if (res.isResource() && !res.fhirType().equals("Parameters")) {
                    // res.setIdBase(tgt.getParameter().size() > 1 ? getParamString(vars, tgt.getParameter().get(0)) : UUID.randomUUID().toString().toLowerCase());
                    if (services != null)
                        res = services.createResource(context.getAppInfo(), res, root);
                }
                if (tgt.hasUserData("profile"))
                    res.setUserData("profile", tgt.getUserData("profile"));
                return res;
            case COPY:
                return getParam(vars, tgt.getParameter().get(0));
            case EVALUATE:
                ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
                if (expr == null) {
                    expr = fpe.parse(getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString()));
                    tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
                }
                List<Base> v = fpe.evaluate(vars, null, null, tgt.getParameter().size() == 2 ? getParam(vars, tgt.getParameter().get(0)) : new BooleanType(false), expr);
                if (v.size() == 0)
                    return null;
                else if (v.size() != 1)
                    throw new FHIRException("Rule \"" + ruleId + "\": Evaluation of " + expr.toString() + " returned " + Integer.toString(v.size()) + " objects");
                else
                    return v.get(0);
            case TRUNCATE:
                String src = getParamString(vars, tgt.getParameter().get(0));
                String len = getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString());
                if (Utilities.isInteger(len)) {
                    int l = Integer.parseInt(len);
                    if (src.length() > l)
                        src = src.substring(0, l);
                }
                return new StringType(src);
            case ESCAPE:
                throw new Error("Rule \"" + ruleId + "\": Transform " + tgt.getTransform().toCode() + " not supported yet");
            case CAST:
                src = getParamString(vars, tgt.getParameter().get(0));
                if (tgt.getParameter().size() == 1)
                    throw new FHIRException("Implicit type parameters on cast not yet supported");
                String t = getParamString(vars, tgt.getParameter().get(1));
                if (t.equals("string"))
                    return new StringType(src);
                else
                    throw new FHIRException("cast to " + t + " not yet supported");
            case APPEND:
                StringBuilder sb = new StringBuilder(getParamString(vars, tgt.getParameter().get(0)));
                for (int i = 1; i < tgt.getParameter().size(); i++) sb.append(getParamString(vars, tgt.getParameter().get(i)));
                return new StringType(sb.toString());
            case TRANSLATE:
                return translate(context, map, vars, tgt.getParameter());
            case REFERENCE:
                Base b = getParam(vars, tgt.getParameter().get(0));
                if (b == null)
                    throw new FHIRException("Rule \"" + ruleId + "\": Unable to find parameter " + ((IdType) tgt.getParameter().get(0).getValue()).asStringValue());
                if (!b.isResource())
                    throw new FHIRException("Rule \"" + ruleId + "\": Transform engine cannot point at an element of type " + b.fhirType());
                else {
                    String id = b.getIdBase();
                    if (id == null) {
                        id = UUID.randomUUID().toString().toLowerCase();
                        b.setIdBase(id);
                    }
                    return new Reference().setReference(b.fhirType() + "/" + id);
                }
            case DATEOP:
                throw new Error("Rule \"" + ruleId + "\": Transform " + tgt.getTransform().toCode() + " not supported yet");
            case UUID:
                return new IdType(UUID.randomUUID().toString());
            case POINTER:
                b = getParam(vars, tgt.getParameter().get(0));
                if (b instanceof Resource)
                    return new UriType("urn:uuid:" + ((Resource) b).getId());
                else
                    throw new FHIRException("Rule \"" + ruleId + "\": Transform engine cannot point at an element of type " + b.fhirType());
            case CC:
                CodeableConcept cc = new CodeableConcept();
                cc.addCoding(buildCoding(getParamStringNoNull(vars, tgt.getParameter().get(0), tgt.toString()), getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString())));
                return cc;
            case C:
                Coding c = buildCoding(getParamStringNoNull(vars, tgt.getParameter().get(0), tgt.toString()), getParamStringNoNull(vars, tgt.getParameter().get(1), tgt.toString()));
                return c;
            default:
                throw new Error("Rule \"" + ruleId + "\": Transform Unknown: " + tgt.getTransform().toCode());
        }
    } catch (Exception e) {
        throw new FHIRException("Exception executing transform " + tgt.toString() + " on Rule \"" + ruleId + "\": " + e.getMessage(), e);
    }
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) StringType(org.hl7.fhir.r4.model.StringType) StructureMapStructureComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapStructureComponent) Reference(org.hl7.fhir.r4.model.Reference) BooleanType(org.hl7.fhir.r4.model.BooleanType) Resource(org.hl7.fhir.r4.model.Resource) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.r4.model.Base) ContactPoint(org.hl7.fhir.r4.model.ContactPoint) NotImplementedException(org.apache.commons.lang3.NotImplementedException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRLexerException(org.hl7.fhir.r4.utils.FHIRLexer.FHIRLexerException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdType(org.hl7.fhir.r4.model.IdType) UriType(org.hl7.fhir.r4.model.UriType) Coding(org.hl7.fhir.r4.model.Coding) ExpressionNode(org.hl7.fhir.r4.model.ExpressionNode) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 75 with BooleanType

use of org.hl7.fhir.r5.model.BooleanType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcAll.

private List<Base> funcAll(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
    List<Base> result = new ArrayList<Base>();
    if (exp.getParameters().size() == 1) {
        List<Base> pc = new ArrayList<Base>();
        boolean all = true;
        for (Base item : focus) {
            pc.clear();
            pc.add(item);
            Equality eq = asBool(execute(changeThis(context, item), pc, exp.getParameters().get(0), true), exp);
            if (eq != Equality.True) {
                all = false;
                break;
            }
        }
        result.add(new BooleanType(all).noExtensions());
    } else {
        // (exp.getParameters().size() == 0) {
        boolean all = true;
        for (Base item : focus) {
            Equality eq = asBool(item, true);
            if (eq != Equality.True) {
                all = false;
                break;
            }
        }
        result.add(new BooleanType(all).noExtensions());
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.r4b.model.BooleanType) Base(org.hl7.fhir.r4b.model.Base)

Aggregations

ArrayList (java.util.ArrayList)59 BooleanType (org.hl7.fhir.r5.model.BooleanType)38 BooleanType (org.hl7.fhir.r4.model.BooleanType)37 FHIRException (org.hl7.fhir.exceptions.FHIRException)33 BooleanType (org.hl7.fhir.r4b.model.BooleanType)27 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)19 NotImplementedException (org.apache.commons.lang3.NotImplementedException)18 Base (org.hl7.fhir.r5.model.Base)17 Test (org.junit.Test)16 StringType (org.hl7.fhir.r4.model.StringType)15 Base (org.hl7.fhir.r4b.model.Base)15 BooleanType (org.hl7.fhir.dstu2016may.model.BooleanType)13 IOException (java.io.IOException)12 HashMap (java.util.HashMap)11 BooleanType (org.hl7.fhir.dstu2.model.BooleanType)11 Base (org.hl7.fhir.dstu2.model.Base)10 StringType (org.hl7.fhir.dstu3.model.StringType)10 StringType (org.hl7.fhir.r5.model.StringType)10 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 Coding (org.hl7.fhir.r4.model.Coding)9