def test_extract(self): msg = hl7.parse(rep_sample_hl7) # Full correct path self.assertEqual(msg["PID.3.1.2.2"], "Sub-Component2") self.assertEqual(msg[Accessor("PID", 1, 3, 1, 2, 2)], "Sub-Component2") # Shorter Paths self.assertEqual(msg["PID.1.1"], "Field1") self.assertEqual(msg[Accessor("PID", 1, 1, 1)], "Field1") self.assertEqual(msg["PID.1"], "Field1") self.assertEqual(msg["PID1.1"], "Field1") self.assertEqual(msg["PID.3.1.2"], "Sub-Component1") # Longer Paths self.assertEqual(msg["PID.1.1.1.1"], "Field1") # Incorrect path self.assertRaisesRegex( IndexError, "PID.1.1.1.2", msg.extract_field, *Accessor.parse_key("PID.1.1.1.2") ) # Optional field, not included in message self.assertEqual(msg["MSH.20"], "") # Optional sub-component, not included in message self.assertEqual(msg["PID.3.1.2.3"], "") self.assertEqual(msg["PID.3.1.3"], "Component3") self.assertEqual(msg["PID.3.1.4"], "")
def test_extract(self): msg = hl7.parse(rep_sample_hl7) # Full correct path self.assertEqual(msg['PID.3.1.2.2'], 'Sub-Component2') self.assertEqual(msg[Accessor('PID', 1, 3, 1, 2, 2)], 'Sub-Component2') # Shorter Paths self.assertEqual(msg['PID.1.1'], 'Field1') self.assertEqual(msg[Accessor('PID', 1, 1, 1)], 'Field1') self.assertEqual(msg['PID.1'], 'Field1') self.assertEqual(msg['PID1.1'], 'Field1') self.assertEqual(msg['PID.3.1.2'], 'Sub-Component1') # Longer Paths self.assertEqual(msg['PID.1.1.1.1'], 'Field1') # Incorrect path self.assertRaisesRegexp(IndexError, 'PID.1.1.1.2', msg.extract_field, *Accessor.parse_key('PID.1.1.1.2')) # Optional field, not included in message self.assertEqual(msg['MSH.20'], '') # Optional sub-component, not included in message self.assertEqual(msg['PID.3.1.2.3'], '') self.assertEqual(msg['PID.3.1.3'], 'Component3') self.assertEqual(msg['PID.3.1.4'], '')
def test_parse(self): self.assertEqual(Accessor("FOO"), Accessor.parse_key("FOO")) self.assertEqual(Accessor("FOO", 2, 3, 1, 4, 6), Accessor.parse_key("FOO2.3.1.4.6"))
def test_key(self): self.assertEqual("FOO", Accessor("FOO").key) self.assertEqual("FOO2", Accessor("FOO", 2).key) self.assertEqual("FOO2.3", Accessor("FOO", 2, 3).key) self.assertEqual("FOO2.3.1.4.6", Accessor("FOO", 2, 3, 1, 4, 6).key)
def test_equality(self): self.assertEqual(Accessor("FOO", 1, 3, 4), Accessor("FOO", 1, 3, 4)) self.assertNotEqual(Accessor("FOO", 1), Accessor("FOO", 2))