Search in sources :

Example 11 with Range

use of org.hl7.fhir.r4b.model.Range in project kindling by HL7.

the class FhirTurtleGenerator method genBaseMetadata.

/**
 * Emit all the basic atoms that are implicit in the actual model
 */
private void genBaseMetadata() {
    // Declare these for now - they will get filled in more completely later on
    FHIRResource Resource = fact.fhir_class("Resource");
    FHIRResource Element = fact.fhir_class("Element");
    FHIRResource Reference = fact.fhir_class("Reference");
    // Primitive isn't in the actual model - added here
    fact.fhir_class("Primitive").addTitle("Types with only a value").addDefinition("Types with only a value and no additional elements as children").restriction(fact.fhir_restriction(value, RDFS.Literal));
    // A resource can have an optional nodeRole
    FHIRResource treeRoot = fact.fhir_class("treeRoot").addTitle("Class of FHIR base documents");
    FHIRResource nodeRole = fact.fhir_objectProperty("nodeRole").addTitle("Identifies role of subject in context of a given document").domain(Resource).range(treeRoot.resource);
    Resource.restriction(fact.fhir_cardinality_restriction(nodeRole.resource, treeRoot.resource, 0, 1));
    // Any element can have an index to assign order in a list
    FHIRResource index = fact.fhir_dataProperty("index").addTitle("Ordering value for list").domain(Element).range(XSD.nonNegativeInteger);
    Element.restriction(fact.fhir_cardinality_restriction(index.resource, XSD.nonNegativeInteger, 0, 1));
    // References have an optional link
    FHIRResource link = fact.fhir_objectProperty("link").addTitle("URI of a reference");
    Reference.restriction(fact.fhir_cardinality_restriction(link.resource, Resource.resource, 0, 1));
    // XHTML is an XML Literal -- but it isn't recognized by OWL so we use string
    FHIRResource NarrativeDiv = fact.fhir_dataProperty("Narrative.div");
    fact.fhir_class("xhtml", "Primitive").restriction(fact.fhir_cardinality_restriction(value, fact.fhir_datatype(XSD.xstring).resource, 1, 1));
}
Also used : FHIRResource(org.hl7.fhir.rdf.FHIRResource)

Example 12 with Range

use of org.hl7.fhir.r4b.model.Range in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7AddressFHIRConversionTest method patient_address_date_ranges_test.

@Test
void patient_address_date_ranges_test() {
    String patientAddress = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + "PID|1||12345678^^^^MR|ALTID|Moose^Mickey^J^III^^^|Mother^Micky|20060504|M|Alias^Alias|2106-3^White^ HL70005|111 1st Street^Suite #1^Minneapolis^MN^11111^USA^H^^AdrC^^^20010101&20081231^^^^Y^Z^V^c/o Pluto19|PatC|^PRN^^^PH^555^5555555|^PRN^^^PH^555^666666|english|married|bhuddist|1234567_account|111-22-3333|||2186-5^not Hispanic or Latino^CDCREC|Born in USA|||USA||||\n";
    String patientAddressExplicitEffectiveExpirationDates = "MSH|^~\\&|MIICEHRApplication|MIIC|MIIC|MIIC|201705130822||VXU^V04^VXU_V04|test1100|P|2.5.1|||AL|AL|||||Z22^CDCPHINVS|^^^^^MIIC^SR^^^MIIC|MIIC\n" + "PID|1||12345678^^^^MR|ALTID|Moose^Mickey^J^III^^^|Mother^Micky|20060504|M|Alias^Alias|2106-3^White^ HL70005|111 1st Street^Suite #1^Minneapolis^MN^11111^USA^H^^AdrC^^^20010101&20081231^19920101^19981231^^Y^Z^V^c/o Pluto19|PatC|^PRN^^^PH^555^5555555|^PRN^^^PH^555^666666|english|married|bhuddist|1234567_account|111-22-3333|||2186-5^not Hispanic or Latino^CDCREC|Born in USA|||USA||||\n";
    // If address county, ignore patient county
    Patient patient = PatientUtils.createPatientFromHl7Segment(ftv, patientAddress);
    assertThat(patient.hasAddress()).isTrue();
    List<Address> addresses = patient.getAddress();
    assertThat(addresses.size()).isEqualTo(1);
    Address address = addresses.get(0);
    // Test date range
    Period period = address.getPeriod();
    assertThat(period.hasStart()).isTrue();
    assertThat(period.hasEnd()).isTrue();
    Date startDate = period.getStart();
    Calendar startCalendar = Calendar.getInstance();
    startCalendar.setTime(startDate);
    assertThat(startCalendar.get(Calendar.YEAR)).isEqualTo(2001);
    // Zero based; January is 0
    assertThat(startCalendar.get(Calendar.MONTH)).isZero();
    assertThat(startCalendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(1);
    Date endDate = period.getEnd();
    Calendar endCalendar = Calendar.getInstance();
    endCalendar.setTime(endDate);
    assertThat(endCalendar.get(Calendar.YEAR)).isEqualTo(2008);
    // Zero based; December is 11
    assertThat(endCalendar.get(Calendar.MONTH)).isEqualTo(11);
    assertThat(endCalendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(31);
    // Test explicit date start (effective) and end (expiration)
    patient = PatientUtils.createPatientFromHl7Segment(ftv, patientAddressExplicitEffectiveExpirationDates);
    assertThat(patient.hasAddress()).isTrue();
    addresses = patient.getAddress();
    assertThat(addresses.size()).isEqualTo(1);
    address = addresses.get(0);
    period = address.getPeriod();
    assertThat(period.hasStart()).isTrue();
    assertThat(period.hasEnd()).isTrue();
    startDate = period.getStart();
    startCalendar = Calendar.getInstance();
    startCalendar.setTime(startDate);
    assertThat(startCalendar.get(Calendar.YEAR)).isEqualTo(1992);
    // Zero based; January is 0
    assertThat(startCalendar.get(Calendar.MONTH)).isZero();
    assertThat(startCalendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(1);
    endDate = period.getEnd();
    endCalendar = Calendar.getInstance();
    endCalendar.setTime(endDate);
    assertThat(endCalendar.get(Calendar.YEAR)).isEqualTo(1998);
    // Zero based; December is 11
    assertThat(endCalendar.get(Calendar.MONTH)).isEqualTo(11);
    assertThat(endCalendar.get(Calendar.DAY_OF_MONTH)).isEqualTo(31);
}
Also used : Address(org.hl7.fhir.r4.model.Address) Calendar(java.util.Calendar) Patient(org.hl7.fhir.r4.model.Patient) Period(org.hl7.fhir.r4.model.Period) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 13 with Range

use of org.hl7.fhir.r4b.model.Range in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7ObservationFHIRConversionTest method testObservationSN_valueQuantity_missing_comparator_result.

@Test
void testObservationSN_valueQuantity_missing_comparator_result() throws IOException {
    String hl7message = baseMessage + "OBX|1|SN|1554-5^GLUCOSE||^182|mg/dl|70_105||||F";
    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);
    // Check valueQuantity
    assertNotNull(obs.getValueQuantity());
    Quantity q = obs.getValueQuantity();
    // code only set if system exists
    assertNull(q.getCode());
    assertEquals("mg/dl", q.getUnit());
    assertNull(q.getSystem());
    assertEquals(182, q.getValue().floatValue());
    // no comparator passed in
    assertNull(q.getComparator());
    // Check referenceRange
    assertTrue(obs.hasReferenceRange());
    assertThat(obs.getReferenceRange()).hasSize(1);
    ObservationReferenceRangeComponent range = obs.getReferenceRangeFirstRep();
    assertNotNull(range);
    assertTrue(range.hasHigh());
    assertTrue(range.hasLow());
    Quantity high = range.getHigh();
    // uses OBX.6.1 for units not text in string
    assertEquals("mg/dl", high.getUnit());
    assertEquals(105f, high.getValue().floatValue());
    Quantity low = range.getLow();
    // uses OBX.6.1 for units not text in string
    assertEquals("mg/dl", low.getUnit());
    assertEquals(70f, low.getValue().floatValue());
    assertEquals("70_105", range.getText());
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ObservationReferenceRangeComponent(org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) Observation(org.hl7.fhir.r4.model.Observation) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with Range

use of org.hl7.fhir.r4b.model.Range in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestRateQuantityRXO.

@Test
void dosageInstructionTestRateQuantityRXO() {
    // Test dosageInstruction.rateQuantity where RXO.21 exists and RXO.17 does not exist -> use RXO segment, no range
    String hl7message = "MSH|^~\\\\&|||||20210101000000||OMP^O09|MSGID|T|2.6\n" + "PID|||1234||DOE^JANE^|||F||||||||||||||||||||||\n" + "PV1||||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|OP||||||||||||||||||||||\n" + // RXO.22.3 purposely empty to check that default system is used
    "RXO|00054418425^Dexamethasone 4 MG Oral Tablet^NDC||||||||||||||||||||6|PC||||||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    // Confirm that one medicationRequest was created.
    assertThat(medicationRequestList).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
    Quantity rateQuantity = medicationRequest.getDosageInstructionFirstRep().getDoseAndRateFirstRep().getRateQuantity();
    // dosageInstruction.doseAndRate.rateQuantity RXO.21
    // RXO.21
    assertThat(rateQuantity.getValue()).hasToString("6.0");
    // RXO.22.1
    assertThat(rateQuantity.getUnit()).isEqualTo("PC");
    // default
    assertThat(rateQuantity.getSystem()).isEqualTo("http://unitsofmeasure.org");
    // Verify no extraneous resources
    // Expect MedicationRequest, and Patient
    assertThat(e).hasSize(2);
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with Range

use of org.hl7.fhir.r4b.model.Range in project hl7v2-fhir-converter by LinuxForHealth.

the class Hl7MedicationRequestFHIRConversionTest method dosageInstructionTestRateQuantityRXE.

@Test
void dosageInstructionTestRateQuantityRXE() {
    // Test dosageInstruction.rateQuantity where RXE.23 exists and RXE.22 does not exist -> use RXE segment, no range
    String hl7message = "MSH|^~\\&||||||S1|RDE^O11||T|2.6|||||||||\n" + "PID|||1234^^^^MR||DOE^JANE^|||F||||||||||||||||||||||\n" + "ORC|NW|||||E|||||||||||||||||||||||I\n" + "RXE||DUONEB3INH^3 ML PLAS CONT : IPRATROPIUM-ALBUTEROL 0.5-2.5 (3) MG/3ML IN SOLN^ADS|||||||||||||||||||" + // RXE.24.3 purposely empty to check that default system is used
    "||7|PC^^http://unitsofmeasure.org||||||||||||||||\n";
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message);
    List<Resource> medicationRequestList = ResourceUtils.getResourceList(e, ResourceType.MedicationRequest);
    // Confirm that one medicationRequest was created.
    assertThat(medicationRequestList).hasSize(1);
    MedicationRequest medicationRequest = ResourceUtils.getResourceMedicationRequest(medicationRequestList.get(0), ResourceUtils.context);
    Quantity rateQuantity = medicationRequest.getDosageInstructionFirstRep().getDoseAndRateFirstRep().getRateQuantity();
    // dosageInstruction.doseAndRate.rateQuantity RXE.23
    // RXO.23
    assertThat(rateQuantity.getValue()).hasToString("7.0");
    // RXO.24.1
    assertThat(rateQuantity.getUnit()).isEqualTo("PC");
    // RXO.24.3
    assertThat(rateQuantity.getSystem()).isEqualTo("http://unitsofmeasure.org");
    // Verify no extraneous resources
    // Expect MedicationRequest, and Patient
    assertThat(e).hasSize(2);
}
Also used : MedicationRequest(org.hl7.fhir.r4.model.MedicationRequest) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Resource(org.hl7.fhir.r4.model.Resource) Quantity(org.hl7.fhir.r4.model.Quantity) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Test (org.junit.jupiter.api.Test)18 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)15 Quantity (org.hl7.fhir.r4.model.Quantity)14 Resource (org.hl7.fhir.r4.model.Resource)13 NotImplementedException (org.apache.commons.lang3.NotImplementedException)12 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Search (ca.uhn.fhir.rest.annotation.Search)11 Trace (com.newrelic.api.agent.Trace)10 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)10 Beneficiary (gov.cms.bfd.model.rif.Beneficiary)9 ArrayList (java.util.ArrayList)9 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)8 Operation (gov.cms.bfd.server.war.Operation)8 OffsetLinkBuilder (gov.cms.bfd.server.war.commons.OffsetLinkBuilder)8 Date (java.util.Date)8 Range (org.hl7.fhir.r4.model.Range)8 ResourceNotFoundException (ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException)7 List (java.util.List)7 Bundle (org.hl7.fhir.r4.model.Bundle)7