-
I am using v251. I would like to know if an IMessage contains an optional segment or not. In my case I have en ORU_R01 type that may or may not include a PV1 segment, but I cannot find a "proper" way to determine that. I have tried using an ADT_A01 message. In this case I can use the IGroup.GetAll() method which seems to do the trick, but I fail to see that work for the ORU_R01 message. Maybe it has to do with me not knowing the right HL7 path expressions. As a workaround I have tried using Terser.Finder.FindSegment("PV1",0) and then checking some of the properties of the segment. It can work, but I consider it to be a poor option as it could lead to other issues. The below code shows an ORU_R01 message without a PV1 segment. In the bottom of the snippet I have added my attempts to identify the PV1 segment using various methods and HL7 path expressions. ORU_R01 oruMessage = new ORU_R01();
// Populate the MSH segment
MSH mshSegment = oruMessage.MSH;
mshSegment.FieldSeparator.Value = "|";
mshSegment.EncodingCharacters.Value = "^~\\&";
mshSegment.SendingApplication.NamespaceID.Value = "SendingApp";
mshSegment.SendingFacility.NamespaceID.Value = "SendingFacility";
mshSegment.ReceivingApplication.NamespaceID.Value = "ReceivingApp";
mshSegment.ReceivingFacility.NamespaceID.Value = "ReceivingFacility";
mshSegment.DateTimeOfMessage.Time.Value = DateTime.Now.ToString("yyyyMMddHHmmss");
mshSegment.MessageType.MessageCode.Value = "ORU";
mshSegment.MessageType.TriggerEvent.Value = "R01";
mshSegment.MessageControlID.Value = "12345";
mshSegment.ProcessingID.ProcessingID.Value = "P";
mshSegment.VersionID.VersionID.Value = "2.5.1";
// Populate the PID segment
PID pidSegment = oruMessage.GetPATIENT_RESULT().PATIENT.PID;
pidSegment.SetIDPID.Value = "1";
pidSegment.PatientID.IDNumber.Value = "123456";
pidSegment.GetPatientName(0).FamilyName.Surname.Value = "Doe";
pidSegment.GetPatientName(0).GivenName.Value = "John";
pidSegment.DateTimeOfBirth.Time.Value = "19800101";
pidSegment.AdministrativeSex.Value = "M";
// Populate the OBR segment
ORU_R01_ORDER_OBSERVATION orderObservation = oruMessage.GetPATIENT_RESULT().GetORDER_OBSERVATION();
OBR obrSegment = orderObservation.OBR;
obrSegment.SetIDOBR.Value = "1";
obrSegment.PlacerOrderNumber.EntityIdentifier.Value = "123456";
obrSegment.FillerOrderNumber.EntityIdentifier.Value = "654321";
obrSegment.UniversalServiceIdentifier.Identifier.Value = "TestCode";
obrSegment.ObservationDateTime.Time.Value = DateTime.Now.ToString("yyyyMMddHHmmss");
// Populate the OBX segment
OBX obxSegment = orderObservation.GetOBSERVATION().OBX;
obxSegment.SetIDOBX.Value = "1";
obxSegment.ValueType.Value = "TX";
obxSegment.ObservationIdentifier.Identifier.Value = "TestObservation";
obxSegment.Units.Identifier.Value = "mg/dL";
obxSegment.ReferencesRange.Value = "70-100";
obxSegment.ObservationResultStatus.Value = "F";
// Populate the PV1 segment
//PV1 pv1Segment = oruMessage.GetPATIENT_RESULT().PATIENT.VISIT.PV1;
var pv1 = oruMessage.GetPATIENT_RESULT().PATIENT.VISIT.PV1; //returns a PV1 object - I hoped for null
var pv1UsingGetAll1 = oruMessage.GetAll("PV1"); //throws exception no matter if I added the PV1 segment or not - I hoped for null if it does not exists
var pv1UsingGetAll2 = oruMessage.GetAll("PATIENT_RESULT/PATIENT/VISIT/PV1"); //throws exception no matter if I added the PV1 segment or not - I hoped for null if it does not exists |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@sse-jtc this might be helpful |
Beta Was this translation helpful? Give feedback.
-
This works for me. It does not throw an exception. it returns false when I don't create a PV1 and true if i call it after using
if you want to only detect properly set up PV1's then you could adjust like:
Since at least from my experience, the SetIDPV1.Value will be null on a unset PV1. I tested this with and without a PV1 in the ORU_R01 message and it worked as expected - and never reached the catch block. |
Beta Was this translation helpful? Give feedback.
If you don't want to risk adding any segments during these checks you can do something like
which will return 0 if there is no PV1 and will not create or throw an error if there is no VISIT, PATIENT or PATIENT_RESULTS group created yet.