Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_msh(values):
encoding_chars = {'SEGMENT': '\r',
'FIELD': values[0],
'COMPONENT': values[1][0],
'SUBCOMPONENT': values[1][1],
'REPETITION': values[1][2],
'ESCAPE': values[1][3]}
msh = parse_segment('MSH{0}{1}'.format(encoding_chars['FIELD'], encoding_chars['FIELD'].join(values[1:])),
encoding_chars=encoding_chars)
return msh
def test_wrong_segment(self):
"""
Tests that if there is an unexpected segment the message in not validated
The message used has an unexpected SPM
"""
msg = self._create_message(self.rsp_k21)
spm = parse_segment('SPM|1|100187400201^||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r')
msg.add(spm)
self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
self._test_report_file('ERROR')
def test_having_more_segments(self):
"""
Tests that when a segment occurs more than the allowed times the message is not validated
The message used has 2 occurrence of the segment evn
"""
msg = self._create_message(self.adt_a01)
evn = parse_segment('EVN||20080115153000||AAA|AAA|20080114003000', version='2.6')
msg.add(evn)
self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
self._test_report_file('ERROR')
def test_parse_segment_ending_with_varies_field(self):
segment = 'QPD|IHE PDQ Query|622e3df468654c2fb3e0ac35bfe3369e|xxxx|yyyyy||||zzzzz'
s = parse_segment(segment)
self.assertEqual(s.qpd_1.datatype, 'CE')
self.assertEqual(s.qpd_2.datatype, 'ST')
self.assertEqual(s.qpd_3.datatype, 'varies')
self.assertEqual(s.qpd_4.datatype, 'varies')
self.assertEqual(s.qpd_8.datatype, 'varies')
def test_wd_type_field(self):
"""
Tests that, in strict mode, a wd field is not present
"""
# The EV1 message is of type WD
s = 'EVN|EV1|20080115153000||AAA|AAA|20080114003000'
parsed_s = parse_segment(s, version='2.7')
self.assertRaises(ValidationError, parsed_s.validate)
def test_to_string_segment_with_unknown_fields(self):
f1 = Field()
f1.value = 'abc'
f2 = Field()
f2.value = 'cba'
pid_er7 = 'PID|1||566-554-3423^^^GHH^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE^^SOMEWHERE^^^USA||555~444|||M|||||||||||||||||||||||'
pid = parse_segment(pid_er7)
pid.add(f1)
self.assertEqual(pid.to_er7(trailing_children=True), pid_er7 + '|abc')
pid.add(f2)
self.assertEqual(pid.to_er7(trailing_children=True), pid_er7 + '|abc|cba')
def test_parse_segment_containing_varies_field(self):
segment = 'OBX|1|ST|1^YYY||ABCDEFG|HJKLMN|||||O'
s = parse_segment(segment)
self.assertEqual(s.obx_5.datatype, 'varies')
self.assertNotEqual(s.obx_6.datatype, 'varies')
def test_parse_segment_invalid_encoding_chars(self):
segment = 'EVN@@20080115153000@@@@20080114003000\r'
self.assertRaises(InvalidEncodingChars, parse_segment, segment,
encoding_chars=self._get_invalid_encoding_chars())
self.assertRaises(InvalidEncodingChars, parse_segment, segment,
encoding_chars=self._get_invalid_encoding_chars(),
validation_level=VALIDATION_LEVEL.STRICT)
def test_parse_segment(self):
segment = 'PV1|1|I|PATIENT WARD|U||||^REFERRING^DOCTOR|^CONSULTING^DOCTOR|CAR||||2|A0|||||||||||||||||||||||||||||2008'
pv1 = parse_segment(segment)
self.assertEqual(pv1.name, 'PV1')
self.assertEqual(pv1.pv1_2.to_er7(), 'I')