Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Child limit exceeded ORU_R01_OBSERVATION.OBX #90

Open
kwiechen opened this issue Mar 6, 2021 · 4 comments
Open

Child limit exceeded ORU_R01_OBSERVATION.OBX #90

kwiechen opened this issue Mar 6, 2021 · 4 comments

Comments

@kwiechen
Copy link

kwiechen commented Mar 6, 2021

I have tried adding an additional OBX segment to an ORU_R01 message using a slightly modified code from Michael Sarfati

from hl7apy import core

hl7 = core.Message("ORU_R01", version="2.2")

hl7.msh.msh_3 = "SendingApp"
hl7.msh.msh_4 = "SendingFac"
hl7.msh.msh_5 = "ReceivingApp"
hl7.msh.msh_6 = "ReceivingFac"
hl7.msh.msh_9 = "ORU^R01"
hl7.msh.msh_10 = "168715"
hl7.msh.msh_11 = "P"

hl7.ORU_R01_PATIENT_RESULT.ORU_R01_PATIENT.PID.pid_3 = "1"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_PATIENT.PID.pid_5 = "Patient^Test"

hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.OBR.obr_4 = "10000"

hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_1 = "1"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_2 = "ST"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_3 = "PDF"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_5 = "Test"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_11 = "F" # Observ Result Status -- "F" meaning 'Final result'

obx = core.Segment("OBX", version="2.2")
obx.obx_1 = "2"
obx.obx_2 = "ST"
obx.obx_5 = "Test2"
obx.obx_11 = "F"

hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.add(obx)

assert hl7.validate() is True

-> gives exception: Child limit exceeded ORU_R01_OBSERVATION.OBX

As far as I understand the specification one or more OBX segments are allowed?

Best regards,

Kai

@rileyschack
Copy link

The specification allows for 1 OBX segment per OBSERVATION group. You'll need to add a new OBSERVATION group for each OBX segment you would like to add.

@perjer4675
Copy link

@kwiechen @rileyschack Do you have an code example? I do not understand.

@svituz
Copy link
Member

svituz commented Sep 10, 2021

@kwiechen @perjer4675 As @rileyschack suggested, OBX segment is part of the ORU_R01_OBSERVATION group which, in turn, is part of ORU_R01_ORDER_OBSERVATION group. It means that you need to create both groups and attach them to ORU_R01_PATIENT_RESULT group.

This will add the OBX:

from hl7apy import core

hl7 = core.Message("ORU_R01", version="2.2")

hl7.msh.msh_3 = "SendingApp"
hl7.msh.msh_4 = "SendingFac"
hl7.msh.msh_5 = "ReceivingApp"
hl7.msh.msh_6 = "ReceivingFac"
hl7.msh.msh_9 = "ORU^R01"
hl7.msh.msh_10 = "168715"
hl7.msh.msh_11 = "P"

hl7.ORU_R01_PATIENT_RESULT.ORU_R01_PATIENT.PID.pid_3 = "1"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_PATIENT.PID.pid_5 = "Patient^Test"

hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.OBR.obr_4 = "10000"

hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_1 = "1"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_2 = "ST"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_3 = "PDF"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_5 = "Test"
hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX.obx_11 = "F" # Observ Result Status -- "F" meaning 'Final result'

obx = core.Segment("OBX", version="2.2")
obx.obx_1 = "2"
obx.obx_2 = "ST"
obx.obx_5 = "Test2"
obx.obx_11 = "F"

order_observation_group = core.Group("ORU_R01_ORDER_OBSERVATION", version="2.2")
observation_group = core.Group("ORU_R01_OBSERVATION", version="2.2")
observation_group.add(obx)
order_observation_group.add(observation_group)

hl7.ORU_R01_PATIENT_RESULT.add(order_observation_group)
print(repr(hl7.to_er7()))

Resulting in

'MSH|^~\\&|SendingApp|SendingFac|ReceivingApp|ReceivingFac|20210910120522||ORU^R01|168715|P|2.2\rPID|||1||Patient^Test\rOBR||||10000\rOBX|1|ST|PDF||Test||||||F\rOBX|2|ST|||Test2||||||F'

You can access the second instance by index.

hl7.ORU_R01_PATIENT_RESULT.ORU_R01_ORDER_OBSERVATION[1].ORU_R01_OBSERVATION.OBX

More about accessing elements here

Notice that validation still fails due to your ORU_R01_OBSERVATIONs missing ORU segment but this is one step forward :)

@perjer4675
Copy link

@svituz thank you very much. ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants