예제 #1
0
 def setUp(self):
     self._test_data_dir = os.path.join(absltest.get_default_test_srcdir(),
                                        _TESTDATA_PATH)
     self._enc = resources_pb2.Encounter()
     with open(os.path.join(self._test_data_dir, 'encounter_1.pbtxt')) as f:
         text_format.Parse(f.read(), self._enc)
     self._bundle = resources_pb2.Bundle()
     self._bundle.entry.add().resource.encounter.CopyFrom(self._enc)
     self._synthea_enc = resources_pb2.Encounter()
     with open(os.path.join(self._test_data_dir,
                            'encounter_synthea.pbtxt')) as f:
         text_format.Parse(f.read(), self._synthea_enc)
     self._synthea_bundle = resources_pb2.Bundle()
     self._synthea_bundle.entry.add().resource.encounter.CopyFrom(
         self._synthea_enc)
예제 #2
0
  def setUp(self):
    self._test_data_dir = os.path.join(absltest.get_default_test_srcdir(),
                                       _TESTDATA_PATH)
    self._bundle = resources_pb2.Bundle()
    with open(os.path.join(self._test_data_dir, 'bundle_1.pbtxt')) as f:
      text_format.Parse(f.read(), self._bundle)
    enc = self._bundle.entry[0].resource.encounter
    patient = self._bundle.entry[1].resource.patient

    self._expected_label = label.ComposeLabel(
        patient, enc,
        label.LOS_RANGE_LABEL,
        'above_14',
        # 24 hours after admission
        datetime.datetime(2009, 2, 14, 23, 31, 30))
예제 #3
0
 def testGetPatient(self):
   patient = resources_pb2.Patient()
   text_format.Merge(
       """
   id: {
     value: "Patient/1"
   }
   birth_date: {
      # February 13, 2009 11:31:30 PM
       value_us : 1234567890000000
       timezone : "America/New_York"
       precision: DAY
   }
   """, patient)
   bundle = resources_pb2.Bundle()
   bundle.entry.add().resource.patient.CopyFrom(patient)
   p = util.GetPatient(bundle)
   self.assertEqual(patient, p)
예제 #4
0
    def setUp(self):
        self._test_data_dir = os.path.join(absltest.get_default_test_srcdir(),
                                           _TESTDATA_PATH)
        enc = resources_pb2.Encounter()
        with open(os.path.join(self._test_data_dir, 'encounter_1.pbtxt')) as f:
            text_format.Parse(f.read(), enc)
        patient = resources_pb2.Patient()
        patient.id.value = 'Patient/1'
        self._bundle = resources_pb2.Bundle()
        self._bundle.entry.add().resource.encounter.CopyFrom(enc)
        self._bundle.entry.add().resource.patient.CopyFrom(patient)

        self._expected_label = label.ComposeLabel(
            patient,
            enc,
            label.LOS_RANGE_LABEL,
            'above_14',
            # 24 hours after admission
            datetime.datetime(2009, 2, 14, 23, 31, 30))
예제 #5
0
 def _VerifyPipeline(self, for_synthea: bool):
     bundle_text_file = 'bundle_1.pbtxt'
     if for_synthea:
         bundle_text_file = 'bundle_synthea.pbtxt'
     bundle = resources_pb2.Bundle()
     with open(os.path.join(self._test_data_dir, bundle_text_file)) as f:
         text_format.Parse(f.read(), bundle)
     enc = bundle.entry[0].resource.encounter
     patient = bundle.entry[1].resource.patient
     expected_label = label.ComposeLabel(
         patient,
         enc,
         label.LOS_RANGE_LABEL,
         'above_14',
         # 24 hours after admission
         datetime.datetime(2009, 2, 14, 23, 31, 30))
     with test_pipeline.TestPipeline() as pipeline:
         result = (pipeline
                   | 'input' >> beam.Create([bundle])
                   | 'process' >> beam.ParDo(
                       bundle_to_label.LengthOfStayRangeLabelAt24HoursFn(
                           for_synthea)))
         util.assert_that(result, util.equal_to([expected_label]))
예제 #6
0
    def testKeyBundleByPatientId(self):
        bundle = text_format.Parse(
            """
      entry { resource { patient {
        id { value: "14" }
      } } }""", resources_pb2.Bundle())
        with test_pipeline.TestPipeline() as p:
            result = (p
                      | "CreateBundles" >> beam.Create([bundle])
                      | "KeyBundleByPatientId" >> beam.ParDo(
                          bundle_to_seqex.KeyBundleByPatientIdFn()))

            def check_result(got):
                try:
                    self.assertLen(got, 1)
                    (got_key, got_bundle) = got[0]
                    self.assertEqual(b"Patient/14", got_key)
                    self.assertProtoEqual(got_bundle, bundle)

                except AssertionError as err:
                    raise util.BeamAssertException(err)

            util.assert_that(result, check_result)
예제 #7
0
  def testSingleTriggerAndStats(self):
    event_trigger = text_format.Parse(
        """
      event_time { value_us: 1420102800000000 }
    """, google_extensions_pb2.EventTrigger())
    event_trigger_labels = (event_trigger, list())
    event_trigger_labels_list = (event_trigger_labels,)

    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
        birth_date { value_us: 8640000000000 }
      } } }
      entry { resource { medication_request {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        contained {
          medication {
            id { value: "med" }
            code { coding {
              system { value:
                "http://hl7.org/fhir/sid/ndc"
              }
              code { value: "123" }
            } }
          }
        }
        authored_on {
          value_us: 1420095600000000 # "2015-01-01T07:00:00+00:00"
        }
        medication { reference {
          medication_id { value: "med" }
        } }
      } } }
    """, resources_pb2.Bundle())
    expected_seqex = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1420095600 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "Patient.birthDate"
          value { int64_list { value: 8640000 } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 1 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1420102800 } }
        } }
        feature_lists: {
          feature_list {
            key: "MedicationRequest.contained.medication.code.ndc"
            value { feature { bytes_list { value: "123" } } }
          }
          feature_list {
            key: "MedicationRequest.meta.lastUpdated"
            value { feature { int64_list { value: 1420095600 } } }
          }
          feature_list {
            key: "MedicationRequest.authoredOn"
            value { feature { int64_list { value: 1420095600 } } }
          }
          feature_list {
            key: "eventId"
            value { feature { int64_list { value: 1420095600 } } }
          }
          feature_list {
            key: "MedicationRequest.contained.medication.code"
            value { feature { bytes_list { value: "ndc:123" } } }
          }
          feature_list {
            key: "encounterId"
            value { feature { int64_list { value: 1420095600 } } }
          }
        }
    """, example_pb2.SequenceExample())
    got_stats = self._runTest(
        "Patient/14", bundle, event_trigger_labels_list,
        (("Patient/14:0-1@1420102800", expected_seqex, 1),))
    # We only spot check a few counters here. The main goal is to make sure
    # we get the counters back from c++ land.
    self.assertEqual(1, got_stats.get("num-examples"))
예제 #8
0
  def testMultipleTriggersAndExamples(self):
    event_trigger1 = text_format.Parse(
        """
      event_time { value_us: 1417424400000000 }
      source { encounter_id { value: "1" } }
    """, google_extensions_pb2.EventTrigger())
    event_trigger2 = text_format.Parse(
        """
      event_time { value_us: 1420102800000000 }
      source { encounter_id { value: "2" } }
    """, google_extensions_pb2.EventTrigger())
    event_trigger_labels1 = (
        event_trigger1,
        list(),
    )
    event_trigger_labels2 = (
        event_trigger2,
        list(),
    )
    event_trigger_labels_list = (
        event_trigger_labels1,
        event_trigger_labels2,
    )

    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
      } } }
      entry {
        resource { encounter {
          id { value: "1" }
          subject { patient_id { value: "14" } }
          class_value {
            system { value: "http://hl7.org/fhir/v3/ActCode" }
            code { value: "IMP" }
          }
          reason {
            coding {
              system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
              code { value: "V410.9" }
              display { value: "Standard issue" }
            }
          }
          period {
            start {
              value_us: 1417420800000000 # "2014-12-01T08:00:00+00:00"
            }
            end {
              value_us: 1417424400000000 # "2014-12-01T09:00:00+00:00"
            }
          }
        } }
      }
      entry {
        resource { encounter {
          id { value: "2" }
          subject { patient_id { value: "14" } }
          class_value {
            system { value: "http://hl7.org/fhir/v3/ActCode" }
            code { value: "IMP" }
          }
          reason {
            coding {
              system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
              code { value: "191.4" }
              display { value: "Malignant neoplasm of occipital lobe" }
            }
          }
          period {
            start {
              value_us: 1420099200000000 # "2015-01-01T08:00:00+00:00"
            }
            end {
              value_us: 1420102800000000 # "2015-01-01T09:00:00+00:00"
            }
          }
        } }
      }
    """, resources_pb2.Bundle())
    # pylint: disable=line-too-long
    expected_seqex1 = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1417420800 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 2 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1417424400 } } }
        }
        feature_lists: {
          feature_list {
            key: "Encounter.class"
            value { feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { value: "actcode:IMP" } } }
          }
          feature_list {
            key: "Encounter.meta.lastUpdated"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } }
          }
          feature_list {
            key: "Encounter.period.start"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } }
          }
          feature_list {
            key: "Encounter.period.end"
            value { feature { int64_list { } } feature { int64_list { value: 1417424400 } } }
          }
          feature_list {
            key: "Encounter.reason"
            value { feature { bytes_list { } } feature { bytes_list { value: "icd9:V410.9" } } }
          }
          feature_list {
            key: "Encounter.reason.icd9"
            value { feature { bytes_list { } } feature { bytes_list { value: "V410.9" } } }
          }
          feature_list {
            key: "Encounter.reason.icd9.display.tokenized"
            value { feature { bytes_list { } } feature { bytes_list { value: "standard" value: "issue" } } }
          }
          feature_list {
            key: "encounterId"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } }
          }
          feature_list {
            key: "eventId"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } }
          }
        }
    """, example_pb2.SequenceExample())
    expected_seqex2 = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1420099200 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 4 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1420102800 } } }
        }
        feature_lists: {
          feature_list {
            key: "Encounter.class"
            value {
              feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { value: "actcode:IMP" } }
            }
          }
          feature_list {
            key: "Encounter.meta.lastUpdated"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } } }
          }
          feature_list {
            key: "Encounter.period.start"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } }
            }
          }
          feature_list {
            key: "Encounter.period.end"
            value {
              feature { int64_list { } } feature { int64_list { value: 1417424400 } } feature { int64_list { } } feature { int64_list { value: 1420102800 } }
            }
          }
          feature_list {
            key: "Encounter.reason"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "icd9:V410.9" } } feature { bytes_list { } } feature { bytes_list { value: "icd9:191.4" } }
            }
          }
          feature_list {
            key: "Encounter.reason.icd9"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "V410.9" } } feature { bytes_list { } } feature { bytes_list { value: "191.4" } }
            }
          }
          feature_list {
            key: "Encounter.reason.icd9.display.tokenized"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "standard" value: "issue" } } feature { bytes_list { } } feature { bytes_list { value: "malignant" value: "neoplasm" value: "of" value: "occipital" value: "lobe" } }
            }
          }
          feature_list {
            key: "encounterId"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } }
            }
          }
          feature_list {
            key: "eventId"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } }
            }
          }
        }
    """, example_pb2.SequenceExample())
    # pylint: enable=line-too-long
    _ = self._runTest("Patient/14", bundle, event_trigger_labels_list, (
        ("Patient/14:0-2@1417424400:Encounter/1", expected_seqex1, 2),
        ("Patient/14:0-4@1420102800:Encounter/2", expected_seqex2, 4),
    ))
예제 #9
0
  def testSingleTriggerAndLabel(self):
    event_trigger = text_format.Parse(
        """
      event_time { value_us: 1420102800000000 }
      source { encounter_id { value: "1" } }
    """, google_extensions_pb2.EventTrigger())
    event_label = text_format.Parse(
        """
      patient { patient_id { value: "14" } }
      type { code { value: "test1" }}
      event_time { value_us: 1420102800000000 }
      label {
        class_name {
          system { value: "urn:test:label"
          }
          code { value: "red" }
        }
      }
    """, google_extensions_pb2.EventLabel())
    event_trigger_labels = (
        event_trigger,
        (event_label,),
    )
    event_trigger_labels_list = (event_trigger_labels,)

    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
      } } }
      entry { resource { condition {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        code { coding {
          system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
          code { value: "bar" }
        } }
        asserted_date {
          value_us: 1417392000000000 # "2014-12-01T00:00:00+00:00"
        }
      } } }
      entry { resource { condition {
        id { value: "2" }
        subject { patient_id { value: "14" } }
        code { coding {
          system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
          code { value: "baz" }
        } }
        asserted_date {
          value_us: 1420099200000000 # "2015-01-01T08:00:00+00:00"
        }
      } } }
      entry { resource { composition {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        encounter { encounter_id { value: "1" } }
        section { text { div { value: "test text" } } }
        date {
          value_us: 1420102800000000
          timezone: "UTC"
          precision: SECOND
        }
      } } }
      entry { resource { encounter {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        class_value {
          system { value: "http://hl7.org/fhir/v3/ActCode" }
          code { value: "IMP" }
        }
        reason {
          coding {
            system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
            code { value: "191.4" }
              display { value: "Malignant neoplasm of occipital lobe" }
          }
        }
        period {
          start {
            value_us: 1420099200000000 # "2015-01-01T08:00:00+00:00"
          }
          end {
            value_us: 1420102800000000 # "2015-01-01T09:00:00+00:00"
          }
        }
      } } }
    """, resources_pb2.Bundle())
    # pylint: disable=line-too-long
    expected_seqex = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1420099200 } }
        }
        feature {
          key: "label.test1.class"
          value { bytes_list { value: "red" } }
        }
        feature {
          key: "label.test1.timestamp_secs"
          value { int64_list { value: 1420102800 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 5 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1420102800 } }
        }
      }
      feature_lists: {
        feature_list {
          key: "Composition.meta.lastUpdated"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420102800 } } feature { int64_list { } } }
        }
        feature_list {
          key: "Composition.date"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420102800 } } feature { int64_list { } } }
        }
        feature_list {
          key: "Composition.section.text.div.tokenized"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "test" value: "text" } } feature { bytes_list { } } }
        }
        feature_list {
          key: "Condition.meta.lastUpdated"
          value { feature { int64_list { value: 1417392000 } } feature { int64_list { value: 1420099200 } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } }
        }
        feature_list {
          key: "Condition.code"
          value { feature { bytes_list { value: "icd9:bar" } } feature { bytes_list { value: "icd9:baz" } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } }
        }
        feature_list {
          key: "Condition.code.icd9"
          value { feature { bytes_list { value: "bar" } } feature { bytes_list { value: "baz" } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } }
        }
        feature_list {
          key: "Condition.assertedDate"
          value { feature { int64_list { value: 1417392000 } } feature { int64_list { value: 1420099200 } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } }
        }
        feature_list {
          key: "Encounter.class"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "actcode:IMP" } } feature { bytes_list { } } feature { bytes_list { value: "actcode:IMP" } } }
        }
        feature_list {
          key: "Encounter.meta.lastUpdated"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420099200 } } feature { int64_list { } } feature { int64_list { value: 1420102800 } } }
        }
        feature_list {
          key: "Encounter.period.start"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420099200 } } feature { int64_list { } } feature { int64_list { value: 1420099200 } } }
        }
        feature_list {
          key: "Encounter.period.end"
          value { feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { } } feature { int64_list { value: 1420102800 } } }
        }
        feature_list {
          key: "Encounter.reason"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "icd9:191.4" } } }
        }
        feature_list {
          key: "Encounter.reason.icd9"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "191.4" } } }
        }
        feature_list {
          key: "Encounter.reason.icd9.display.tokenized"
          value { feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { } } feature { bytes_list { value: "malignant" value: "neoplasm" value: "of" value: "occipital" value: "lobe" } } }
        }
        feature_list {
          key: "encounterId"
          value { feature { int64_list { value: 1417392000 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } } }
        }
        feature_list {
          key: "eventId"
          value { feature { int64_list { value: 1417392000 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } } feature { int64_list { value: 1420102800 } } }
        }
      }
    """, example_pb2.SequenceExample())
    # pylint: enable=line-too-long
    _ = self._runTest(
        "Patient/14", bundle, event_trigger_labels_list,
        (("Patient/14:0-5@1420102800:Encounter/1", expected_seqex, 5),))
예제 #10
0
  def testBundleAndLabelsToSeqexDoFn(self):
    event_trigger1 = text_format.Parse(
        """
      event_time { value_us: 1417424400000000 }
      source { encounter_id { value: "1" } }
    """, google_extensions_pb2.EventTrigger())
    event_trigger2 = text_format.Parse(
        """
      event_time { value_us: 1420102800000000 }
      source { encounter_id { value: "2" } }
    """, google_extensions_pb2.EventTrigger())
    event_trigger_labels1 = (
        event_trigger1,
        list(),
    )
    event_trigger_labels2 = (
        event_trigger2,
        list(),
    )
    event_trigger_labels_list = [
        event_trigger_labels1,
        event_trigger_labels2,
    ]

    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
      } } }
      entry {
        resource { encounter {
          id { value: "1" }
          subject { patient_id { value: "14" } }
          class_value {
            system { value: "http://hl7.org/fhir/v3/ActCode" }
            code { value: "IMP" }
          }
          reason {
            coding {
              system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
              code { value: "V410.9" }
              display { value: "Standard issue" }
            }
          }
          period {
            start {
              value_us: 1417420800000000 # "2014-12-01T08:00:00+00:00"
            }
            end {
              value_us: 1417424400000000 # "2014-12-01T09:00:00+00:00"
            }
          }
        } }
      }
      entry {
        resource { encounter {
          id { value: "2" }
          subject { patient_id { value: "14" } }
          class_value {
            system { value: "http://hl7.org/fhir/v3/ActCode" }
            code { value: "IMP" }
          }
          reason {
            coding {
              system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
              code { value: "191.4" }
              display { value: "Malignant neoplasm of occipital lobe" }
            }
          }
          period {
            start {
              value_us: 1420099200000000 # "2015-01-01T08:00:00+00:00"
            }
            end {
              value_us: 1420102800000000 # "2015-01-01T09:00:00+00:00"
            }
          }
        } }
      }
    """, resources_pb2.Bundle())
    # pylint: disable=line-too-long
    expected_seqex1 = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1417420800 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 2 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1417424400 } } }
        }
        feature_lists: {
          feature_list {
            key: "Encounter.class"
            value { feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } }
          }
          feature_list {
            key: "Encounter.meta.lastUpdated"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } }
          }
          feature_list {
            key: "Encounter.period.start"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } }
          }
          feature_list {
            key: "Encounter.period.end"
            value { feature { int64_list { } } feature { int64_list { value: 1417424400 } } }
          }
          feature_list {
            key: "Encounter.reason.http-hl7-org-fhir-sid-icd-9-cm-diagnosis"
            value { feature { bytes_list { } } feature { bytes_list { value: "V410.9" } } }
          }
          feature_list {
            key: "Encounter.reason.http-hl7-org-fhir-sid-icd-9-cm-diagnosis.display.tokenized"
            value { feature { bytes_list { } } feature { bytes_list { value: "standard" value: "issue" } } }
          }
          feature_list {
            key: "encounterId"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } }
          }
          feature_list {
            key: "eventId"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } }
          }
        }
    """, example_pb2.SequenceExample())
    expected_seqex2 = text_format.Parse(
        """
      context: {
        feature {
          key: "currentEncounterId"
          value { int64_list { value: 1420099200 } }
        }
        feature {
          key: "patientId"
          value { bytes_list { value: "14" } }
        }
        feature {
          key: "sequenceLength"
          value { int64_list { value: 4 } }
        }
        feature {
          key: "timestamp"
          value { int64_list { value: 1420102800 } } }
        }
        feature_lists: {
          feature_list {
            key: "Encounter.class"
            value {
              feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } } feature { bytes_list { value: "http-hl7-org-fhir-v3-ActCode:IMP" } }
            }
          }
          feature_list {
            key: "Encounter.meta.lastUpdated"
            value { feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } } }
          }
          feature_list {
            key: "Encounter.period.start"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } }
            }
          }
          feature_list {
            key: "Encounter.period.end"
            value {
              feature { int64_list { } } feature { int64_list { value: 1417424400 } } feature { int64_list { } } feature { int64_list { value: 1420102800 } }
            }
          }
          feature_list {
            key: "Encounter.reason.http-hl7-org-fhir-sid-icd-9-cm-diagnosis"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "V410.9" } } feature { bytes_list { } } feature { bytes_list { value: "191.4" } }
            }
          }
          feature_list {
            key: "Encounter.reason.http-hl7-org-fhir-sid-icd-9-cm-diagnosis.display.tokenized"
            value {
              feature { bytes_list { } } feature { bytes_list { value: "standard" value: "issue" } } feature { bytes_list { } } feature { bytes_list { value: "malignant" value: "neoplasm" value: "of" value: "occipital" value: "lobe" } }
            }
          }
          feature_list {
            key: "encounterId"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420099200 } }
            }
          }
          feature_list {
            key: "eventId"
            value {
              feature { int64_list { value: 1417420800 } } feature { int64_list { value: 1417424400 } } feature { int64_list { value: 1420099200 } } feature { int64_list { value: 1420102800 } }
            }
          }
        }
    """, example_pb2.SequenceExample())
    with test_pipeline.TestPipeline() as p:
      result = (
          p
          | beam.Create([(b"Patient/14", (bundle, event_trigger_labels_list))])
          | "BundleAndLabelsToSeqex" >> beam.ParDo(
              bundle_to_seqex.BundleAndLabelsToSeqexDoFn(
                  version_config=self._version_config,
                  enable_attribution=False,
                  generate_sequence_label=False)))

      def check_result(got):
        try:
          self.assertLen(got, 2, "got: %s" % got)
          got_seqex1 = got[0]
          got_seqex2 = got[1]
          self.assertProtoEqual(expected_seqex1, got_seqex1)
          self.assertProtoEqual(expected_seqex2, got_seqex2)
        except AssertionError as err:
          raise util.BeamAssertException(err)

      util.assert_that(result, check_result)
예제 #11
0
  def testCreateBundleAndLabels(self):
    bundle1 = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "14" }
      } } }
      entry { resource { condition {
        id { value: "1" }
        subject { patient_id { value: "14" } }
        code {
          coding {
            system { value: "http://hl7.org/fhir/sid/icd-9-cm/diagnosis" }
            code { value: "bar" }
          }
        }
        asserted_date {
          value_us: 1417392000000000 # "2014-12-01T00:00:00+00:00"
        }
      } } }""", resources_pb2.Bundle())
    bundle1_event_trigger = text_format.Parse(
        """
      event_time { value_us: 1388566800000000 }  # "2014-01-01T09:00:00+00:00"
    """, google_extensions_pb2.EventTrigger())

    # For the purpose of testing, bundle2 does not exist.
    bundle2_event_trigger = text_format.Parse(
        """
      event_time { value_us: 1388566800000000 }  # "2014-01-01T09:00:00+00:00"
    """, google_extensions_pb2.EventTrigger())

    bundle3 = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "30" }
      } } }""", resources_pb2.Bundle())
    bundle1_event_trigger_labels_list = [
        (
            bundle1_event_trigger,
            list(),
        ),
    ]
    bundle2_event_trigger_labels_list = [
        (
            bundle2_event_trigger,
            list(),
        ),
    ]
    with test_pipeline.TestPipeline() as p:
      bundle_pcoll = p | "CreateBundles" >> beam.Create([
          (b"Patient/14", bundle1),
          (b"Patient/30", bundle3),
      ])
      trigger_list_pcoll = p | "CreateTriggerLists" >> beam.Create([
          (b"Patient/14", bundle1_event_trigger_labels_list),
          (b"Patient/20", bundle2_event_trigger_labels_list),
      ])
      result = bundle_to_seqex.CreateBundleAndLabels(bundle_pcoll,
                                                     trigger_list_pcoll)

      def check_result(got):
        try:
          self.assertLen(got, 1)
          (got_key, got_bundle_and_labels) = got[0]
          self.assertEqual(b"Patient/14", got_key)
          (got_bundle, got_trigger_labels_list) = got_bundle_and_labels
          self.assertProtoEqual(got_bundle, bundle1)
          self.assertLen(got_trigger_labels_list, 1)
          self.assertProtoEqual(got_trigger_labels_list[0][0],
                                bundle1_event_trigger)
          self.assertFalse(len(got_trigger_labels_list[0][1]))

        except AssertionError as err:
          raise util.BeamAssertException(err)

      util.assert_that(result, check_result)
예제 #12
0
  def test_get_trigger_labels_pair(self):
    # pylint: disable=line-too-long
    bundle = text_format.Parse(
        """
      entry { resource { patient {
        id { value: "20" }
      } } }
      entry { resource { encounter {
        id { value: "1" }
        extension {
          url { value: "https://g.co/fhir/StructureDefinition/eventTrigger" }
          extension {
            url { value: "type" }
            value { coding {
              system { value: "urn:test:trigger"}
              code { value: "at_discharge" }
            } }
          }
          extension {
            url { value: "eventTime" }
            value { date_time {
              value_us: 1388566800000000  # "2014-01-01T09:00:00+00:00"
            } }
          }
        }
        extension {
          url { value: "https://g.co/fhir/StructureDefinition/eventLabel" }
          extension {
            url { value: "type" }
            value { coding {
              system { value: "urn:test:label" }
              code { value: "test1" }
            } }
          }
          extension {
            url { value: "eventTime" }
            value { date_time { value_us: 1388566800000000 } }
          }
          extension {
            url { value: "source" }
            value { reference { encounter_id { value: "1" } } }
          }
        }
      } } }
      entry { resource { encounter {
        id { value: "2" }
        extension {
          url { value: "https://g.co/fhir/StructureDefinition/eventTrigger" }
          extension {
            url { value: "type" }
            value { coding {
              system { value: "urn:test:trigger"}
              code { value: "at_discharge" }
            } }
          }
          extension {
            url { value: "eventTime" }
            value { date_time {
              value_us: 1420102800000000  # "2015-01-01T09:00:00+00:00"
            } }
          }
        }
        extension {
          url { value: "https://g.co/fhir/StructureDefinition/eventLabel" }
          extension {
            url { value: "type" }
            value { coding {
              system { value: "urn:test:label" }
              code { value: "test1" }
            } }
          }
          extension {
            url { value: "source" }
            value { reference { encounter_id { value: "2" } } }
          }
          extension {
            url { value: "label" }
            extension {
              url { value: "className" }
              value { coding {
                system { value: "urn:test:label:test1" }
                code { value: "red" }
              } }
            }
          }
        }
      } } }
    """, resources_pb2.Bundle())
    trigger1 = text_format.Parse(
        """
      type {
        system { value: "urn:test:trigger" }
        code { value: "at_discharge" }
      }
      event_time { value_us: 1388566800000000 }  # "2014-01-01T09:00:00+00:00"
    """, google_extensions_pb2.EventTrigger())
    trigger2 = text_format.Parse(
        """
      type {
        system { value: "urn:test:trigger" }
        code { value: "at_discharge" }
      }
      event_time { value_us: 1420102800000000 }  # "2015-01-01T09:00:00+00:00"
    """, google_extensions_pb2.EventTrigger())
    label1 = text_format.Parse(
        """
      type {
        system { value: "urn:test:label" }
        code { value: "test1" }
      }
      event_time { value_us: 1388566800000000 }
      source { encounter_id { value: "1" } }
    """, google_extensions_pb2.EventLabel())
    label2 = text_format.Parse(
        """
      type {
        system { value: "urn:test:label" }
        code { value: "test1" }
      }
      source { encounter_id { value: "2" } }
      label {
        class_name {
          system { value: "urn:test:label:test1" }
          code { value: "red" }
        }
      }
    """, google_extensions_pb2.EventLabel())
    # pylint: enable=line-too-long

    (filtered_count, got_list) = bundle_to_seqex_util.get_trigger_labels_pair(
        bundle, [b"test1"], b"at_discharge")
    self.assertEqual(0, filtered_count)
    self.assertLen(got_list, 2)
    (got_trigger_1, got_label_list1) = got_list[0]
    (got_trigger_2, got_label_list2) = got_list[1]
    self.assertProtoEqual(got_trigger_1, trigger1)
    self.assertLen(got_label_list1, 1)
    self.assertProtoEqual(got_label_list1[0], label1)
    self.assertProtoEqual(got_trigger_2, trigger2)
    self.assertLen(got_label_list2, 1)
    self.assertProtoEqual(got_label_list2[0], label2)