From 8a7fbf8f3b093b0fa11b1557433ccc6aeaad092b Mon Sep 17 00:00:00 2001 From: Vittorio Meloni Date: Wed, 13 Mar 2024 11:55:53 +0100 Subject: [PATCH] feat: removes escape warngings for python 3.12 and fix SIU messaegs structure for hl7 2.4 --- hl7apy/exceptions.py | 2 +- hl7apy/parser.py | 2 +- hl7apy/v2_4/messages.py | 13 ------------- tests/test_core.py | 20 ++++++++++---------- tests/test_mllp.py | 4 ++-- tests/test_parser.py | 6 +++--- tests/test_to_string.py | 2 +- tests/test_validation.py | 6 +++--- 8 files changed, 21 insertions(+), 34 deletions(-) diff --git a/hl7apy/exceptions.py b/hl7apy/exceptions.py index 58b0da3..38280d7 100644 --- a/hl7apy/exceptions.py +++ b/hl7apy/exceptions.py @@ -47,7 +47,7 @@ class ValidationError(HL7apyException): >>> from hl7apy.parser import parse_message >>> from hl7apy.validation import VALIDATION_LEVEL - >>> msh = 'MSH|^~\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20080115153000||ADT^A01^ADT_A01|' \ + >>> msh = 'MSH|^~\\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20080115153000||ADT^A01^ADT_A01|' \ '0123456789|P|2.5||||AL\\r' >>> evn = 'EVN||20080115153000||AAA|AAA|20080114003000\\r' >>> pid = 'PID|1||123-456-789^^^HOSPITAL^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE STREET^^SOMEWHERE^^^USA||' \ diff --git a/hl7apy/parser.py b/hl7apy/parser.py index 07acdd7..f552adf 100644 --- a/hl7apy/parser.py +++ b/hl7apy/parser.py @@ -58,7 +58,7 @@ def parse_message(message, validation_level=None, find_groups=True, message_prof :return: an instance of :class:`Message ` - >>> message = "MSH|^~\&|GHH_ADT||||20080115153000||OML^O33^OML_O33|0123456789|P|2.5||||AL\\rPID|1||" \ + >>> message = "MSH|^~\\&|GHH_ADT||||20080115153000||OML^O33^OML_O33|0123456789|P|2.5||||AL\\rPID|1||" \ "566-554-3423^^^GHH^MR||EVERYMAN^ADAM^A|||M|||2222 HOME STREET^^ANN ARBOR^MI^^USA||555-555-2004|||M\\r" >>> m = parse_message(message) >>> print(m) diff --git a/hl7apy/v2_4/messages.py b/hl7apy/v2_4/messages.py index d74a55c..4d65b41 100644 --- a/hl7apy/v2_4/messages.py +++ b/hl7apy/v2_4/messages.py @@ -1163,91 +1163,78 @@ 'SIU_S13': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S13_PATIENT', GROUPS['SIU_S13_PATIENT'], (0, -1), 'GRP'), ('SIU_S13_RESOURCES', GROUPS['SIU_S13_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S14': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S14_PATIENT', GROUPS['SIU_S14_PATIENT'], (0, -1), 'GRP'), ('SIU_S14_RESOURCES', GROUPS['SIU_S14_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S15': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S15_PATIENT', GROUPS['SIU_S15_PATIENT'], (0, -1), 'GRP'), ('SIU_S15_RESOURCES', GROUPS['SIU_S15_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S16': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S16_PATIENT', GROUPS['SIU_S16_PATIENT'], (0, -1), 'GRP'), ('SIU_S16_RESOURCES', GROUPS['SIU_S16_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S17': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S17_PATIENT', GROUPS['SIU_S17_PATIENT'], (0, -1), 'GRP'), ('SIU_S17_RESOURCES', GROUPS['SIU_S17_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S18': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S18_PATIENT', GROUPS['SIU_S18_PATIENT'], (0, -1), 'GRP'), ('SIU_S18_RESOURCES', GROUPS['SIU_S18_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S19': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S19_PATIENT', GROUPS['SIU_S19_PATIENT'], (0, -1), 'GRP'), ('SIU_S19_RESOURCES', GROUPS['SIU_S19_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S20': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S20_PATIENT', GROUPS['SIU_S20_PATIENT'], (0, -1), 'GRP'), ('SIU_S20_RESOURCES', GROUPS['SIU_S20_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S21': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S21_PATIENT', GROUPS['SIU_S21_PATIENT'], (0, -1), 'GRP'), ('SIU_S21_RESOURCES', GROUPS['SIU_S21_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S22': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S22_PATIENT', GROUPS['SIU_S22_PATIENT'], (0, -1), 'GRP'), ('SIU_S22_RESOURCES', GROUPS['SIU_S22_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S23': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S23_PATIENT', GROUPS['SIU_S23_PATIENT'], (0, -1), 'GRP'), ('SIU_S23_RESOURCES', GROUPS['SIU_S23_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S24': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S24_PATIENT', GROUPS['SIU_S24_PATIENT'], (0, -1), 'GRP'), ('SIU_S24_RESOURCES', GROUPS['SIU_S24_RESOURCES'], (1, -1), 'GRP'),)), 'SIU_S26': ('sequence', (('MSH', SEGMENTS['MSH'], (1, 1), 'SEG'), ('SCH', SEGMENTS['SCH'], (1, 1), 'SEG'), - ('TQ1', SEGMENTS['TQ1'], (0, -1), 'SEG'), ('NTE', SEGMENTS['NTE'], (0, -1), 'SEG'), ('SIU_S26_PATIENT', GROUPS['SIU_S26_PATIENT'], (0, -1), 'GRP'), ('SIU_S26_RESOURCES', GROUPS['SIU_S26_RESOURCES'], (1, -1), 'GRP'),)), diff --git a/tests/test_core.py b/tests/test_core.py index f450dd8..469e2eb 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -44,7 +44,7 @@ def _get_invalid_encoding_chars(): def _get_test_msg(): - return 'MSH|^~\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33^OML_O33|978226056138290600|D|2.5|||||USA||EN\r' \ + return 'MSH|^~\\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33^OML_O33|978226056138290600|D|2.5|||||USA||EN\r' \ 'PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009^^~^^^^^^L^^^|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100|||||||||||\r' \ 'PV1||O|||||||||||||||||1107080001^^^LIS\r' \ 'SPM|1|100187400201^||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \ @@ -87,7 +87,7 @@ def _get_fail_test_msg(): def _get_rsp_k21_mp_msg(): - return 'MSH|^~\&|SENDING APP|SENDING FAC|RECEIVING APP|RECEIVING FAC|20140410170011||RSP^K22^RSP_K21|11111111|P|2.5\r' \ + return 'MSH|^~\\&|SENDING APP|SENDING FAC|RECEIVING APP|RECEIVING FAC|20140410170011||RSP^K22^RSP_K21|11111111|P|2.5\r' \ 'MSA|AA|20140410170015\r' \ 'QAK|222222222|OK\r' \ 'QPD|IHE PDQ Query|222222222|@PID.3.1.1^3333333|||||^^^IHEFACILITY&1.3.6.1.4.1.21367.3000.1.6&ISO|\r' \ @@ -1269,7 +1269,7 @@ def test_assign_value_traversal_message_profile(self): def test_assign_value_with_encoding_chars(self): # using field separator field_str = 'xxx|yyy' - escaped_str = 'xxx\F\yyy' + escaped_str = 'xxx\\F\\yyy' f = Field('PID_3') f.value = field_str self.assertEqual(f.to_er7(), escaped_str) @@ -1280,21 +1280,21 @@ def test_assign_value_with_encoding_chars(self): f = Field() f.value = field_str - self.assertEqual(f.to_er7(), 'xxx\F\yyy') + self.assertEqual(f.to_er7(), 'xxx\\F\\yyy') # using repetition field_str = 'xxx~yyy' f = Field() f.value = field_str - self.assertEqual(f.to_er7(), 'xxx\R\yyy') + self.assertEqual(f.to_er7(), 'xxx\\R\\yyy') f = Field('PID_2') f.value = field_str - self.assertEqual(f.to_er7(), 'xxx\R\yyy') + self.assertEqual(f.to_er7(), 'xxx\\R\\yyy') f = Field('PID_2', validation_level=VALIDATION_LEVEL.STRICT) f.value = field_str - self.assertEqual(f.to_er7(), 'xxx\R\yyy') + self.assertEqual(f.to_er7(), 'xxx\\R\\yyy') def test_field_wgith_three_part_name_bug_39(self): """ @@ -1903,15 +1903,15 @@ def test_assign_value_with_encoding_chars(self): cmp_str = 'xxx^yyy' c = Component() c.value = cmp_str - self.assertEqual(c.to_er7(), 'xxx\S\yyy') + self.assertEqual(c.to_er7(), 'xxx\\S\\yyy') c = Component('CWE_1') c.value = cmp_str - self.assertEqual(c.to_er7(), 'xxx\S\yyy') + self.assertEqual(c.to_er7(), 'xxx\\S\\yyy') c = Component('CWE_1', validation_level=VALIDATION_LEVEL.STRICT) c.value = cmp_str - self.assertEqual(c.to_er7(), 'xxx\S\yyy') + self.assertEqual(c.to_er7(), 'xxx\\S\\yyy') def test_bug_13(self): c = Component('CX_10') diff --git a/tests/test_mllp.py b/tests/test_mllp.py index 38a92a3..0d6473d 100644 --- a/tests/test_mllp.py +++ b/tests/test_mllp.py @@ -34,7 +34,7 @@ UNSUPPORTED_MESSAGE = 'INVALID MESSAGE' PDQ_REQ_TPL = \ - 'MSH|^~\&|REC APP|REC FAC|SENDING APP|SENTING FAC|20110708163513||{}|1|D|2.5|||||ITA||EN\r' \ + 'MSH|^~\\&|REC APP|REC FAC|SENDING APP|SENTING FAC|20110708163513||{}|1|D|2.5|||||ITA||EN\r' \ 'QPD|IHE PDQ Query|111069|@PID.3.1^1||||\r' \ 'RCP|I|' @@ -43,7 +43,7 @@ PDQV_REQ = PDQ_REQ_TPL.format('QBP^ZV1^QBP_Q21') PDQ_RES_TPL = \ - 'MSH|^~\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708163514||{}|2|D|2.5|||||ITA||EN\r' \ + 'MSH|^~\\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708163514||{}|2|D|2.5|||||ITA||EN\r' \ 'MSA|AA|26775702551812240|\r' \ 'QAK|1|OK||1|1|0\r' \ 'QPD|IHE PDQ Query|111069|@PID.3.1^1010110909194822~@PID.5.1^SMITH||||\r' \ diff --git a/tests/test_parser.py b/tests/test_parser.py index 5712886..82835ac 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -184,15 +184,15 @@ def test_parse_message_missing_encoding_chars_zero(self): m = 'MSH|||||||||||||||||||' self.assertRaises(InvalidEncodingChars, parse_message, m) self.assertRaises(InvalidEncodingChars, parse_message, m, validation_level=VALIDATION_LEVEL.STRICT) - m = 'MSH|^~\||||||||||2.7' + m = 'MSH|^~\\||||||||||2.7' self.assertRaises(InvalidEncodingChars, parse_message, m) self.assertRaises(InvalidEncodingChars, parse_message, m, validation_level=VALIDATION_LEVEL.STRICT) def test_parse_message_missing_encoding_chars(self): - m = 'MSH|@%\|||||||||' + m = 'MSH|@%\\|||||||||' self.assertRaises(InvalidEncodingChars, parse_message, m) self.assertRaises(InvalidEncodingChars, parse_message, m, validation_level=VALIDATION_LEVEL.STRICT) - m = 'MSH|^~\||||||||||2.7' + m = 'MSH|^~\\||||||||||2.7' self.assertRaises(InvalidEncodingChars, parse_message, m) self.assertRaises(InvalidEncodingChars, parse_message, m, validation_level=VALIDATION_LEVEL.STRICT) diff --git a/tests/test_to_string.py b/tests/test_to_string.py index 9ad23a2..6c1d2fd 100644 --- a/tests/test_to_string.py +++ b/tests/test_to_string.py @@ -41,7 +41,7 @@ def setUp(self): 'SUBCOMPONENT': '@', 'REPETITION': 'r', 'ESCAPE': '?'} - self.msh_values_standard = ['|', '^~\&', 'LIP', 'LIP', 'LB', 'LB', '20111207121030', '', 'RSP^SLI^RSP_K11', + self.msh_values_standard = ['|', '^~\\&', 'LIP', 'LIP', 'LB', 'LB', '20111207121030', '', 'RSP^SLI^RSP_K11', '430102', 'D', '2.5', '', '', '', '', 'IT', '', 'EN', '', ''] self.msh_standard = 'MSH|^~\\&|LIP|LIP|LB|LB|20111207121030||RSP^SLI^RSP_K11|430102|D|2.5|||||IT||EN' self.msh_values_custom = ['!', '$r?@', 'LIP', 'LIP', 'LB', 'LB', '20111207121030', '', 'RSP^SLI^RSP_K11', diff --git a/tests/test_validation.py b/tests/test_validation.py index e6e1a95..faa2a14 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -55,7 +55,7 @@ def setUp(self): 'IN1|1|INSURANCE PLAN ID^PLAN DESC|COMPANY ID|INSURANCE COMPANY, INC.|5555 INSURERS STREET^^SOMEWHERE^^^USA||||||||||||||||||||||||||||||||||||||||||||555-44-3333\r' self.oml_o33 = \ - 'MSH|^~\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33^OML_O33|978226056138290600|D|2.5|||||USA||EN\r' \ + 'MSH|^~\\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33^OML_O33|978226056138290600|D|2.5|||||USA||EN\r' \ 'PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009^^~^^^^^^L^^^|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100|||||||||||\r' \ 'PV1||O|||||||||||||||||1107080001^^^LIS\r' \ 'SPM|1|100187400201^||BLDV|||||||B||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \ @@ -64,7 +64,7 @@ def setUp(self): 'OBR||83428|83428|TPO^ANTI THYROPEROXIDASE ANTIBODIES(TPO)^^TPO||||||||||||ND^UNKNOWN^UNKNOWN\r' self.oml_o33_2 = \ - 'MSH|^~\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33^OML_O33|978226056138290600|D|2.5|||||USA||EN\r' \ + 'MSH|^~\\&|SENDING APP|SENDING FAC|REC APP|REC FAC|20110708162817||OML^O33^OML_O33|978226056138290600|D|2.5|||||USA||EN\r' \ 'PID|||1010110909194822^^^GATEWAY_IL&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK||PIPPO^PLUTO^^^^^L||19790515|M|||VIA DI TOPOLINO^CAGLIARI^CAGLIARI^^09100^100^H^^092009^^~^^^^^^L^^^|||||||PPPPPP79E15B354I^^^CF|||||CAGLIARI|||100|||||||||||\r' \ 'PV1||O|||||||||||||||||1107080001^^^LIS\r' \ 'SPM|1|100187400201^||BLDV|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r' \ @@ -393,7 +393,7 @@ class TestMessageProfile(unittest.TestCase): def setUp(self): self.rsp_k21 = \ - 'MSH|^~\&|SENDING APP|SENDING FAC|RECEIVING APP|RECEIVING FAC|20140410170011||RSP^K22^RSP_K21|11111111|P|2.5\r' \ + 'MSH|^~\\&|SENDING APP|SENDING FAC|RECEIVING APP|RECEIVING FAC|20140410170011||RSP^K22^RSP_K21|11111111|P|2.5\r' \ 'MSA|AA|20140410170015\r' \ 'QAK|222222222|OK\r' \ 'QPD|IHE PDQ Query|222222222|@PID.3.1.1^3333333|||||^^^IHEFACILITY&1.3.6.1.4.1.21367.3000.1.6&ISO^|\r' \