Skip to content

Commit

Permalink
feat: removes escape warngings for python 3.12 and fix SIU messaegs s…
Browse files Browse the repository at this point in the history
…tructure for hl7 2.4
  • Loading branch information
svituz committed Mar 13, 2024
1 parent 9a50787 commit 8a7fbf8
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 34 deletions.
2 changes: 1 addition & 1 deletion hl7apy/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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||' \
Expand Down
2 changes: 1 addition & 1 deletion hl7apy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def parse_message(message, validation_level=None, find_groups=True, message_prof
:return: an instance of :class:`Message <hl7apy.core.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)
Expand Down
13 changes: 0 additions & 13 deletions hl7apy/v2_4/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),)),
Expand Down
20 changes: 10 additions & 10 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand Down Expand Up @@ -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' \
Expand Down Expand Up @@ -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)
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mllp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|'

Expand All @@ -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^[email protected]^SMITH||||\r' \
Expand Down
6 changes: 3 additions & 3 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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' \
Expand All @@ -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' \
Expand Down Expand Up @@ -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' \
Expand Down

0 comments on commit 8a7fbf8

Please sign in to comment.