Search in sources :

Example 21 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project fhir-bridge by ehrbase.

the class ProvideResourceAuditHandler method process.

@Override
public void process(Exchange exchange) throws Exception {
    RequestDetails requestDetails = getRequestDetails(exchange);
    AuditEvent auditEvent = new AuditEvent(new Coding("http://terminology.hl7.org/CodeSystem/audit-event-type", "rest", "RESTful Operation"), new InstantType(new Date()), getSource());
    getSubtype(requestDetails).ifPresent(auditEvent::addSubtype);
    getAction(requestDetails).ifPresent(auditEvent::setAction);
    Throwable ex = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
    if (ex == null) {
        auditEvent.setOutcome(AuditEvent.AuditEventOutcome._0);
        auditEvent.setOutcomeDesc("Operation completed successfully");
    } else {
        auditEvent.setOutcome(AuditEvent.AuditEventOutcome._8);
        auditEvent.setOutcomeDesc("Operation failed: " + ex.getMessage());
    }
    auditEvent.addAgent(getAgent(exchange));
    getEntity(exchange, requestDetails).ifPresent(auditEvent::addEntity);
    MethodOutcome outcome = auditEventDao.create(auditEvent, requestDetails);
    LOG.debug("Created AuditEvent: id={}", outcome.getId());
}
Also used : Coding(org.hl7.fhir.r4.model.Coding) AuditEvent(org.hl7.fhir.r4.model.AuditEvent) InstantType(org.hl7.fhir.r4.model.InstantType) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) RequestDetails(ca.uhn.fhir.rest.api.server.RequestDetails) Date(java.util.Date)

Example 22 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project integration-adaptor-111 by nhsconnect.

the class DateUtil method parseToInstantType.

public static InstantType parseToInstantType(String dateToParse) {
    DateFormat format = getFormat(dateToParse);
    SimpleDateFormat formatter = getFormatter(format);
    try {
        Date date = formatter.parse(dateToParse);
        return new InstantType(date, TemporalPrecisionEnum.MILLI, TimeZone.getTimeZone(ZoneOffset.UTC));
    } catch (ParseException e) {
        throw new IllegalStateException(String.format(ERROR_MESSAGE, dateToParse), e);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(uk.nhs.adaptors.oneoneone.cda.report.enums.DateFormat) DateTimeParseException(java.time.format.DateTimeParseException) ParseException(java.text.ParseException) InstantType(org.hl7.fhir.dstu3.model.InstantType) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 23 with InstantType

use of org.hl7.fhir.r4b.model.InstantType 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)

Example 24 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverter method toCohortParameter.

public static Parameter toCohortParameter(Extension extension) {
    Parameter parameter;
    Type extensionValue = extension.getValue();
    if (extensionValue instanceof Base64BinaryType) {
        parameter = new StringParameter(((Base64BinaryType) extensionValue).asStringValue());
    } else if (extensionValue instanceof BooleanType) {
        parameter = new BooleanParameter(((BooleanType) extensionValue).booleanValue());
    } else if (extensionValue instanceof DateType) {
        parameter = new DateParameter(((DateType) extensionValue).asStringValue());
    } else if (extensionValue instanceof DateTimeType) {
        parameter = convertDateTimeType((DateTimeType) extensionValue);
    } else if (extensionValue instanceof DecimalType) {
        parameter = new DecimalParameter(((DecimalType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof InstantType) {
        parameter = new DatetimeParameter(((InstantType) extensionValue).getValueAsString());
    } else if (extensionValue instanceof IntegerType) {
        parameter = new IntegerParameter(((IntegerType) extensionValue).getValue());
    } else if (extensionValue instanceof StringType) {
        parameter = new StringParameter(((StringType) extensionValue).getValue());
    } else if (extensionValue instanceof TimeType) {
        parameter = new TimeParameter(((TimeType) extensionValue).asStringValue());
    } else if (extensionValue instanceof UriType) {
        parameter = new StringParameter(((UriType) extensionValue).getValue());
    } else if (extensionValue instanceof Coding) {
        parameter = convertCoding((Coding) extensionValue);
    } else if (extensionValue instanceof CodeableConcept) {
        parameter = convertCodeableConcept((CodeableConcept) extensionValue);
    } else if (extensionValue instanceof Period) {
        Period castValue = (Period) extensionValue;
        parameter = new IntervalParameter(convertDateTimeType(castValue.getStartElement()), true, convertDateTimeType(castValue.getEndElement()), true);
    } else if (extensionValue instanceof Quantity) {
        parameter = convertQuantity((Quantity) extensionValue);
    } else if (extensionValue instanceof Range) {
        Range castValue = (Range) extensionValue;
        parameter = new IntervalParameter(convertQuantity(castValue.getLow()), true, convertQuantity(castValue.getHigh()), true);
    } else if (extensionValue instanceof Ratio) {
        Ratio castValue = (Ratio) extensionValue;
        parameter = new RatioParameter().setDenominator(convertQuantity(castValue.getDenominator())).setNumerator(convertQuantity(castValue.getNumerator()));
    } else {
        throw new UnsupportedFhirTypeException(extensionValue);
    }
    return parameter;
}
Also used : IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) StringType(org.hl7.fhir.r4.model.StringType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) TimeType(org.hl7.fhir.r4.model.TimeType) UriType(org.hl7.fhir.r4.model.UriType) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) Coding(org.hl7.fhir.r4.model.Coding) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) Ratio(org.hl7.fhir.r4.model.Ratio) InstantType(org.hl7.fhir.r4.model.InstantType) DateType(org.hl7.fhir.r4.model.DateType) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) UnsupportedFhirTypeException(com.ibm.cohort.engine.measure.parameter.UnsupportedFhirTypeException) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) BooleanType(org.hl7.fhir.r4.model.BooleanType) Period(org.hl7.fhir.r4.model.Period) Quantity(org.hl7.fhir.r4.model.Quantity) Range(org.hl7.fhir.r4.model.Range) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) IntegerType(org.hl7.fhir.r4.model.IntegerType) Type(org.hl7.fhir.r4.model.Type) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) StringType(org.hl7.fhir.r4.model.StringType) DecimalType(org.hl7.fhir.r4.model.DecimalType) IntegerType(org.hl7.fhir.r4.model.IntegerType) DateType(org.hl7.fhir.r4.model.DateType) TimeType(org.hl7.fhir.r4.model.TimeType) BooleanType(org.hl7.fhir.r4.model.BooleanType) InstantType(org.hl7.fhir.r4.model.InstantType) UriType(org.hl7.fhir.r4.model.UriType) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) IntervalParameter(com.ibm.cohort.cql.evaluation.parameters.IntervalParameter) DecimalParameter(com.ibm.cohort.cql.evaluation.parameters.DecimalParameter) ConceptParameter(com.ibm.cohort.cql.evaluation.parameters.ConceptParameter) QuantityParameter(com.ibm.cohort.cql.evaluation.parameters.QuantityParameter) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) DateParameter(com.ibm.cohort.cql.evaluation.parameters.DateParameter) StringParameter(com.ibm.cohort.cql.evaluation.parameters.StringParameter) CodeParameter(com.ibm.cohort.cql.evaluation.parameters.CodeParameter) TimeParameter(com.ibm.cohort.cql.evaluation.parameters.TimeParameter) BooleanParameter(com.ibm.cohort.cql.evaluation.parameters.BooleanParameter) Parameter(com.ibm.cohort.cql.evaluation.parameters.Parameter) DecimalType(org.hl7.fhir.r4.model.DecimalType) RatioParameter(com.ibm.cohort.cql.evaluation.parameters.RatioParameter) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 25 with InstantType

use of org.hl7.fhir.r4b.model.InstantType in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testInstant__shouldReturnDateTimeParameter.

@Test
public void testInstant__shouldReturnDateTimeParameter() {
    ParameterDefinition parameterDefinition = getBaseParameterDefinition("instant");
    String instantString = "2020-01-01T12:30:00.0Z";
    InstantType fhirValue = new InstantType(instantString);
    parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
    assertEquals(new DatetimeParameter(instantString), R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition));
}
Also used : DatetimeParameter(com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter) InstantType(org.hl7.fhir.r4.model.InstantType) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Test(org.junit.Test)

Aggregations

NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 InstantType (org.hl7.fhir.r4.model.InstantType)8 Test (org.junit.jupiter.api.Test)8 InstantType (org.hl7.fhir.r4b.model.InstantType)7 Date (java.util.Date)6 InstantType (org.hl7.fhir.dstu3.model.InstantType)6 Base64 (org.apache.commons.codec.binary.Base64)5 DateTimeType (org.hl7.fhir.r4.model.DateTimeType)4 InstantType (org.hl7.fhir.r5.model.InstantType)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 DateTimeType (org.hl7.fhir.r5.model.DateTimeType)3 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)3 DisplayName (org.junit.jupiter.api.DisplayName)3 DatetimeParameter (com.ibm.cohort.cql.evaluation.parameters.DatetimeParameter)2 BigDecimal (java.math.BigDecimal)2 TimeZone (java.util.TimeZone)2 BooleanType (org.hl7.fhir.dstu2.model.BooleanType)2 Coding (org.hl7.fhir.dstu2.model.Coding)2 DateTimeType (org.hl7.fhir.dstu2.model.DateTimeType)2 Enumeration (org.hl7.fhir.dstu2.model.Enumeration)2