QRF-5 ExtraComponents
alberk8 opened this issue · 8 comments
I have the QRF that needs to be transformed. How can this be done? I can get the Data below but I could not find a way to change the data on the fourth component.
ST part5 = qry_r02.QRF.GetOtherQRYSubjectFilter(0);
var msg = part5.ExtraComponents.GetComponent(3).Data
Original
QRF|MON||||168430091^5^1^0^2005&2005&2005&2005&2005
Transformed
QRF|MON||||168430091^5^1^0^2005
Hi @alberk8
Can you provide some additional data, what version of nHapi? what version of dotnet?
Could you provide complete sample code? perhaps on https://dotnetfiddle.net/
Also I'm not 100% certain on your desired outcome.
Hi,
I am using the latest version of NHapi 3.2, nhapi.model.v26 on net 7.0
I can extract the data from the code above but I want to transform the the QRF segment. I can't find a way to rebuild or change the field no 5.
MSH|^~\&||KC1234F3|||20230810160302+0800||QRY^R02|202308101603020042|P|2.6
QRD|20230810160302+0800|R|I|Q101||||TXE107200400230|RES
PID|||107200400230||Surname^Lastname|||M||||||||||107200400230
PV1||I|^^&1
QRF|MON||||168430091&5^5^1^0^2005&2005&2005&2005&2005
@alberk8 thanks for the extra info, I'll take a look in the coming week.
@milkshakeuk I have tried a few combinations. Is there a way to add non standard segment without the Terser?.
public QRY_R02 CustomQry()
{
var qry = new QRY_R02();
#region This can compile but runtime error at return
PID p1 = qry.AddStructure("PID");
p1.GetPatientIdentifierList(0).IDNumber.Value = "1234";
p1.GetPatientName(0).GivenName.Value = "John";
p1.DateTimeOfBirth.Value = "1970-01-10";
p1.AdministrativeSex.Value = "M";
#endregion
#region This works
qry.AddNonstandardSegment("PID");
Terser ter = new Terser(qry);
ter.Set("/PID(0)-3", "1234");
ter.Set("/PID(0)-5(0)-2", "John");
ter.Set("/PID(0)-7", "1970-01-10");
ter.Set("/PID(0)-8", "M");
#endregion
return qry;
}
@alberk8 to add the non-standard segment PID
without the Terser
you can do this:
using System;
using NHapi.Base.Parser;
using NHapi.Model.V26.Message;
using NHapi.Model.V26.Segment;
var er7 = """
MSH|^~\&||KC1234F3|||20230810160302+0800||QRY^R02|202308101603020042|P|2.6
QRD|20230810160302+0800|R|I|Q101||||TXE107200400230|RES
QRF|MON||||168430091&5^5^1^0^2005&2005&2005&2005&2005
""".ReplaceLineEndings("\r");
var pipeParser = new PipeParser();
var qryR02 = (QRY_R02)pipeParser.Parse(er7);
// Standard segments for QRY_R02 (v2.6)
// index: Name
// 0: MSH (Message Header)
// 1: SFT (Software Segment) optional repeating
// 2: UAC (User Authentication Credential Segment) optional
// 3: QRD (Original-Style Query Definition)
// 4: QRF (Original style query filter)
// Insert non-standard PID at index 4 (takes standard segment indexes into account)
// pushes QRF to index position 5
_ = qryR02.AddNonstandardSegment("PID", 4);
var pid = qryR02.GetStructure("PID") as PID;
pid.GetPatientIdentifierList(0).IDNumber.Value = "1234";
pid.GetPatientName(0).GivenName.Value = "John";
pid.DateTimeOfBirth.Value = "1970-01-10";
pid.AdministrativeSex.Value = "M";
var encoded = pipeParser.Encode(qryR02);
Console.WriteLine(encoded);
outputs the following:
MSH|^~\&||KC1234F3|||20230810160302+0800||QRY^R02|202308101603020042|P|2.6
QRD|20230810160302+0800|R|I|Q101||||TXE107200400230|RES
PID|||1234||^John||1970-01-10|M
QRF|MON||||168430091^5^1^0^2005&2005&2005&2005&2005
@alberk8 here is how you could customise QRF-5
:
using System;
using NHapi.Base.Parser;
using NHapi.Base.Model;
using NHapi.Model.V26.Message;
using NHapi.Model.V26.Datatype;
var er7 = """
MSH|^~\&||KC1234F3|||20230810160302+0800||QRY^R02|202308101603020042|P|2.6
QRD|20230810160302+0800|R|I|Q101||||TXE107200400230|RES
QRF|MON||||168430091&5^5^1^0^2005&2005&2005&2005&2005
""".ReplaceLineEndings("\r");
var pipeParser = new PipeParser();
var qryR02 = pipeParser.Parse(er7) as QRY_R02;
ST part5 = qryR02.QRF.GetOtherQRYSubjectFilter(0);
// getting non-existent component at index 4 component will create it
var newComponent = part5.ExtraComponents.GetComponent(4);
((GenericPrimitive)newComponent.Data).Value = "test";
// getting non-existent sub component at index 0 will create it
var newSubComponent = newComponent.ExtraComponents.GetComponent(0);
((GenericPrimitive)newSubComponent.Data).Value = "subcomponent";
Console.WriteLine(PipeParser.Encode(qryR02.QRF, EncodingCharacters.FromMessage(qryR02)));
outputs the following:
QRF|MON||||168430091^5^1^0^2005&2005&2005&2005&2005^test&subcomponent
@alberk8 can you let me know if these solve your issues?
@milkshakeuk , Thank you. It worked like a charm. I think this needs to go into an example. Thank you again.