Beispiel #1
0
    def test_assign_value(self):
        segment_str = 'PID|1||123-456-789^^^HOSPITAL^MR||SURNAME^NAME^A|||M|||1111 SOMEWHERE STREET^^SOMEWHERE^^^USA||555-555-2004~444-333-222|||M\r'

        s = Segment('PID')
        parsed_s = parse_segment(segment_str)
        s.value = segment_str
        self.assertEqual(s.to_er7(), parsed_s.to_er7())

        s = Segment('PID', validation_level=VALIDATION_LEVEL.STRICT)
        parsed_a = parse_segment(segment_str)
        s.value = segment_str
        self.assertEqual(s.to_er7(), parsed_a.to_er7())
Beispiel #2
0
 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)
Beispiel #3
0
 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')
Beispiel #4
0
 def test_to_string_wd_field(self):
     """
     Tests that, in strict mode, a wd field is not present
     """
     # The EV1 message is of type WD
     s = 'EVN||20080115153000||AAA|AAA|20080114003000'
     parsed_s = parse_segment(s, version='2.7')
     self.assertEqual(parsed_s.to_er7(), 'EVN||20080115153000||AAA|AAA|20080114003000')
Beispiel #5
0
 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)
Beispiel #6
0
 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')
Beispiel #7
0
 def test_to_string_wd_field(self):
     """
     Tests that, in strict mode, a wd field is not present
     """
     # The EV1 message is of type WD
     s = 'EVN||20080115153000||AAA|AAA|20080114003000'
     parsed_s = parse_segment(s, version='2.7')
     self.assertEqual(parsed_s.to_er7(),
                      'EVN||20080115153000||AAA|AAA|20080114003000')
Beispiel #8
0
 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')
     msg.add(evn)
     self.assertFalse(msg.validate())
Beispiel #9
0
 def _get_msh(self, 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
Beispiel #10
0
 def test_parse_segment_containing_multiple_instances_field(self):
     segment = 'QPD|||@PID.3.1^[email protected]^F'
     s = parse_segment(segment)
     self.assertEqual(len(s.qpd_3), 2)
     # check single PID_3 instances
     self.assertEqual(s.qpd_3[0].qpd_3_1.to_er7(), '@PID.3.1')
     self.assertEqual(s.qpd_3[0].qpd_3_2.to_er7(), 'aaaa')
     self.assertEqual(s.qpd_3[1].qpd_3_1.to_er7(), '@PID.8')
     self.assertEqual(s.qpd_3[1].qpd_3_2.to_er7(), 'F')
Beispiel #11
0
 def test_parse_segment_all_values_null(self):
     segment = 'PID|||||||||||'
     s = parse_segment(segment)
     self.assertEqual(len(s.children), 0)
     s.pid_2.to_er7()
     s.pid_23.to_er7()
     self.assertEqual(len(s.children), 0)
     s.pid_23 = ''
     self.assertEqual(s.to_er7(), 'PID|||||||||||||||||||||||')
Beispiel #12
0
 def test_parse_segment_containing_multiple_instances_field(self):
     segment = 'QPD|||@PID.3.1^[email protected]^F'
     s = parse_segment(segment)
     self.assertEqual(len(s.qpd_3), 2)
     # check single PID_3 instances
     self.assertEqual(s.qpd_3[0].qpd_3_1.to_er7(), '@PID.3.1' )
     self.assertEqual(s.qpd_3[0].qpd_3_2.to_er7(), 'aaaa')
     self.assertEqual(s.qpd_3[1].qpd_3_1.to_er7(), '@PID.8' )
     self.assertEqual(s.qpd_3[1].qpd_3_2.to_er7(), 'F')
Beispiel #13
0
 def test_parse_segment_all_values_null(self):
     segment = 'PID|||||||||||'
     s = parse_segment(segment)
     self.assertEqual(len(s.children), 0)
     s.pid_2.to_er7()
     s.pid_23.to_er7()
     self.assertEqual(len(s.children), 0)
     s.pid_23 = ''
     self.assertEqual(s.to_er7(), 'PID|||||||||||||||||||||||')
Beispiel #14
0
 def _get_msh(self, 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
Beispiel #15
0
 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.adt_a01)
     spm = parse_segment('SPM|1|100187400201^||SPECIMEN^Blood|||||||PSN^Human Patient||||||20110708162817||20110708162817|||||||1|CONTAINER^CONTAINER DESC\r')
     msg.add(spm)
     self.assertFalse(msg.validate())
Beispiel #16
0
 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')
Beispiel #17
0
 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')
Beispiel #18
0
 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')
Beispiel #19
0
 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')
     msg.add(evn)
     self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
     self._test_report_file('ERROR')
Beispiel #20
0
 def test_parse_wd_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'
     self.assertRaises(MaxChildLimitReached, parse_segment, s, version='2.7',
                       validation_level=VALIDATION_LEVEL.STRICT)
     parsed_s = parse_segment(s, version='2.7')
     self.assertEqual(parsed_s.to_er7(), s)
Beispiel #21
0
    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 STREET^^SOMEWHERE^^^USA||555-555-2004~444-333-222|||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')
Beispiel #22
0
 def test_parse_wd_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'
     self.assertRaises(MaxChildLimitReached,
                       parse_segment,
                       s,
                       version='2.7',
                       validation_level=VALIDATION_LEVEL.STRICT)
     parsed_s = parse_segment(s, version='2.7')
     self.assertEqual(parsed_s.to_er7(), s)
Beispiel #23
0
 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')
Beispiel #24
0
 def test_parse_segment_custom_encoding_chars(self):
     segment = 'PV1@1@I@PATIENT WARD@U@@@@$REFERRING$DOCTOR$$MD@$CONSULTING$DOCTOR$P@CAR@@@@2@A0@@@@@@@@'
     s = parse_segment(segment, encoding_chars=self._get_custom_encoding_chars())
     self.assertEqual(s.pv1_3.to_er7(), 'PATIENT WARD')
     self.assertEqual(s.pv1_8.pv1_8_2.to_er7(), 'REFERRING')
Beispiel #25
0
 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')
Beispiel #26
0
 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')
Beispiel #27
0
 def test_parse_segment_custom_encoding_chars(self):
     segment = 'PV1@1@I@PATIENT WARD@U@@@@$REFERRING$DOCTOR$$MD@$CONSULTING$DOCTOR$P@CAR@@@@2@A0@@@@@@@@'
     s = parse_segment(segment, encoding_chars=self._get_custom_encoding_chars())
     self.assertEqual(s.pv1_3.to_er7(), 'PATIENT WARD')
     self.assertEqual(s.pv1_8.pv1_8_2.to_er7(), 'REFERRING')
Beispiel #28
0
 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')