use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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);
}
use of org.hl7.fhir.r4b.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()));
}
}
}
use of org.hl7.fhir.r4b.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;
}
use of org.hl7.fhir.r4b.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()));
}
}
}
}
Aggregations