def test_parse_batch3(self): batch = hl7.parse_batch(sample_batch3) self.assertEqual(len(batch), 1) self.assertIsInstance(batch[0], hl7.Message) self.assertIsInstance(batch.header, hl7.Segment) self.assertEqual(batch.header[0][0], "BHS") self.assertEqual(batch.header[4][0], "ABCHS") self.assertIsInstance(batch.trailer, hl7.Segment) self.assertEqual(batch.trailer[0][0], "BTS")
def test_parse_batch2(self): batch = hl7.parse_batch(sample_batch2) self.assertEqual(len(batch), 2) self.assertIsInstance(batch[0], hl7.Message) self.assertEqual(batch[0][0][10][0], "12334456778890") self.assertIsInstance(batch[1], hl7.Message) self.assertEqual(batch[1][0][10][0], "12334456778891") self.assertFalse(batch.header) self.assertFalse(batch.trailer)
def send_message(server, port): client = MLLPClient(server, port) f = open('test.dat', 'r') ff = f.read() messages = hl7.parse_batch(ff) for message in messages: client.send_message(str(message))
def test_parse_batch1(self): batch = hl7.parse_batch(sample_batch1) self.assertEqual(len(batch), 2) self.assertIsInstance(batch[0], hl7.Message) self.assertEqual(batch[0][0][10][0], "12334456778890") self.assertIsInstance(batch[1], hl7.Message) self.assertEqual(batch[1][0][10][0], "12334456778891") self.assertIsInstance(batch.header, hl7.Segment) self.assertEqual(batch.header[0][0], "BHS") self.assertEqual(batch.header[4][0], "ABCHS") self.assertIsInstance(batch.trailer, hl7.Segment) self.assertEqual(batch.trailer[0][0], "BTS") self.assertEqual(batch.trailer[1][0], "2")
def test_parse_batch4(self): batch = hl7.parse_batch(sample_batch4) self.assertEqual(len(batch), 1) self.assertIsInstance(batch[0], hl7.Message) self.assertIsNone(batch.header) self.assertIsNone(batch.trailer)
def test_parse_bad_batch1(self): with self.assertRaises(ParseException) as cm: hl7.parse_batch(sample_bad_batch1) self.assertIn( "Batch cannot have more than one BHS segment", cm.exception.args[0] )
def test_parse_bad_batch(self): with self.assertRaises(ParseException) as cm: hl7.parse_batch(sample_bad_batch) self.assertIn("Segment received before message header", cm.exception.args[0])