How to use the hl7apy.v2_5.ST function in hl7apy

To help you get started, we’ve selected a few hl7apy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crs4 / hl7apy / tests / test_core.py View on Github external
# string
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
        c.cwe_1 = subcmp_str
        self.assertEqual(c.cwe_1.to_er7(), subcmp_str)

        # string using value
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
        c.cwe_1.value = subcmp_str
        self.assertEqual(c.cwe_1.to_er7(), subcmp_str)

        # base datatype
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
        c.cwe_1 = ST(subcmp_str)
        self.assertEqual(c.cwe_1.to_er7(), subcmp_str)

        # base datatype using value
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
        c.cwe_1.value = ST(subcmp_str)
        self.assertEqual(c.cwe_1.to_er7(), subcmp_str)

        # further levels
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1 = subcmp_str
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)

        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1.value = subcmp_str
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)
github crs4 / hl7apy / tests / test_core.py View on Github external
# further level
        segment_str = 'PID||||^^^^^^^^^aaa'
        s = Segment('PID')
        s.pid_4.pid_4_10_1 = subcmp_str
        self.assertEqual(s.to_er7(), segment_str)

        s = Segment('PID')
        s.pid_4.pid_4_10_1.value = subcmp_str
        self.assertEqual(s.to_er7(), segment_str)

        s = Segment('PID')
        s.pid_4.pid_4_10_1.value = ST(subcmp_str)
        self.assertEqual(s.to_er7(), segment_str)

        s = Segment('PID')
        s.pid_4.pid_4_10_1.value = ST(subcmp_str)
        self.assertEqual(s.to_er7(), segment_str)
github crs4 / hl7apy / tests / test_core.py View on Github external
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
        c.cwe_1.value = ST(subcmp_str)
        self.assertEqual(c.cwe_1.to_er7(), subcmp_str)

        # further levels
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1 = subcmp_str
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)

        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1.value = subcmp_str
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)

        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1 = ST(subcmp_str)
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)

        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1.value = ST(subcmp_str)
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)
github crs4 / hl7apy / tests / test_core.py View on Github external
m.rsp_k21_query_response.pid.pid_39.cwe_1 = cmp_str
        self.assertEqual(m.rsp_k21_query_response.pid.pid_39.cwe_1.to_er7(), cmp_str)

        # value
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.rsp_k21_query_response.pid.pid_39.cwe_1.value = cmp_str
        self.assertEqual(m.rsp_k21_query_response.pid.pid_39.cwe_1.to_er7(), cmp_str)

        # name with base datatype
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.rsp_k21_query_response.pid.pid_39.cwe_1 = ST(cmp_str)
        self.assertEqual(m.rsp_k21_query_response.pid.pid_39.cwe_1.to_er7(), cmp_str)

        # value with base datatype
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.rsp_k21_query_response.pid.pid_39.cwe_1.value = ST(cmp_str)
        self.assertEqual(m.rsp_k21_query_response.pid.pid_39.cwe_1.to_er7(), cmp_str)

        # complex datatype
        complex_cmp_str = 'xxx&yyy&zzz'

        # name
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        f = m.add_segment('qpd').add_field('qpd_8')
        f.cx_10 = complex_cmp_str
        self.assertEqual(f.cx_10.to_er7(), complex_cmp_str)
        self.assertEqual(len(f.cx_10.children), 3)

        # value
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        f = m.add_segment('qpd').add_field('qpd_8')
        f.cx_10.value = complex_cmp_str
github crs4 / hl7apy / tests / test_core.py View on Github external
# string using value
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
        c.cwe_1.value = subcmp_str
        self.assertEqual(c.cwe_1.to_er7(), subcmp_str)

        # base datatype
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
        c.cwe_1 = ST(subcmp_str)
        self.assertEqual(c.cwe_1.to_er7(), subcmp_str)

        # base datatype using value
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('QPD').add_field('QPD_8').add_component('CX_10')
        c.cwe_1.value = ST(subcmp_str)
        self.assertEqual(c.cwe_1.to_er7(), subcmp_str)

        # further levels
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1 = subcmp_str
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)

        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1.value = subcmp_str
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)

        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        m.qpd.qpd_8.qpd_8_10_1 = ST(subcmp_str)
        self.assertEqual(m.qpd.qpd_8.cx_10.cwe_1.to_er7(), subcmp_str)

        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
github crs4 / hl7apy / tests / test_core.py View on Github external
f = Field('PID_3', validation_level=VALIDATION_LEVEL.TOLERANT) # It is a complex datatype field
        with self.assertRaises(ChildNotValid):
            f.value = ST('aaa')

        f = Field('PID_1', validation_level=VALIDATION_LEVEL.STRICT)
        f.value = SI(1)
        self.assertEqual(f.to_er7(), '1')
        f.value = SI(2)
        self.assertEqual(f.to_er7(), '2')
        with self.assertRaises(ChildNotValid):
            f.value = ST('aaa')

        f = Field('PID_3', validation_level=VALIDATION_LEVEL.STRICT) # It is a complex datatype field
        with self.assertRaises(ChildNotValid):
            f.value = ST('aaa')
github crs4 / hl7apy / tests / test_core.py View on Github external
# further level

        # name
        m = Message('RSP_K21')
        m.pid.pid_39.cwe_1 = cmp_str
        self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)

        # value
        m = Message('RSP_K21')
        m.pid.pid_39.cwe_1.value = cmp_str
        self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)

        # name with base datatype
        m = Message('RSP_K21')
        m.pid.pid_39.cwe_1 = ST(cmp_str)
        self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)

        # value with base datatype
        m = Message('RSP_K21')
        m.pid.pid_39.cwe_1.value = ST(cmp_str)
        self.assertEqual(m.pid.pid_39.cwe_1.to_er7(), cmp_str)

        # complex datatype
        complex_cmp_str = 'xxx&yyy&zzz'

        # name
        f = Field('PID_4')
        f.cx_10 = complex_cmp_str
        self.assertEqual(f.cx_10.to_er7(), complex_cmp_str)
        self.assertEqual(len(f.cx_10.children), 3)
github crs4 / hl7apy / tests / test_core.py View on Github external
def test_assign_value_base_datatype(self):
        # tolerant
        c = Component('CX_1', validation_level=VALIDATION_LEVEL.TOLERANT)
        c.value = ST('aaa')
        self.assertEqual(c.to_er7(), 'aaa')
        c.value = ST('bbb')
        self.assertEqual(c.to_er7(), 'bbb')

        with self.assertRaises(ChildNotValid):
            c.value = SI(1)

        # strict
        c = Component('CX_1', validation_level=VALIDATION_LEVEL.STRICT)
        c.value = ST('aaa')
        self.assertEqual(c.to_er7(), 'aaa')
        c.value = ST('bbb')
        self.assertEqual(c.to_er7(), 'bbb')

        with self.assertRaises(ChildNotValid):
            c.value = SI(1)

        # complex datatype
        # tolerant
        c = Component('CX_10', validation_level=VALIDATION_LEVEL.TOLERANT)
        with self.assertRaises(ChildNotValid):
            c.value = ST('aaa')

        # strict
        c = Component('CX_10', validation_level=VALIDATION_LEVEL.STRICT)
        with self.assertRaises(ChildNotValid):
github crs4 / hl7apy / tests / test_core.py View on Github external
m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
        c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_1')
        c.value = ST('aaa')
        self.assertEqual(c.to_er7(), 'aaa')
        c.value = ST('bbb')
        self.assertEqual(c.to_er7(), 'bbb')

        with self.assertRaises(ChildNotValid):
            c.value = SI(1)

        # strict
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_1')
        c.value = ST('aaa')
        self.assertEqual(c.to_er7(), 'aaa')
        c.value = ST('bbb')
        self.assertEqual(c.to_er7(), 'bbb')

        with self.assertRaises(ChildNotValid):
            c.value = SI(1)

        # complex datatype
        # tolerant
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
        c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
        with self.assertRaises(ChildNotValid):
            c.value = ST('aaa')

        # strict
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
        with self.assertRaises(ChildNotValid):
github crs4 / hl7apy / tests / test_core.py View on Github external
with self.assertRaises(ChildNotValid):
            c.value = SI(1)

        # complex datatype
        # tolerant
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.TOLERANT)
        c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
        with self.assertRaises(ChildNotValid):
            c.value = ST('aaa')

        # strict
        m = Message('RSP_K21', reference=self.rsp_k21_mp, validation_level=VALIDATION_LEVEL.STRICT)
        c = m.add_segment('qpd').add_field('qpd_8').add_component('cx_10')
        with self.assertRaises(ChildNotValid):
            c.value = ST('aaa')