Closed kathrine-swe closed 8 months 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)
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)