using NHapi.Model.V26.Message;
using NHapi.Model.V26.Segment;
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);
_ = 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).ReplaceLineEndings();
Console.WriteLine(encoded);