Search in sources :

Example 1 with BaseDateTimeType

use of org.hl7.fhir.dstu3.model.BaseDateTimeType in project beneficiary-fhir-data by CMSgov.

the class TransformerTestUtils method assertCommonEobInformationInpatientSNF.

/**
 * Tests EOB information fields that are common between the Inpatient and SNF claim types.
 *
 * @param eob the {@link ExplanationOfBenefit} that will be tested by this method
 * @param noncoveredStayFromDate NCH_VRFD_NCVRD_STAY_FROM_DT: an {@link Optional}<{@link
 *     LocalDate}> shared field representing the non-covered stay from date for the claim
 * @param noncoveredStayThroughDate NCH_VRFD_NCVRD_STAY_THRU_DT: an {@link Optional}<{@link
 *     LocalDate}> shared field representing the non-covered stay through date for the claim
 * @param coveredCareThroughDate NCH_ACTV_OR_CVRD_LVL_CARE_THRU: an {@link Optional}<{@link
 *     LocalDate}> shared field representing the covered stay through date for the claim
 * @param medicareBenefitsExhaustedDate NCH_BENE_MDCR_BNFTS_EXHTD_DT_I: an {@link
 *     Optional}<{@link LocalDate}> shared field representing the medicare benefits
 *     exhausted date for the claim
 * @param diagnosisRelatedGroupCd CLM_DRG_CD: an {@link Optional}<{@link String}> shared
 *     field representing the non-covered stay from date for the claim
 */
static void assertCommonEobInformationInpatientSNF(ExplanationOfBenefit eob, Optional<LocalDate> noncoveredStayFromDate, Optional<LocalDate> noncoveredStayThroughDate, Optional<LocalDate> coveredCareThroughDate, Optional<LocalDate> medicareBenefitsExhaustedDate, Optional<String> diagnosisRelatedGroupCd) {
    // noncoveredStayFromDate & noncoveredStayThroughDate
    if (noncoveredStayFromDate.isPresent() || noncoveredStayThroughDate.isPresent()) {
        SupportingInformationComponent nchVrfdNcvrdStayInfo = TransformerTestUtils.assertHasInfo(CcwCodebookVariable.NCH_VRFD_NCVRD_STAY_FROM_DT, eob);
        TransformerTestUtils.assertPeriodEquals(noncoveredStayFromDate, noncoveredStayThroughDate, (Period) nchVrfdNcvrdStayInfo.getTiming());
    }
    // coveredCareThroughDate
    if (coveredCareThroughDate.isPresent()) {
        SupportingInformationComponent nchActvOrCvrdLvlCareThruInfo = TransformerTestUtils.assertHasInfo(CcwCodebookVariable.NCH_ACTV_OR_CVRD_LVL_CARE_THRU, eob);
        TransformerTestUtils.assertDateEquals(coveredCareThroughDate.get(), (DateTimeType) nchActvOrCvrdLvlCareThruInfo.getTiming());
    }
    // medicareBenefitsExhaustedDate
    if (medicareBenefitsExhaustedDate.isPresent()) {
        SupportingInformationComponent nchBeneMdcrBnftsExhtdDtIInfo = TransformerTestUtils.assertHasInfo(CcwCodebookVariable.NCH_BENE_MDCR_BNFTS_EXHTD_DT_I, eob);
        TransformerTestUtils.assertDateEquals(medicareBenefitsExhaustedDate.get(), (BaseDateTimeType) nchBeneMdcrBnftsExhtdDtIInfo.getTiming());
    }
    // diagnosisRelatedGroupCd
    assertHasCoding(CcwCodebookVariable.CLM_DRG_CD, diagnosisRelatedGroupCd, eob.getDiagnosisFirstRep().getPackageCode());
}
Also used : SupportingInformationComponent(org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent)

Example 2 with BaseDateTimeType

use of org.hl7.fhir.dstu3.model.BaseDateTimeType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opMinus.

private List<Base> opMinus(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 new PathEngineException("Error performing -: left operand has more than one value", expr.getStart(), expr.toString());
    if (!left.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType()), expr.getStart(), expr.toString());
    if (right.size() > 1)
        throw new PathEngineException("Error performing -: right operand has more than one value", expr.getStart(), expr.toString());
    if (!right.get(0).isPrimitive() && !((left.get(0).isDateTime() || "0".equals(left.get(0).primitiveValue()) || left.get(0).hasType("Quantity")) && right.get(0).hasType("Quantity")))
        throw new PathEngineException(String.format("Error performing -: right operand has the wrong type (%s)", right.get(0).fhirType()), expr.getStart(), expr.toString());
    List<Base> result = new ArrayList<Base>();
    Base l = left.get(0);
    Base r = right.get(0);
    if (l.hasType("integer") && r.hasType("integer"))
        result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) - Integer.parseInt(r.primitiveValue())));
    else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer"))
        result.add(new DecimalType(new BigDecimal(l.primitiveValue()).subtract(new BigDecimal(r.primitiveValue()))));
    else if (l.isDateTime() && r.hasType("Quantity"))
        result.add(dateAdd((BaseDateTimeType) l, (Quantity) r, true, expr));
    else
        throw new PathEngineException(String.format("Error performing -: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType()), expr.getStart(), expr.toString());
    return result;
}
Also used : PathEngineException(org.hl7.fhir.exceptions.PathEngineException) BigDecimal(java.math.BigDecimal)

Example 3 with BaseDateTimeType

use of org.hl7.fhir.dstu3.model.BaseDateTimeType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opPlus.

private List<Base> opPlus(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 new PathEngineException("Error performing +: left operand has more than one value", expr.getStart(), expr.toString());
    if (!left.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing +: left operand has the wrong type (%s)", left.get(0).fhirType()), expr.getStart(), expr.toString());
    if (right.size() > 1)
        throw new PathEngineException("Error performing +: right operand has more than one value", expr.getStart(), expr.toString());
    if (!right.get(0).isPrimitive() && !((left.get(0).isDateTime() || "0".equals(left.get(0).primitiveValue()) || left.get(0).hasType("Quantity")) && right.get(0).hasType("Quantity")))
        throw new PathEngineException(String.format("Error performing +: right operand has the wrong type (%s)", right.get(0).fhirType()), expr.getStart(), expr.toString());
    List<Base> result = new ArrayList<Base>();
    Base l = left.get(0);
    Base r = right.get(0);
    if (l.hasType(FHIR_TYPES_STRING) && r.hasType(FHIR_TYPES_STRING))
        result.add(new StringType(l.primitiveValue() + r.primitiveValue()));
    else if (l.hasType("integer") && r.hasType("integer"))
        result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) + Integer.parseInt(r.primitiveValue())));
    else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer"))
        result.add(new DecimalType(new BigDecimal(l.primitiveValue()).add(new BigDecimal(r.primitiveValue()))));
    else if (l.isDateTime() && r.hasType("Quantity"))
        result.add(dateAdd((BaseDateTimeType) l, (Quantity) r, false, expr));
    else
        throw new PathEngineException(String.format("Error performing +: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType()), expr.getStart(), expr.toString());
    return result;
}
Also used : PathEngineException(org.hl7.fhir.exceptions.PathEngineException) BigDecimal(java.math.BigDecimal)

Example 4 with BaseDateTimeType

use of org.hl7.fhir.dstu3.model.BaseDateTimeType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opPlus.

private List<Base> opPlus(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, "+");
    }
    if (!left.get(0).isPrimitive()) {
        throw makeException(expr, I18nConstants.FHIRPATH_LEFT_VALUE_WRONG_TYPE, "+", left.get(0).fhirType());
    }
    if (right.size() > 1) {
        throw makeException(expr, I18nConstants.FHIRPATH_RIGHT_VALUE_PLURAL, "+");
    }
    if (!right.get(0).isPrimitive() && !((left.get(0).isDateTime() || "0".equals(left.get(0).primitiveValue()) || left.get(0).hasType("Quantity")) && right.get(0).hasType("Quantity"))) {
        throw makeException(expr, I18nConstants.FHIRPATH_RIGHT_VALUE_WRONG_TYPE, "+", right.get(0).fhirType());
    }
    List<Base> result = new ArrayList<Base>();
    Base l = left.get(0);
    Base r = right.get(0);
    if (l.hasType(FHIR_TYPES_STRING) && r.hasType(FHIR_TYPES_STRING)) {
        result.add(new StringType(l.primitiveValue() + r.primitiveValue()));
    } else if (l.hasType("integer") && r.hasType("integer")) {
        result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) + Integer.parseInt(r.primitiveValue())));
    } else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer")) {
        result.add(new DecimalType(new BigDecimal(l.primitiveValue()).add(new BigDecimal(r.primitiveValue()))));
    } else if (l.isDateTime() && r.hasType("Quantity")) {
        result.add(dateAdd((BaseDateTimeType) l, (Quantity) r, false, expr));
    } else {
        throw makeException(expr, I18nConstants.FHIRPATH_OP_INCOMPATIBLE, "+", left.get(0).fhirType(), right.get(0).fhirType());
    }
    return result;
}
Also used : IntegerType(org.hl7.fhir.r5.model.IntegerType) StringType(org.hl7.fhir.r5.model.StringType) ArrayList(java.util.ArrayList) DecimalType(org.hl7.fhir.r5.model.DecimalType) Base(org.hl7.fhir.r5.model.Base) BigDecimal(java.math.BigDecimal)

Example 5 with BaseDateTimeType

use of org.hl7.fhir.dstu3.model.BaseDateTimeType in project pathling by aehrc.

the class DateTimePath method valueFromRow.

/**
 * Gets a value from a row for a DateTime or DateTime literal.
 *
 * @param row The {@link Row} from which to extract the value
 * @param columnNumber The column number to extract the value from
 * @param fhirType The FHIR type to assume when extracting the value
 * @return A {@link BaseDateTimeType}, or the absence of a value
 */
@Nonnull
public static Optional<BaseDateTimeType> valueFromRow(@Nonnull final Row row, final int columnNumber, final FHIRDefinedType fhirType) {
    if (row.isNullAt(columnNumber)) {
        return Optional.empty();
    }
    if (fhirType == FHIRDefinedType.INSTANT) {
        final InstantType value = new InstantType(row.getTimestamp(columnNumber));
        value.setTimeZone(TIME_ZONE);
        return Optional.of(value);
    } else {
        final DateTimeType value = new DateTimeType(row.getString(columnNumber));
        value.setTimeZone(TIME_ZONE);
        return Optional.of(value);
    }
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) BaseDateTimeType(org.hl7.fhir.r4.model.BaseDateTimeType) InstantType(org.hl7.fhir.r4.model.InstantType) Nonnull(javax.annotation.Nonnull)

Aggregations

BigDecimal (java.math.BigDecimal)6 ArrayList (java.util.ArrayList)4 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)4 Base (org.hl7.fhir.r4b.model.Base)2 DecimalType (org.hl7.fhir.r4b.model.DecimalType)2 IntegerType (org.hl7.fhir.r4b.model.IntegerType)2 Base (org.hl7.fhir.r5.model.Base)2 DecimalType (org.hl7.fhir.r5.model.DecimalType)2 IntegerType (org.hl7.fhir.r5.model.IntegerType)2 Nonnull (javax.annotation.Nonnull)1 SupportingInformationComponent (org.hl7.fhir.dstu3.model.ExplanationOfBenefit.SupportingInformationComponent)1 BaseDateTimeType (org.hl7.fhir.r4.model.BaseDateTimeType)1 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)1 InstantType (org.hl7.fhir.r4.model.InstantType)1 BaseDateTimeType (org.hl7.fhir.r4b.model.BaseDateTimeType)1 Quantity (org.hl7.fhir.r4b.model.Quantity)1 StringType (org.hl7.fhir.r4b.model.StringType)1 BaseDateTimeType (org.hl7.fhir.r5.model.BaseDateTimeType)1 Quantity (org.hl7.fhir.r5.model.Quantity)1 StringType (org.hl7.fhir.r5.model.StringType)1