Search in sources :

Example 6 with Function

use of org.hl7.fhir.dstu2.model.ExpressionNode.Function in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ObservationFHIRConversionTest method testObservationSTResult.

@Test
void testObservationSTResult() throws IOException {
    String hl7message = baseMessage + "OBX|1|ST|^Type of protein feed^L||Fourth Line: HYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%||||||F||||Alex||";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> obsResource = ResourceUtils.getResourceList(e, ResourceType.Observation);
    assertThat(obsResource).hasSize(1);
    Observation obs = (Observation) obsResource.get(0);
    assertThat(obs.getValueStringType()).isNotNull();
    StringType q = obs.getValueStringType();
    assertThat(q.asStringValue()).isEqualTo("Fourth Line: HYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%");
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) StringType(org.hl7.fhir.r4.model.StringType) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with Function

use of org.hl7.fhir.dstu2.model.ExpressionNode.Function in project hl7v2-fhir-converter by LinuxForHealth.

the class JvmTimeZoneIdTest method testEmptyDefaultTimeZoneYieldsJVMZoneId.

@Test
void testEmptyDefaultTimeZoneYieldsJVMZoneId() throws IOException {
    // Create our own properties file
    File configFile = new File(folder, "config.properties");
    writeSimpleProperties(configFile);
    System.setProperty(CONF_PROP_HOME, configFile.getParent());
    ConverterConfiguration.reset();
    // Prove that we're using our custom properties file with no ZoneId
    ConverterConfiguration theConvConfig = ConverterConfiguration.getInstance();
    // Four messages supported.  (Proves we're using our created file, not the default.)
    assertThat(theConvConfig.getSupportedMessageTemplates()).hasSize(13);
    // Purposely empty
    assertThat(theConvConfig.getZoneId()).isNull();
    // IMPORTANT: TimeZoneId's are different than an offset.  TimeZoneId's are a location.
    // The offset of the location changes depending on whether Daylight savings time is in effect.
    // Because we compare after processing, we can't compare locations, only offsets.
    // It is critical that when we compare offsets, we start with the same date, so the same daylight savings rules apply!
    // Otherwise a test might work only half of the year.
    // Calculate the local server zone offset
    // 20020202020000
    LocalDateTime localDateTime = LocalDateTime.of(2002, Month.FEBRUARY, 2, 2, 0, 0);
    String defaultLocalZone = TimeZone.getDefault().getID();
    ZoneId localZoneId = ZoneId.of(defaultLocalZone);
    ZonedDateTime localZonedDateTime = localDateTime.atZone(localZoneId);
    ZoneOffset localOffset = localZonedDateTime.getOffset();
    // PART 1
    // Test the format utility (which will fallback to local server time and zone offset)
    String testDateTime = DateUtil.formatToDateTimeWithDefaultZone("20020202020000");
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    ZonedDateTime testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
    ZoneOffset testOffset = testZonedDateTime.getOffset();
    // Offset from our function call test should equal offset of the local time
    assertThat(testOffset).isEqualTo(localOffset);
    // PART 2
    // Do the same for a date going through the entire conversion
    String hl7message = "MSH|^~\\&|||||20020202020000|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // PRB.2 to recordedDateTime (check time ZoneId)
    "PRB|AD|20020202020000|K80.00^Cholelithiasis^I10|53956||||||||||||\r";
    ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().build();
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
    // Find the condition from the FHIR bundle.
    List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditionResource).hasSize(1);
    Condition condition = (Condition) conditionResource.get(0);
    // Get the recordedDate value; convert it back to a zoned time; get the offset for comparison
    // PRB.2
    testDateTime = condition.getRecordedDateElement().getValueAsString();
    testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
    testOffset = testZonedDateTime.getOffset();
    // Offset from our test should equal offset of the local time
    assertThat(testOffset).isEqualTo(localOffset);
// After the test, the properties file resets.
}
Also used : LocalDateTime(java.time.LocalDateTime) Condition(org.hl7.fhir.r4.model.Condition) ZoneId(java.time.ZoneId) ConverterOptions(io.github.linuxforhealth.hl7.ConverterOptions) Builder(io.github.linuxforhealth.hl7.ConverterOptions.Builder) Resource(org.hl7.fhir.r4.model.Resource) ConverterConfiguration(io.github.linuxforhealth.core.config.ConverterConfiguration) ZoneOffset(java.time.ZoneOffset) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ZonedDateTime(java.time.ZonedDateTime) File(java.io.File) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.jupiter.api.Test)

Example 8 with Function

use of org.hl7.fhir.dstu2.model.ExpressionNode.Function in project cqf-ruler by DBCG.

the class Libraries method getFunctions.

static LibraryFunctions getFunctions(FhirVersionEnum fhirVersionEnum) {
    FhirContext fhirContext = FhirContext.forCached(fhirVersionEnum);
    Class<? extends IBaseResource> libraryClass = fhirContext.getResourceDefinition(LIBRARY_RESOURCE_TYPE).getImplementingClass();
    Function<IBase, List<IBase>> attachments = Reflections.getFunction(libraryClass, "content");
    Function<IBase, String> contentType = Reflections.getPrimitiveFunction(fhirContext.getElementDefinition("Attachment").getImplementingClass(), "contentType");
    Function<IBase, byte[]> content = Reflections.getPrimitiveFunction(fhirContext.getElementDefinition("Attachment").getImplementingClass(), "data");
    Function<IBase, String> version = Reflections.getVersionFunction(libraryClass);
    return new LibraryFunctions(attachments, contentType, content, version);
}
Also used : FhirContext(ca.uhn.fhir.context.FhirContext) ArrayList(java.util.ArrayList) List(java.util.List) IBase(org.hl7.fhir.instance.model.api.IBase)

Example 9 with Function

use of org.hl7.fhir.dstu2.model.ExpressionNode.Function in project cqf-ruler by DBCG.

the class Reflections method getPrimitiveFunction.

/**
 * Generates a function to access a primitive property of the given
 * BaseType.
 *
 * @param <BaseType>       an IBase type
 * @param <ReturnType>     a return type for the Functions
 * @param theBaseTypeClass the class of a the IBase type
 * @param theChildName     to create a function for
 * @return a function for accessing the "theChildName" property of the
 *         BaseType
 */
@SuppressWarnings("unchecked")
public static <BaseType extends IBase, ReturnType> Function<BaseType, ReturnType> getPrimitiveFunction(final Class<? extends BaseType> theBaseTypeClass, String theChildName) {
    checkNotNull(theBaseTypeClass);
    checkNotNull(theChildName);
    IAccessor accessor = getAccessor(theBaseTypeClass, theChildName);
    return r -> {
        Optional<IBase> value = accessor.getFirstValueOrNull(r);
        if (!value.isPresent()) {
            return null;
        } else {
            return ((IPrimitiveType<ReturnType>) value.get()).getValue();
        }
    };
}
Also used : List(java.util.List) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor) FhirContext(ca.uhn.fhir.context.FhirContext) IBase(org.hl7.fhir.instance.model.api.IBase) BaseRuntimeElementDefinition(ca.uhn.fhir.context.BaseRuntimeElementDefinition) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IPrimitiveType(org.hl7.fhir.instance.model.api.IPrimitiveType) Optional(java.util.Optional) RuntimeResourceDefinition(ca.uhn.fhir.context.RuntimeResourceDefinition) Function(java.util.function.Function) Optional(java.util.Optional) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor)

Example 10 with Function

use of org.hl7.fhir.dstu2.model.ExpressionNode.Function in project cqf-ruler by DBCG.

the class ReflectionsTest method testGetName.

@Test
public void testGetName() {
    Library library = new Library().setName("test");
    Function<Library, String> getName = Reflections.getNameFunction(library.getClass());
    String name = getName.apply(library);
    assertEquals("test", name);
}
Also used : Library(org.hl7.fhir.dstu3.model.Library) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)17 List (java.util.List)8 FhirPath (au.csiro.pathling.fhirpath.FhirPath)7 Reference (org.hl7.fhir.r4.model.Reference)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 ParserContext (au.csiro.pathling.fhirpath.parser.ParserContext)6 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)6 URI (java.net.URI)6 Row (org.apache.spark.sql.Row)6 Session (org.eclipse.jetty.websocket.api.Session)6 ClientUpgradeRequest (org.eclipse.jetty.websocket.client.ClientUpgradeRequest)6 WebSocketClient (org.eclipse.jetty.websocket.client.WebSocketClient)6 IIdType (org.hl7.fhir.instance.model.api.IIdType)6 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)6 FhirReference (org.openmrs.module.fhir2.model.FhirReference)6 FhirTask (org.openmrs.module.fhir2.model.FhirTask)6 DatasetBuilder (au.csiro.pathling.test.builders.DatasetBuilder)5 ElementPathBuilder (au.csiro.pathling.test.builders.ElementPathBuilder)5 ParserContextBuilder (au.csiro.pathling.test.builders.ParserContextBuilder)5 ArrayList (java.util.ArrayList)5