Search in sources :

Example 46 with Function

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

the class Reflections method getFunction.

/**
 * 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 extends List<? extends IBase>> Function<BaseType, ReturnType> getFunction(final Class<? extends BaseType> theBaseTypeClass, String theChildName) {
    checkNotNull(theBaseTypeClass);
    checkNotNull(theChildName);
    IAccessor accessor = getAccessor(theBaseTypeClass, theChildName);
    return r -> {
        return (ReturnType) accessor.getValues(r);
    };
}
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) IAccessor(ca.uhn.fhir.context.BaseRuntimeChildDefinition.IAccessor)

Example 47 with Function

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

the class ReflectionsTest method testGetNameLiteral.

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

Example 48 with Function

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

the class ReflectionsTest method testGetVersion.

@Test
public void testGetVersion() {
    Library library = new Library().setVersion("test");
    Function<Library, String> getVersion = Reflections.getVersionFunction(library.getClass());
    String version = getVersion.apply(library);
    assertEquals("test", version);
}
Also used : Library(org.hl7.fhir.dstu3.model.Library) Test(org.junit.jupiter.api.Test)

Example 49 with Function

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

the class HL7OMLMessageTest method testOMLO21WithPatientWithPatientVisitAndMinimumOrder.

@Test
public void testOMLO21WithPatientWithPatientVisitAndMinimumOrder() throws IOException {
    String hl7message = "MSH|^~\\&||Test System|||20210917110100||OML^O21^OML_O21|||2.6\r" + "PID|1||7659afb9-0dfc-d744-1f40-5b9314807108^^^^MR||Feeney^Sam^^^^^L|||M||||||||\r" + "PV1|1|O|||||||||||||||||2462201|||||||||||||||||||||||||20180520230000\r" + "ORC|NW|8125550e-04db-11ec-a9a8-086d41d421ca^^ID^UUID||||||||||\r";
    String json = ftv.convert(hl7message, OPTIONS_PRETTYPRINT);
    assertThat(json).isNotBlank();
    IBaseResource bundleResource = context.getParser().parseResource(json);
    assertThat(bundleResource).isNotNull();
    Bundle b = (Bundle) bundleResource;
    List<BundleEntryComponent> e = b.getEntry();
    List<Resource> patientResource = ResourceUtils.getResourceList(e, ResourceType.Patient);
    // from PID
    assertThat(patientResource).hasSize(1);
    List<Resource> encounterResource = ResourceUtils.getResourceList(e, ResourceType.Encounter);
    // from PV1
    assertThat(encounterResource).hasSize(1);
    // TODO: When function is added to create ServiceRequest from ORC then also check for ServiceRequest
    // List<Resource> serviceResource = e.stream()
    // .filter(v -> ResourceType.ServiceRequest == v.getResource().getResourceType())
    // .map(BundleEntryComponent::getResource).collect(Collectors.toList());
    // assertThat(serviceResource).hasSize(1);
    // Confirm that there are no extra resources
    // TODO: When ServiceRequest is added then this line should check for 3.
    assertThat(e.size()).isEqualTo(2);
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Resource(org.hl7.fhir.r4.model.Resource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Test(org.junit.jupiter.api.Test)

Example 50 with Function

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

the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_ppr_test.

@ParameterizedTest
// Spot check for PPR messages
@ValueSource(strings = { "PPR^PC1" /* "PPR^PC2", "PPR^PC3" */
})
void doc_ref_ppr_test(String messageType) {
    String documentReferenceMessage = "MSH|^~\\&|SendTest1|Sendfac1|Receiveapp1|Receivefac1|202101010000|security|" + messageType + "|1|P^I|2.6||||||ASCII||\r" + "PID|||1234^^^^MR||DOE^JANE^|||F|||||||||||||||||||||\r" + "PV1||I|6N^1234^A^GENHOS|||||||SUR|||||||0148^ANDERSON^CARL|S|1400|A|||||||||||||||||||SF|K||||199501102300\r" + "PRB|AD||202101010000|aortic stenosis|53692||2|||202101010000\r" + "OBX|1|NM|111^TotalProtein||7.5|gm/dl|5.9-8.4||||F\r" + "NTE|1|P|Problem Comments\r" + "ORC|NW|1000^OE|9999999^RX|||E|^Q6H^D10^^^R\r" + "OBR|1|TESTID|TESTID|||201801180346|201801180347||||||||||||||||||F||||||WEAKNESS||||||||||||\r" + // Next three lines create an attachment because OBX type TX
    "OBX|1|TX|||ECHOCARDIOGRAPHIC REPORT||||||F|||202101010000|||\r" + "OBX|2|TX|||NORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH||||||F|||202101010000|||\r" + "OBX|3|TX|||HYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%||||||F|||202101010000|||\n";
    DocumentReference documentRef = ResourceUtils.getDocumentReference(ftv, documentReferenceMessage);
    DocumentReference.DocumentReferenceContextComponent drContext = documentRef.getContext();
    // Should contain a reference to the service request
    assertThat(drContext.hasPeriod()).isFalse();
    DocumentReference.DocumentReferenceContentComponent content = documentRef.getContentFirstRep();
    // Currently always defaults to text/plain
    assertThat(content.getAttachment().getContentType()).isEqualTo("text/plain");
    // No TXA.7 in message
    assertThat(content.getAttachment().getCreation()).isNull();
    assertThat(content.getAttachment().hasData()).isTrue();
    String decodedData = new String(Base64.getDecoder().decode(content.getAttachment().getDataElement().getValueAsString()));
    assertThat(decodedData).isEqualTo("ECHOCARDIOGRAPHIC REPORT\nNORMAL LV CHAMBER SIZE WITH MILD CONCENTRIC LVH\nHYPERDYNAMIC LV SYSTOLIC FUNCTION, VISUAL EF 80%");
}
Also used : DocumentReference(org.hl7.fhir.r4.model.DocumentReference) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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