crs4 / hl7apy

Python library to parse, create and handle HL7 v2 messages.
http://crs4.github.io/hl7apy/
MIT License
231 stars 91 forks source link

Invalid Segments in OML_O21 message #91

Closed kathrine-swe closed 8 months ago

kathrine-swe commented 3 years ago

I'm trying to create an OML_O21 message with optional PID and required ORC segments. I am receiving the following error: Invalid children detected for <Message OML_O21>: ['PID', 'ORC']

My message construction is as follows: `message = Message('OML_O21') message.msh.sending_application = 'HALO' message.msh.sending_facility = 'NIH' message.msh.receiving_application = 'DXP' message.msh.receiving_facility = 'NIH' message.msh.security = '' message.msh.message_type = 'OML_O21' message.msh.message_control_id = '2020111817312300001' message.msh.processing_id = 'T' try: message.msh.validate() logger.debug("MSH Validated") except Exception as e: logger.error(e)

    message.add_segment('PID')
    message.pid.pid_1 = '1' # set_id
    message.pid.pid_2 = '123456789012' # External patient id
    message.pid.pid_3 = '210987654321' # Internal patient id
    message.pid.patient_name = 'BROWN^JOHN^PETER^JR^MD'
    try:
        message.pid.validate()
        logger.debug("PID Validated")
    except Exception as e:
        logger.error(e)

    message.add_segment('ORC')
    message.orc.order_control = 'NW'
    message.orc.orc_2 = 'SB-20-182642' # Place order control
    try:
        message.orc.validate()
        logger.debug("ORC Validated")
    except Exception as e:
        logger.error(e)

    try:
        message.validate()
        logger.debug("HL7 message validated")
    except Exception as e:
        logger.error(e)`
rileyschack commented 3 years ago

The PID segment must be within a PATIENT group, and the ORC segment must be within an ORDER group. Try this instead

from hl7apy.core import Message

message = Message('OML_O21')
message.msh.sending_application = 'HALO'
message.msh.sending_facility = 'NIH'
message.msh.receiving_application = 'DXP'
message.msh.receiving_facility = 'NIH'
message.msh.security = ''
message.msh.message_type = 'OML_O21'
message.msh.message_control_id = '2020111817312300001'
message.msh.processing_id = 'T'

try:
    message.msh.validate()
    print("MSH Validated")
except Exception as e:
    print(e)

message.add_group('OML_O21_PATIENT')
message.oml_o21_patient.add_segment('PID')
message.oml_o21_patient.pid.pid_1 = '1' # set_id
message.oml_o21_patient.pid.pid_2 = '123456789012' # External patient id
message.oml_o21_patient.pid.pid_3 = '210987654321' # Internal patient id
message.oml_o21_patient.pid.patient_name = 'BROWN^JOHN^PETER^JR^MD'

try:
    message.oml_o21_patient.pid.validate()
    print("PID Validated")
except Exception as e:
    print(e)

message.add_group("OML_O21_ORDER")
message.oml_o21_order.add_segment('ORC')
message.oml_o21_order.orc.order_control = 'NW'
message.oml_o21_order.orc.orc_2 = 'SB-20-182642' # Place order control

try:
    message.oml_o21_order.orc.validate()
    print("ORC Validated")
except Exception as e:
    print(e)

try:
    message.validate()
    print("HL7 message validated")
except Exception as e:
    print(e)