예제 #1
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')
예제 #2
0
    def test_assign_value_with_repetition(self):
        field_str = 'xxx~yyy'
        f = Field()
        f.value = field_str
        self.assertEqual(f.to_er7(), 'xxx\R\yyy')

        f = Field('PID_2')
        f.value = field_str
        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')
예제 #3
0
    def test_to_string_z_segment_with_unknown_fields(self):
        f1 = Field()
        f1.value = 'abc'
        f2 = Field()
        f2.value = 'cba'

        zin = Segment('ZIN')
        zin.zin_1 = 'yyy'
        zin.add(f1)
        self.assertEqual(zin.to_er7(), 'ZIN|yyy|abc')
        zin.zin_4 = 'zzz'
        self.assertEqual(zin.to_er7(), 'ZIN|yyy|||zzz|abc')
        zin.add(f2)
        self.assertEqual(zin.to_er7(), 'ZIN|yyy|||zzz|abc|cba')
예제 #4
0
    def test_assign_value_with_field_separator(self):
        field_str = 'xxx|yyy'
        escaped_str = 'xxx\F\yyy'
        f = Field('PID_3')
        f.value = field_str
        self.assertEqual(f.to_er7(), escaped_str)

        f = Field('PID_3', validation_level=VALIDATION_LEVEL.STRICT)
        f.value = field_str
        self.assertEqual(f.to_er7(), escaped_str)

        f = Field()
        f.value = field_str
        self.assertEqual(f.to_er7(), 'xxx\F\yyy')
예제 #5
0
    def test_assign_value(self):
        field_str = '1010110909194822^^^AUTH&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK'

        f = Field('PID_3')
        f.value = field_str
        parsed_field = parse_field(field_str, 'PID_3')
        self.assertEqual(f.to_er7(), parsed_field.to_er7())

        f = Field('PID_3', validation_level=VALIDATION_LEVEL.STRICT)
        f.value = field_str
        self.assertEqual(f.to_er7(), parsed_field.to_er7())

        f = Field('PID_1', validation_level=VALIDATION_LEVEL.STRICT)
        with self.assertRaises(MaxChildLimitReached):
            f.value = '1^2'
예제 #6
0
 def test_wrong_z_field(self):
     """
     Tests that Fields of None datatype are not validated
     """
     f = Field('zin_1')
     f.value = 'aa^bb'
     self.assertRaises(ValidationError, f.validate, report_file=self.report_file)
     self._test_report_file('ERROR')
예제 #7
0
 def test_wrong_z_field(self):
     """
     Tests that Fields of None datatype are not validated
     """
     f = Field('zin_1')
     f.value = 'aa^bb'
     self.assertRaises(ValidationError, f.validate, report_file=self.report_file)
     self._test_report_file('ERROR')
예제 #8
0
 def test_z_segment(self):
     """
     Tests that, after adding a Z segment to a valid message, the message is still valid
     """
     msg = self._create_message(self.rsp_k21)
     msg.add_segment('zin')
     msg.zin = 'ZIN|aa|bb|cc|'
     zin_4 = Field('ZIN_4', datatype='CWE')
     zin_4.value = 'dd'
     msg.zin.zin_4 = zin_4
     self.assertTrue(msg.validate())
예제 #9
0
 def test_z_segment(self):
     """
     Tests that, after adding a Z segment to a valid message, the message is still valid
     """
     msg = self._create_message(self.rsp_k21)
     msg.add_segment('zin')
     msg.zin = 'ZIN|aa|bb|cc|'
     zin_4 = Field('ZIN_4', datatype='CWE')
     zin_4.value = 'dd'
     msg.zin.zin_4 = zin_4
     self.assertTrue(msg.validate())
예제 #10
0
    def test_wrong_z_segment(self):
        """
        Tests that, if the Z segment doesn't follow HL7 rules, the message is not validated
        """
        msg = self._create_message(self.adt_a01)
        msg.add_segment('zin')
        msg.zin = 'ZIN|aa|bb|cc|'
        # CX_1 is mandatory
        zin_4 = Field('ZIN_4', datatype='CX')
        zin_4.value = '^12'
        msg.zin.add(zin_4)
        self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)

        del msg.zin.zin_4

        # Z segment with unknown fields are not validated
        msg.zin.add(Field())
        self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
        self._test_report_file('ERROR')
예제 #11
0
    def test_wrong_z_segment(self):
        """
        Tests that, if the Z segment doesn't follow HL7 rules, the message is not validated
        """
        msg = self._create_message(self.adt_a01)
        msg.add_segment('zin')
        msg.zin = 'ZIN|aa|bb|cc|'
        # CX_1 is mandatory
        zin_4 = Field('ZIN_4', datatype='CX', version='2.6')
        zin_4.value = '^12'
        msg.zin.add(zin_4)
        self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)

        del msg.zin.zin_4

        # Z segment with unknown fields are not validated
        msg.zin.add(Field(version="2.6"))
        self.assertRaises(ValidationError, msg.validate, report_file=self.report_file)
        self._test_report_file('ERROR')
예제 #12
0
 def test_assign_value_unknown_field(self):
     field_str = '1010110909194822^^^AUTH&1.3.6.1.4.1.21367.2011.2.5.17&ISO^PK'
     f = Field()
     f.value = field_str