Search in sources :

Example 31 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class OperationOutcomeUtilities method convertToIssue.

public static OperationOutcomeIssueComponent convertToIssue(ValidationMessage message, OperationOutcome op) {
    OperationOutcomeIssueComponent issue = new OperationOutcome.OperationOutcomeIssueComponent();
    issue.setUserData("source.vm", message);
    issue.setCode(convert(message.getType()));
    if (message.getLocation() != null) {
        // message location has a fhirPath in it. We need to populate the expression
        issue.addExpression(message.getLocation());
    }
    // pass through line/col if they're present
    if (message.getLine() >= 0)
        issue.addExtension().setUrl(ToolingExtensions.EXT_ISSUE_LINE).setValue(new IntegerType(message.getLine()));
    if (message.getCol() >= 0)
        issue.addExtension().setUrl(ToolingExtensions.EXT_ISSUE_COL).setValue(new IntegerType(message.getCol()));
    issue.setSeverity(convert(message.getLevel()));
    CodeableConcept c = new CodeableConcept();
    c.setText(message.getMessage());
    issue.setDetails(c);
    if (message.getSource() != null) {
        issue.getExtension().add(ToolingExtensions.makeIssueSource(message.getSource()));
    }
    issue.setUserData("source.msg", message);
    return issue;
}
Also used : IntegerType(org.hl7.fhir.r4b.model.IntegerType) OperationOutcomeIssueComponent(org.hl7.fhir.r4b.model.OperationOutcome.OperationOutcomeIssueComponent) CodeableConcept(org.hl7.fhir.r4b.model.CodeableConcept)

Example 32 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class ProfileUtilities method describeCardinality.

private String describeCardinality(ElementDefinition definition, ElementDefinition fallback, UnusedTracker tracker) {
    IntegerType min = definition.hasMinElement() ? definition.getMinElement() : new IntegerType();
    StringType max = definition.hasMaxElement() ? definition.getMaxElement() : new StringType();
    if (min.isEmpty() && fallback != null)
        min = fallback.getMinElement();
    if (max.isEmpty() && fallback != null)
        max = fallback.getMaxElement();
    tracker.used = !max.isEmpty() && !max.getValue().equals("0");
    if (min.isEmpty() && max.isEmpty())
        return null;
    else
        return (!min.hasValue() ? "" : Integer.toString(min.getValue())) + ".." + (!max.hasValue() ? "" : max.getValue());
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) StringType(org.hl7.fhir.r5.model.StringType)

Example 33 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opDiv.

private List<Base> opDiv(List<Base> left, List<Base> right, ExpressionNode expr) throws PathEngineException {
    if (left.size() == 0 || right.size() == 0) {
        return new ArrayList<Base>();
    }
    if (left.size() > 1) {
        throw makeException(expr, I18nConstants.FHIRPATH_LEFT_VALUE_PLURAL, "div");
    }
    if (!left.get(0).isPrimitive() && !(left.get(0) instanceof Quantity)) {
        throw makeException(expr, I18nConstants.FHIRPATH_LEFT_VALUE_WRONG_TYPE, "div", left.get(0).fhirType());
    }
    if (right.size() > 1) {
        throw makeException(expr, I18nConstants.FHIRPATH_RIGHT_VALUE_PLURAL, "div");
    }
    if (!right.get(0).isPrimitive() && !(right.get(0) instanceof Quantity)) {
        throw makeException(expr, I18nConstants.FHIRPATH_RIGHT_VALUE_WRONG_TYPE, "div", right.get(0).fhirType());
    }
    List<Base> result = new ArrayList<Base>();
    Base l = left.get(0);
    Base r = right.get(0);
    if (l.hasType("integer") && r.hasType("integer")) {
        int divisor = Integer.parseInt(r.primitiveValue());
        if (divisor != 0) {
            result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) / divisor));
        }
    } else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer")) {
        Decimal d1;
        try {
            d1 = new Decimal(l.primitiveValue());
            Decimal d2 = new Decimal(r.primitiveValue());
            result.add(new IntegerType(d1.divInt(d2).asDecimal()));
        } catch (UcumException e) {
        // just return nothing
        }
    } else {
        throw makeException(expr, I18nConstants.FHIRPATH_OP_INCOMPATIBLE, "div", left.get(0).fhirType(), right.get(0).fhirType());
    }
    return result;
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) BigDecimal(java.math.BigDecimal) Decimal(org.fhir.ucum.Decimal) ArrayList(java.util.ArrayList) Quantity(org.hl7.fhir.r5.model.Quantity) UcumException(org.fhir.ucum.UcumException) Base(org.hl7.fhir.r5.model.Base)

Example 34 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcToInteger.

private List<Base> funcToInteger(ExecutionContext context, List<Base> focus, ExpressionNode exp) {
    String s = convertToString(focus);
    List<Base> result = new ArrayList<Base>();
    if (Utilities.isInteger(s)) {
        result.add(new IntegerType(s).noExtensions());
    } else if ("true".equals(s)) {
        result.add(new IntegerType(1).noExtensions());
    } else if ("false".equals(s)) {
        result.add(new IntegerType(0).noExtensions());
    }
    return result;
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) ArrayList(java.util.ArrayList) Base(org.hl7.fhir.r5.model.Base)

Example 35 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method funcIndexOf.

private List<Base> funcIndexOf(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
    List<Base> result = new ArrayList<Base>();
    String sw = convertToString(execute(context, focus, exp.getParameters().get(0), true));
    if (focus.size() == 0) {
        result.add(new IntegerType(0).noExtensions());
    } else if (Utilities.noString(sw)) {
        result.add(new IntegerType(0).noExtensions());
    } else {
        String s = convertToString(focus.get(0));
        if (s == null) {
            result.add(new IntegerType(0).noExtensions());
        } else {
            result.add(new IntegerType(s.indexOf(sw)).noExtensions());
        }
    }
    return result;
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) ArrayList(java.util.ArrayList) Base(org.hl7.fhir.r5.model.Base)

Aggregations

ArrayList (java.util.ArrayList)51 BigDecimal (java.math.BigDecimal)34 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)28 IntegerType (org.hl7.fhir.r5.model.IntegerType)26 IntegerType (org.hl7.fhir.r4.model.IntegerType)23 IntegerType (org.hl7.fhir.r4b.model.IntegerType)23 UcumException (org.fhir.ucum.UcumException)19 Test (org.junit.jupiter.api.Test)13 Decimal (org.fhir.ucum.Decimal)12 FHIRException (org.hl7.fhir.exceptions.FHIRException)12 Base (org.hl7.fhir.r4b.model.Base)11 Base (org.hl7.fhir.r5.model.Base)11 IntegerType (org.hl7.fhir.dstu2.model.IntegerType)10 IntegerType (org.hl7.fhir.dstu2016may.model.IntegerType)10 StringType (org.hl7.fhir.r4.model.StringType)10 Patient (org.hl7.fhir.r4.model.Patient)9 Map (java.util.Map)7 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)7 DecimalType (org.hl7.fhir.r5.model.DecimalType)7 List (java.util.List)6