def testLengthOfStayRangeAt24Hours(self, end_us, label_val): enc = resources_pb2.Encounter() enc.CopyFrom(self._enc) enc.period.end.value_us = end_us labels = [l for l in label.LengthOfStayRangeAt24Hours( self._patient, enc)] expected_label = label.ComposeLabel( self._patient, self._enc, label.LOS_RANGE_LABEL, label_val, # 24 hours after admission datetime.datetime(2009, 2, 14, 23, 31, 30)) self.assertEqual([expected_label], labels)
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))
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))
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]))
def testComposeLabel(self): output_label = label.ComposeLabel(self._patient, self._enc, 'label.test', 'true', datetime(2003, 1, 2, 4, 5, 6)) self.assertEqual(self._expected_label, output_label)