Search in sources :

Example 46 with BooleanType

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

the class FamilyMemberHistory method setProperty.

@Override
public Base setProperty(String name, Base value) throws FHIRException {
    if (name.equals("identifier")) {
        this.getIdentifier().add(castToIdentifier(value));
    } else if (name.equals("definition")) {
        this.getDefinition().add(castToReference(value));
    } else if (name.equals("status")) {
        value = new FamilyHistoryStatusEnumFactory().fromType(castToCode(value));
        // Enumeration<FamilyHistoryStatus>
        this.status = (Enumeration) value;
    } else if (name.equals("notDone")) {
        // BooleanType
        this.notDone = castToBoolean(value);
    } else if (name.equals("notDoneReason")) {
        // CodeableConcept
        this.notDoneReason = castToCodeableConcept(value);
    } else if (name.equals("patient")) {
        // Reference
        this.patient = castToReference(value);
    } else if (name.equals("date")) {
        // DateTimeType
        this.date = castToDateTime(value);
    } else if (name.equals("name")) {
        // StringType
        this.name = castToString(value);
    } else if (name.equals("relationship")) {
        // CodeableConcept
        this.relationship = castToCodeableConcept(value);
    } else if (name.equals("gender")) {
        value = new AdministrativeGenderEnumFactory().fromType(castToCode(value));
        // Enumeration<AdministrativeGender>
        this.gender = (Enumeration) value;
    } else if (name.equals("born[x]")) {
        // Type
        this.born = castToType(value);
    } else if (name.equals("age[x]")) {
        // Type
        this.age = castToType(value);
    } else if (name.equals("estimatedAge")) {
        // BooleanType
        this.estimatedAge = castToBoolean(value);
    } else if (name.equals("deceased[x]")) {
        // Type
        this.deceased = castToType(value);
    } else if (name.equals("reasonCode")) {
        this.getReasonCode().add(castToCodeableConcept(value));
    } else if (name.equals("reasonReference")) {
        this.getReasonReference().add(castToReference(value));
    } else if (name.equals("note")) {
        this.getNote().add(castToAnnotation(value));
    } else if (name.equals("condition")) {
        this.getCondition().add((FamilyMemberHistoryConditionComponent) value);
    } else
        return super.setProperty(name, value);
    return value;
}
Also used : AdministrativeGenderEnumFactory(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGenderEnumFactory)

Example 47 with BooleanType

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

the class QuestionnaireBuilder method convertType.

@SuppressWarnings("unchecked")
private Type convertType(Base value, QuestionnaireItemType af, ValueSet vs, String path) throws FHIRException {
    switch(af) {
        // simple cases
        case BOOLEAN:
            if (value instanceof BooleanType)
                return (Type) value;
        case DECIMAL:
            if (value instanceof DecimalType)
                return (Type) value;
        case INTEGER:
            if (value instanceof IntegerType)
                return (Type) value;
        case DATE:
            if (value instanceof DateType)
                return (Type) value;
        case DATETIME:
            if (value instanceof DateTimeType)
                return (Type) value;
        case TIME:
            if (value instanceof TimeType)
                return (Type) value;
        case STRING:
            if (value instanceof StringType)
                return (Type) value;
            else if (value instanceof UriType)
                return new StringType(((UriType) value).asStringValue());
        case TEXT:
            if (value instanceof StringType)
                return (Type) value;
        case QUANTITY:
            if (value instanceof Quantity)
                return (Type) value;
        // ? QuestionnaireItemTypeAttachment: ...?
        case CHOICE:
        case OPENCHOICE:
            if (value instanceof Coding)
                return (Type) value;
            else if (value instanceof Enumeration) {
                Coding cc = new Coding();
                cc.setCode(((Enumeration<Enum<?>>) value).asStringValue());
                cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
                return cc;
            } else if (value instanceof StringType) {
                Coding cc = new Coding();
                cc.setCode(((StringType) value).asStringValue());
                cc.setSystem(getSystemForCode(vs, cc.getCode(), path));
                return cc;
            }
        case REFERENCE:
            if (value instanceof Reference)
                return (Type) value;
            else if (value instanceof StringType) {
                Reference r = new Reference();
                r.setReference(((StringType) value).asStringValue());
            }
    }
    throw new FHIRException("Unable to convert from '" + value.getClass().toString() + "' for Answer Format " + af.toCode() + ", path = " + path);
}
Also used : Enumeration(org.hl7.fhir.dstu3.model.Enumeration) StringType(org.hl7.fhir.dstu3.model.StringType) Reference(org.hl7.fhir.dstu3.model.Reference) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Quantity(org.hl7.fhir.dstu3.model.Quantity) FHIRException(org.hl7.fhir.exceptions.FHIRException) TimeType(org.hl7.fhir.dstu3.model.TimeType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) UriType(org.hl7.fhir.dstu3.model.UriType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) DateTimeType(org.hl7.fhir.dstu3.model.DateTimeType) Coding(org.hl7.fhir.dstu3.model.Coding) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) DateType(org.hl7.fhir.dstu3.model.DateType)

Example 48 with BooleanType

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

the class FluentPathTests method test.

@ParameterizedTest(name = "{index}: file {0}")
@MethodSource("data")
public void test(String name, Element element) throws IOException, FHIRException {
    String input = element.getAttribute("inputfile");
    String expression = XMLUtil.getNamedChild(element, "expression").getTextContent();
    boolean fail = "true".equals(XMLUtil.getNamedChild(element, "expression").getAttribute("invalid"));
    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 = new XmlParser().parse(new FileInputStream(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", input)));
            fp.check(res, res.getResourceType().toString(), res.getResourceType().toString(), node);
        }
        outcome = fp.evaluate(res, node);
        Assertions.assertTrue(!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(element.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(element, "output", expected);
    Assertions.assertTrue(outcome.size() == expected.size(), String.format("Expected %d objects but found %d", expected.size(), outcome.size()));
    for (int i = 0; i < Math.min(outcome.size(), expected.size()); i++) {
        String tn = expected.get(i).getAttribute("type");
        if (!Utilities.noString(tn)) {
            Assertions.assertTrue(tn.equals(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)) {
            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.assertTrue(v.equals(((PrimitiveType) outcome.get(i)).asStringValue()), String.format("Outcome %d: Value should be %s but was %s", i, v, outcome.get(i).toString()));
        }
    }
}
Also used : XmlParser(org.hl7.fhir.dstu3.formats.XmlParser) Element(org.w3c.dom.Element) Resource(org.hl7.fhir.dstu3.model.Resource) ArrayList(java.util.ArrayList) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) Base(org.hl7.fhir.dstu3.model.Base) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 49 with BooleanType

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

the class FHIRPathEngine method funcConformsTo.

private List<Base> funcConformsTo(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
    if (hostServices == null)
        throw new FHIRException("Unable to check conformsTo - no hostservices provided");
    List<Base> result = new ArrayList<Base>();
    if (focus.size() != 1)
        result.add(new BooleanType(false).noExtensions());
    else {
        String url = convertToString(execute(context, focus, exp.getParameters().get(0), true));
        result.add(new BooleanType(hostServices.conformsToProfile(context.appInfo, focus.get(0), url)).noExtensions());
    }
    return result;
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 50 with BooleanType

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

the class BaseWorkerContext method validateCodeBatch.

@Override
public void validateCodeBatch(ValidationOptions options, List<? extends CodingValidationRequest> codes, ValueSet vs) {
    if (options == null) {
        options = ValidationOptions.defaults();
    }
    // 3rd pass: hit the server
    for (CodingValidationRequest t : codes) {
        t.setCacheToken(txCache != null ? txCache.generateValidationToken(options, t.getCoding(), vs) : null);
        if (t.getCoding().hasSystem()) {
            codeSystemsUsed.add(t.getCoding().getSystem());
        }
        if (txCache != null) {
            t.setResult(txCache.getValidation(t.getCacheToken()));
        }
    }
    if (options.isUseClient()) {
        for (CodingValidationRequest t : codes) {
            if (!t.hasResult()) {
                try {
                    ValueSetCheckerSimple vsc = new ValueSetCheckerSimple(options, vs, this);
                    ValidationResult res = vsc.validateCode(t.getCoding());
                    if (txCache != null) {
                        txCache.cacheValidation(t.getCacheToken(), res, TerminologyCache.TRANSIENT);
                    }
                    t.setResult(res);
                } catch (Exception e) {
                }
            }
        }
    }
    for (CodingValidationRequest t : codes) {
        if (!t.hasResult()) {
            String codeKey = t.getCoding().hasVersion() ? t.getCoding().getSystem() + "|" + t.getCoding().getVersion() : t.getCoding().getSystem();
            if (!options.isUseServer()) {
                t.setResult(new ValidationResult(IssueSeverity.WARNING, formatMessage(I18nConstants.UNABLE_TO_VALIDATE_CODE_WITHOUT_USING_SERVER), TerminologyServiceErrorClass.BLOCKED_BY_OPTIONS));
            } else if (unsupportedCodeSystems.contains(codeKey)) {
                t.setResult(new ValidationResult(IssueSeverity.ERROR, formatMessage(I18nConstants.TERMINOLOGY_TX_SYSTEM_NOTKNOWN, t.getCoding().getSystem()), TerminologyServiceErrorClass.CODESYSTEM_UNSUPPORTED));
            } else if (noTerminologyServer) {
                t.setResult(new ValidationResult(IssueSeverity.ERROR, formatMessage(I18nConstants.ERROR_VALIDATING_CODE_RUNNING_WITHOUT_TERMINOLOGY_SERVICES), TerminologyServiceErrorClass.NOSERVICE));
            }
        }
    }
    if (expParameters == null)
        throw new Error(formatMessage(I18nConstants.NO_EXPANSIONPROFILE_PROVIDED));
    // for those that that failed, we try to validate on the server
    Bundle batch = new Bundle();
    batch.setType(BundleType.BATCH);
    Set<String> systems = new HashSet<>();
    for (CodingValidationRequest t : codes) {
        if (!t.hasResult()) {
            Parameters pIn = new Parameters();
            pIn.addParameter().setName("coding").setValue(t.getCoding());
            if (options.isGuessSystem()) {
                pIn.addParameter().setName("implySystem").setValue(new BooleanType(true));
            }
            if (vs != null) {
                pIn.addParameter().setName("valueSet").setResource(vs);
            }
            pIn.addParameter().setName("profile").setResource(expParameters);
            setTerminologyOptions(options, pIn);
            BundleEntryComponent be = batch.addEntry();
            be.setResource(pIn);
            be.getRequest().setMethod(HTTPVerb.POST);
            be.getRequest().setUrl("CodeSystem/$validate-code");
            be.setUserData("source", t);
            systems.add(t.getCoding().getSystem());
        }
    }
    if (batch.getEntry().size() > 0) {
        tlog("$batch validate for " + batch.getEntry().size() + " codes on systems " + systems.toString());
        if (txClient == null) {
            throw new FHIRException(formatMessage(I18nConstants.ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE));
        }
        if (txLog != null) {
            txLog.clearLastId();
        }
        Bundle resp = txClient.validateBatch(batch);
        for (int i = 0; i < batch.getEntry().size(); i++) {
            CodingValidationRequest t = (CodingValidationRequest) batch.getEntry().get(i).getUserData("source");
            BundleEntryComponent r = resp.getEntry().get(i);
            if (r.getResource() instanceof Parameters) {
                t.setResult(processValidationResult((Parameters) r.getResource()));
                if (txCache != null) {
                    txCache.cacheValidation(t.getCacheToken(), t.getResult(), TerminologyCache.PERMANENT);
                }
            } else {
                t.setResult(new ValidationResult(IssueSeverity.ERROR, getResponseText(r.getResource())).setTxLink(txLog == null ? null : txLog.getLastId()));
            }
        }
    }
}
Also used : Parameters(org.hl7.fhir.r4b.model.Parameters) Bundle(org.hl7.fhir.r4b.model.Bundle) BooleanType(org.hl7.fhir.r4b.model.BooleanType) FHIRException(org.hl7.fhir.exceptions.FHIRException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) NoTerminologyServiceException(org.hl7.fhir.exceptions.NoTerminologyServiceException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) BundleEntryComponent(org.hl7.fhir.r4b.model.Bundle.BundleEntryComponent) ValueSetCheckerSimple(org.hl7.fhir.r4b.terminologies.ValueSetCheckerSimple) HashSet(java.util.HashSet)

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