diff --git a/src/NHapi.Model.V21/Group/ORM_O01_ORDER_DETAIL.cs b/src/NHapi.Model.V21/Group/ORM_O01_ORDER_DETAIL.cs index 87952cd64..9715fcca9 100644 --- a/src/NHapi.Model.V21/Group/ORM_O01_ORDER_DETAIL.cs +++ b/src/NHapi.Model.V21/Group/ORM_O01_ORDER_DETAIL.cs @@ -30,7 +30,7 @@ public class ORM_O01_ORDER_DETAIL : AbstractGroup { /// public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(parent, factory){ try { - this.add(typeof(OBR), true, false); + this.add(typeof(OBR), true, true); this.add(typeof(ORO), true, false); this.add(typeof(RX1), true, false); this.add(typeof(NTE), false, true); @@ -42,10 +42,9 @@ public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(pa } /// - /// Returns OBR (OBSERVATION REQUEST) - creates it if necessary + /// Returns first repetition of OBR (OBSERVATION REQUEST) - creates it if necessary /// - public OBR OBR { -get{ + public OBR GetOBR() { OBR ret = null; try { ret = (OBR)this.GetStructure("OBR"); @@ -55,6 +54,70 @@ public OBR OBR { } return ret; } + + /// + ///Returns a specific repetition of OBR + /// * (OBSERVATION REQUEST) - creates it if necessary + /// throws HL7Exception if the repetition requested is more than one + /// greater than the number of existing repetitions. + /// + public OBR GetOBR(int rep) { + return (OBR)this.GetStructure("OBR", rep); + } + + /** + * Returns the number of existing repetitions of OBR + */ + public int OBRRepetitionsUsed { +get{ + int reps = -1; + try { + reps = this.GetAll("OBR").Length; + } catch (HL7Exception e) { + string message = "Unexpected error accessing data - this is probably a bug in the source code generator."; + HapiLogFactory.GetHapiLog(GetType()).Error(message, e); + throw new System.Exception(message); + } + return reps; + } + } + + /** + * Enumerate over the OBR results + */ + public IEnumerable OBRs + { + get + { + for (int rep = 0; rep < OBRRepetitionsUsed; rep++) + { + yield return (OBR)this.GetStructure("OBR", rep); + } + } + } + + /// + ///Adds a new OBR + /// + public OBR AddOBR() + { + return this.AddStructure("OBR") as OBR; + } + + /// + ///Removes the given OBR + /// + public void RemoveOBR(OBR toRemove) + { + this.RemoveStructure("OBR", toRemove); + } + + /// + ///Removes the OBR at the given index + /// + public void RemoveOBRAt(int index) + { + this.RemoveRepetition("OBR", index); } /// diff --git a/src/NHapi.Model.V22/Group/ORM_O01_ORDER_DETAIL.cs b/src/NHapi.Model.V22/Group/ORM_O01_ORDER_DETAIL.cs index feafbec3b..d23e79216 100644 --- a/src/NHapi.Model.V22/Group/ORM_O01_ORDER_DETAIL.cs +++ b/src/NHapi.Model.V22/Group/ORM_O01_ORDER_DETAIL.cs @@ -33,7 +33,7 @@ public class ORM_O01_ORDER_DETAIL : AbstractGroup { /// public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(parent, factory){ try { - this.add(typeof(OBR), true, false); + this.add(typeof(OBR), true, true); this.add(typeof(RQD), true, false); this.add(typeof(RQ1), true, false); this.add(typeof(RXO), true, false); @@ -48,10 +48,9 @@ public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(pa } /// - /// Returns OBR (OBSERVATION REQUEST) - creates it if necessary + /// Returns first repetition of OBR (OBSERVATION REQUEST) - creates it if necessary /// - public OBR OBR { -get{ + public OBR GetOBR() { OBR ret = null; try { ret = (OBR)this.GetStructure("OBR"); @@ -61,6 +60,70 @@ public OBR OBR { } return ret; } + + /// + ///Returns a specific repetition of OBR + /// * (OBSERVATION REQUEST) - creates it if necessary + /// throws HL7Exception if the repetition requested is more than one + /// greater than the number of existing repetitions. + /// + public OBR GetOBR(int rep) { + return (OBR)this.GetStructure("OBR", rep); + } + + /** + * Returns the number of existing repetitions of OBR + */ + public int OBRRepetitionsUsed { +get{ + int reps = -1; + try { + reps = this.GetAll("OBR").Length; + } catch (HL7Exception e) { + string message = "Unexpected error accessing data - this is probably a bug in the source code generator."; + HapiLogFactory.GetHapiLog(GetType()).Error(message, e); + throw new System.Exception(message); + } + return reps; + } + } + + /** + * Enumerate over the OBR results + */ + public IEnumerable OBRs + { + get + { + for (int rep = 0; rep < OBRRepetitionsUsed; rep++) + { + yield return (OBR)this.GetStructure("OBR", rep); + } + } + } + + /// + ///Adds a new OBR + /// + public OBR AddOBR() + { + return this.AddStructure("OBR") as OBR; + } + + /// + ///Removes the given OBR + /// + public void RemoveOBR(OBR toRemove) + { + this.RemoveStructure("OBR", toRemove); + } + + /// + ///Removes the OBR at the given index + /// + public void RemoveOBRAt(int index) + { + this.RemoveRepetition("OBR", index); } /// diff --git a/src/NHapi.Model.V23/Group/ORM_O01_ORDER_DETAIL.cs b/src/NHapi.Model.V23/Group/ORM_O01_ORDER_DETAIL.cs index ff1aaaba3..166540bc7 100644 --- a/src/NHapi.Model.V23/Group/ORM_O01_ORDER_DETAIL.cs +++ b/src/NHapi.Model.V23/Group/ORM_O01_ORDER_DETAIL.cs @@ -33,7 +33,7 @@ public class ORM_O01_ORDER_DETAIL : AbstractGroup { /// public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(parent, factory){ try { - this.add(typeof(OBR), true, false); + this.add(typeof(OBR), true, true); this.add(typeof(RQD), true, false); this.add(typeof(RQ1), true, false); this.add(typeof(RXO), true, false); @@ -48,10 +48,9 @@ public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(pa } /// - /// Returns OBR (Observation request segment) - creates it if necessary + /// Returns first repetition of OBR (Observation request segment) - creates it if necessary /// - public OBR OBR { -get{ + public OBR GetOBR() { OBR ret = null; try { ret = (OBR)this.GetStructure("OBR"); @@ -61,6 +60,70 @@ public OBR OBR { } return ret; } + + /// + ///Returns a specific repetition of OBR + /// * (Observation request segment) - creates it if necessary + /// throws HL7Exception if the repetition requested is more than one + /// greater than the number of existing repetitions. + /// + public OBR GetOBR(int rep) { + return (OBR)this.GetStructure("OBR", rep); + } + + /** + * Returns the number of existing repetitions of OBR + */ + public int OBRRepetitionsUsed { +get{ + int reps = -1; + try { + reps = this.GetAll("OBR").Length; + } catch (HL7Exception e) { + string message = "Unexpected error accessing data - this is probably a bug in the source code generator."; + HapiLogFactory.GetHapiLog(GetType()).Error(message, e); + throw new System.Exception(message); + } + return reps; + } + } + + /** + * Enumerate over the OBR results + */ + public IEnumerable OBRs + { + get + { + for (int rep = 0; rep < OBRRepetitionsUsed; rep++) + { + yield return (OBR)this.GetStructure("OBR", rep); + } + } + } + + /// + ///Adds a new OBR + /// + public OBR AddOBR() + { + return this.AddStructure("OBR") as OBR; + } + + /// + ///Removes the given OBR + /// + public void RemoveOBR(OBR toRemove) + { + this.RemoveStructure("OBR", toRemove); + } + + /// + ///Removes the OBR at the given index + /// + public void RemoveOBRAt(int index) + { + this.RemoveRepetition("OBR", index); } /// diff --git a/src/NHapi.Model.V231/Group/ORM_O01_ORDER_DETAIL.cs b/src/NHapi.Model.V231/Group/ORM_O01_ORDER_DETAIL.cs index 769cd2379..161c66de2 100644 --- a/src/NHapi.Model.V231/Group/ORM_O01_ORDER_DETAIL.cs +++ b/src/NHapi.Model.V231/Group/ORM_O01_ORDER_DETAIL.cs @@ -33,7 +33,7 @@ public class ORM_O01_ORDER_DETAIL : AbstractGroup { /// public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(parent, factory){ try { - this.add(typeof(OBR), true, false); + this.add(typeof(OBR), true, true); this.add(typeof(RQD), true, false); this.add(typeof(RQ1), true, false); this.add(typeof(ODS), true, false); @@ -48,10 +48,9 @@ public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(pa } /// - /// Returns OBR (OBR - observation request segment) - creates it if necessary + /// Returns first repetition of OBR (OBR - observation request segment) - creates it if necessary /// - public OBR OBR { -get{ + public OBR GetOBR() { OBR ret = null; try { ret = (OBR)this.GetStructure("OBR"); @@ -61,6 +60,70 @@ public OBR OBR { } return ret; } + + /// + ///Returns a specific repetition of OBR + /// * (OBR - observation request segment) - creates it if necessary + /// throws HL7Exception if the repetition requested is more than one + /// greater than the number of existing repetitions. + /// + public OBR GetOBR(int rep) { + return (OBR)this.GetStructure("OBR", rep); + } + + /** + * Returns the number of existing repetitions of OBR + */ + public int OBRRepetitionsUsed { +get{ + int reps = -1; + try { + reps = this.GetAll("OBR").Length; + } catch (HL7Exception e) { + string message = "Unexpected error accessing data - this is probably a bug in the source code generator."; + HapiLogFactory.GetHapiLog(GetType()).Error(message, e); + throw new System.Exception(message); + } + return reps; + } + } + + /** + * Enumerate over the OBR results + */ + public IEnumerable OBRs + { + get + { + for (int rep = 0; rep < OBRRepetitionsUsed; rep++) + { + yield return (OBR)this.GetStructure("OBR", rep); + } + } + } + + /// + ///Adds a new OBR + /// + public OBR AddOBR() + { + return this.AddStructure("OBR") as OBR; + } + + /// + ///Removes the given OBR + /// + public void RemoveOBR(OBR toRemove) + { + this.RemoveStructure("OBR", toRemove); + } + + /// + ///Removes the OBR at the given index + /// + public void RemoveOBRAt(int index) + { + this.RemoveRepetition("OBR", index); } /// diff --git a/src/NHapi.Model.V24/Group/ORM_O01_ORDER_DETAIL.cs b/src/NHapi.Model.V24/Group/ORM_O01_ORDER_DETAIL.cs index 43eda88c8..fa9303c42 100644 --- a/src/NHapi.Model.V24/Group/ORM_O01_ORDER_DETAIL.cs +++ b/src/NHapi.Model.V24/Group/ORM_O01_ORDER_DETAIL.cs @@ -34,7 +34,7 @@ public class ORM_O01_ORDER_DETAIL : AbstractGroup { /// public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(parent, factory){ try { - this.add(typeof(OBR), true, false); + this.add(typeof(OBR), true, true); this.add(typeof(RQD), true, false); this.add(typeof(RQ1), true, false); this.add(typeof(RXO), true, false); @@ -50,10 +50,9 @@ public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(pa } /// - /// Returns OBR (Observation Request) - creates it if necessary + /// Returns first repetition of OBR (Observation Request) - creates it if necessary /// - public OBR OBR { -get{ + public OBR GetOBR() { OBR ret = null; try { ret = (OBR)this.GetStructure("OBR"); @@ -63,6 +62,70 @@ public OBR OBR { } return ret; } + + /// + ///Returns a specific repetition of OBR + /// * (Observation Request) - creates it if necessary + /// throws HL7Exception if the repetition requested is more than one + /// greater than the number of existing repetitions. + /// + public OBR GetOBR(int rep) { + return (OBR)this.GetStructure("OBR", rep); + } + + /** + * Returns the number of existing repetitions of OBR + */ + public int OBRRepetitionsUsed { +get{ + int reps = -1; + try { + reps = this.GetAll("OBR").Length; + } catch (HL7Exception e) { + string message = "Unexpected error accessing data - this is probably a bug in the source code generator."; + HapiLogFactory.GetHapiLog(GetType()).Error(message, e); + throw new System.Exception(message); + } + return reps; + } + } + + /** + * Enumerate over the OBR results + */ + public IEnumerable OBRs + { + get + { + for (int rep = 0; rep < OBRRepetitionsUsed; rep++) + { + yield return (OBR)this.GetStructure("OBR", rep); + } + } + } + + /// + ///Adds a new OBR + /// + public OBR AddOBR() + { + return this.AddStructure("OBR") as OBR; + } + + /// + ///Removes the given OBR + /// + public void RemoveOBR(OBR toRemove) + { + this.RemoveStructure("OBR", toRemove); + } + + /// + ///Removes the OBR at the given index + /// + public void RemoveOBRAt(int index) + { + this.RemoveRepetition("OBR", index); } /// diff --git a/src/NHapi.Model.V25/Group/ORM_O01_ORDER_DETAIL.cs b/src/NHapi.Model.V25/Group/ORM_O01_ORDER_DETAIL.cs index 81b6da93e..7dc0eeb39 100644 --- a/src/NHapi.Model.V25/Group/ORM_O01_ORDER_DETAIL.cs +++ b/src/NHapi.Model.V25/Group/ORM_O01_ORDER_DETAIL.cs @@ -34,7 +34,7 @@ public class ORM_O01_ORDER_DETAIL : AbstractGroup { /// public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(parent, factory){ try { - this.add(typeof(OBR), true, false); + this.add(typeof(OBR), true, true); this.add(typeof(RQD), true, false); this.add(typeof(RQ1), true, false); this.add(typeof(RXO), true, false); @@ -50,10 +50,9 @@ public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(pa } /// - /// Returns OBR (Observation Request) - creates it if necessary + /// Returns first repetition of OBR (Observation Request) - creates it if necessary /// - public OBR OBR { -get{ + public OBR GetOBR() { OBR ret = null; try { ret = (OBR)this.GetStructure("OBR"); @@ -63,6 +62,70 @@ public OBR OBR { } return ret; } + + /// + ///Returns a specific repetition of OBR + /// * (Observation Request) - creates it if necessary + /// throws HL7Exception if the repetition requested is more than one + /// greater than the number of existing repetitions. + /// + public OBR GetOBR(int rep) { + return (OBR)this.GetStructure("OBR", rep); + } + + /** + * Returns the number of existing repetitions of OBR + */ + public int OBRRepetitionsUsed { +get{ + int reps = -1; + try { + reps = this.GetAll("OBR").Length; + } catch (HL7Exception e) { + string message = "Unexpected error accessing data - this is probably a bug in the source code generator."; + HapiLogFactory.GetHapiLog(GetType()).Error(message, e); + throw new System.Exception(message); + } + return reps; + } + } + + /** + * Enumerate over the OBR results + */ + public IEnumerable OBRs + { + get + { + for (int rep = 0; rep < OBRRepetitionsUsed; rep++) + { + yield return (OBR)this.GetStructure("OBR", rep); + } + } + } + + /// + ///Adds a new OBR + /// + public OBR AddOBR() + { + return this.AddStructure("OBR") as OBR; + } + + /// + ///Removes the given OBR + /// + public void RemoveOBR(OBR toRemove) + { + this.RemoveStructure("OBR", toRemove); + } + + /// + ///Removes the OBR at the given index + /// + public void RemoveOBRAt(int index) + { + this.RemoveRepetition("OBR", index); } /// diff --git a/src/NHapi.Model.V251/Group/ORM_O01_ORDER_DETAIL.cs b/src/NHapi.Model.V251/Group/ORM_O01_ORDER_DETAIL.cs index b3e46f192..b95cb9e10 100644 --- a/src/NHapi.Model.V251/Group/ORM_O01_ORDER_DETAIL.cs +++ b/src/NHapi.Model.V251/Group/ORM_O01_ORDER_DETAIL.cs @@ -34,7 +34,7 @@ public class ORM_O01_ORDER_DETAIL : AbstractGroup { /// public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(parent, factory){ try { - this.add(typeof(OBR), true, false); + this.add(typeof(OBR), true, true); this.add(typeof(RQD), true, false); this.add(typeof(RQ1), true, false); this.add(typeof(RXO), true, false); @@ -50,10 +50,9 @@ public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(pa } /// - /// Returns OBR (Observation Request) - creates it if necessary + /// Returns first repetition of OBR (Observation Request) - creates it if necessary /// - public OBR OBR { -get{ + public OBR GetOBR() { OBR ret = null; try { ret = (OBR)this.GetStructure("OBR"); @@ -63,6 +62,70 @@ public OBR OBR { } return ret; } + + /// + ///Returns a specific repetition of OBR + /// * (Observation Request) - creates it if necessary + /// throws HL7Exception if the repetition requested is more than one + /// greater than the number of existing repetitions. + /// + public OBR GetOBR(int rep) { + return (OBR)this.GetStructure("OBR", rep); + } + + /** + * Returns the number of existing repetitions of OBR + */ + public int OBRRepetitionsUsed { +get{ + int reps = -1; + try { + reps = this.GetAll("OBR").Length; + } catch (HL7Exception e) { + string message = "Unexpected error accessing data - this is probably a bug in the source code generator."; + HapiLogFactory.GetHapiLog(GetType()).Error(message, e); + throw new System.Exception(message); + } + return reps; + } + } + + /** + * Enumerate over the OBR results + */ + public IEnumerable OBRs + { + get + { + for (int rep = 0; rep < OBRRepetitionsUsed; rep++) + { + yield return (OBR)this.GetStructure("OBR", rep); + } + } + } + + /// + ///Adds a new OBR + /// + public OBR AddOBR() + { + return this.AddStructure("OBR") as OBR; + } + + /// + ///Removes the given OBR + /// + public void RemoveOBR(OBR toRemove) + { + this.RemoveStructure("OBR", toRemove); + } + + /// + ///Removes the OBR at the given index + /// + public void RemoveOBRAt(int index) + { + this.RemoveRepetition("OBR", index); } /// diff --git a/src/NHapi.Model.V26/Group/ORM_O01_ORDER_DETAIL.cs b/src/NHapi.Model.V26/Group/ORM_O01_ORDER_DETAIL.cs index cb8cdfb0d..464c93841 100644 --- a/src/NHapi.Model.V26/Group/ORM_O01_ORDER_DETAIL.cs +++ b/src/NHapi.Model.V26/Group/ORM_O01_ORDER_DETAIL.cs @@ -34,7 +34,7 @@ public class ORM_O01_ORDER_DETAIL : AbstractGroup { /// public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(parent, factory){ try { - this.add(typeof(OBR), true, false); + this.add(typeof(OBR), true, true); this.add(typeof(RQD), true, false); this.add(typeof(RQ1), true, false); this.add(typeof(RXO), true, false); @@ -50,10 +50,9 @@ public ORM_O01_ORDER_DETAIL(IGroup parent, IModelClassFactory factory) : base(pa } /// - /// Returns OBR (Observation Request) - creates it if necessary + /// Returns first repetition of OBR (Observation Request) - creates it if necessary /// - public OBR OBR { -get{ + public OBR GetOBR() { OBR ret = null; try { ret = (OBR)this.GetStructure("OBR"); @@ -63,6 +62,70 @@ public OBR OBR { } return ret; } + + /// + ///Returns a specific repetition of OBR + /// * (Observation Request) - creates it if necessary + /// throws HL7Exception if the repetition requested is more than one + /// greater than the number of existing repetitions. + /// + public OBR GetOBR(int rep) { + return (OBR)this.GetStructure("OBR", rep); + } + + /** + * Returns the number of existing repetitions of OBR + */ + public int OBRRepetitionsUsed { +get{ + int reps = -1; + try { + reps = this.GetAll("OBR").Length; + } catch (HL7Exception e) { + string message = "Unexpected error accessing data - this is probably a bug in the source code generator."; + HapiLogFactory.GetHapiLog(GetType()).Error(message, e); + throw new System.Exception(message); + } + return reps; + } + } + + /** + * Enumerate over the OBR results + */ + public IEnumerable OBRs + { + get + { + for (int rep = 0; rep < OBRRepetitionsUsed; rep++) + { + yield return (OBR)this.GetStructure("OBR", rep); + } + } + } + + /// + ///Adds a new OBR + /// + public OBR AddOBR() + { + return this.AddStructure("OBR") as OBR; + } + + /// + ///Removes the given OBR + /// + public void RemoveOBR(OBR toRemove) + { + this.RemoveStructure("OBR", toRemove); + } + + /// + ///Removes the OBR at the given index + /// + public void RemoveOBRAt(int index) + { + this.RemoveRepetition("OBR", index); } /// diff --git a/tests/NHapi.NUnit/Parser/PipeParserV23Tests.cs b/tests/NHapi.NUnit/Parser/PipeParserV23Tests.cs index a4cd8da0b..fda5ff7a1 100644 --- a/tests/NHapi.NUnit/Parser/PipeParserV23Tests.cs +++ b/tests/NHapi.NUnit/Parser/PipeParserV23Tests.cs @@ -591,5 +591,28 @@ public void TestObx5DataTypeIsSetFromObx2_WhenObx2IsEmptyAndDefaultIsSet_Default typeof(XPN), typeof(XTN), }; + + [Test] + public void ParseORMO01WithMultipleOBRInOrderDetail() + { + // Regression test for #80: every OBR in an ORM^O01 order detail must be reachable. + var message = + "MSH|^~\\&|HIS|MedCenter|LIS|MedCenter|20060307110114||ORM^O01|MSGID20060307110114|P|2.3\r" + + "ORC|NW|20060307110114\r" + + "OBR|1|20060307110114||003038^Urinalysis^L|||20060307110114\r" + + "OBR|2|20060307110114||003050^BloodCount^L|||20060307110114"; + + var parser = new PipeParser(); + + var m = parser.Parse(message) as ORM_O01; + + Assert.That(m, Is.Not.Null); + + var orderDetail = m.GetORDER(0).ORDER_DETAIL; + + Assert.That(orderDetail.OBRRepetitionsUsed, Is.EqualTo(2)); + Assert.That(orderDetail.GetOBR(0).SetIDObservationRequest.Value, Is.EqualTo("1")); + Assert.That(orderDetail.GetOBR(1).SetIDObservationRequest.Value, Is.EqualTo("2")); + } } } \ No newline at end of file diff --git a/tests/NHapi.NUnit/Parser/PipeParserV24Tests.cs b/tests/NHapi.NUnit/Parser/PipeParserV24Tests.cs index 7af3f3850..f437f53b3 100644 --- a/tests/NHapi.NUnit/Parser/PipeParserV24Tests.cs +++ b/tests/NHapi.NUnit/Parser/PipeParserV24Tests.cs @@ -520,5 +520,31 @@ public void TestObx5DataTypeIsSetFromObx2_WhenObx2IsEmptyAndDefaultIsSet_Default typeof(XPN), typeof(XTN), }; + + [Test] + public void ParseORMO01WithMultipleOBRInOrderDetail() + { + // ORM^O01 (v2.4) with a single ORC followed by more than one OBR in the order + // detail. Regression test for #80: every OBR must be reachable, not just the first. + var message = + "MSH|^~\\&|HIS|MedCenter|LIS|MedCenter|20060307110114||ORM^O01|MSGID20060307110114|P|2.4\r" + + "PID|||12001||Jones^John^^^Mr.||19670824|M|||123 West St.^^Denver^CO^80020^USA\r" + + "PV1||O|OP^PAREG^||||2342^Jones^Bob|||OP|||||||||2|||||||||||||||||||||||||20060307110111|\r" + + "ORC|NW|20060307110114\r" + + "OBR|1|20060307110114||003038^Urinalysis^L|||20060307110114\r" + + "OBR|2|20060307110114||003050^BloodCount^L|||20060307110114"; + + var parser = new PipeParser(); + + var m = parser.Parse(message) as ORM_O01; + + Assert.That(m, Is.Not.Null); + + var orderDetail = m.GetORDER(0).ORDER_DETAIL; + + Assert.That(orderDetail.OBRRepetitionsUsed, Is.EqualTo(2)); + Assert.That(orderDetail.GetOBR(0).SetIDOBR.Value, Is.EqualTo("1")); + Assert.That(orderDetail.GetOBR(1).SetIDOBR.Value, Is.EqualTo("2")); + } } } \ No newline at end of file diff --git a/tests/NHapi.NUnit/Parser/PipeParserV26Tests.cs b/tests/NHapi.NUnit/Parser/PipeParserV26Tests.cs index c73984a5e..09ca0ea31 100644 --- a/tests/NHapi.NUnit/Parser/PipeParserV26Tests.cs +++ b/tests/NHapi.NUnit/Parser/PipeParserV26Tests.cs @@ -419,5 +419,28 @@ public void TestObx5DataTypeIsSetFromObx2_WhenObx2IsEmptyAndDefaultIsSet_Default typeof(XPN), typeof(XTN), }; + + [Test] + public void ParseORMO01WithMultipleOBRInOrderDetail() + { + // Regression test for #80: every OBR in an ORM^O01 order detail must be reachable. + var message = + "MSH|^~\\&|HIS|MedCenter|LIS|MedCenter|20060307110114||ORM^O01|MSGID20060307110114|P|2.6\r" + + "ORC|NW|20060307110114\r" + + "OBR|1|20060307110114||003038^Urinalysis^L|||20060307110114\r" + + "OBR|2|20060307110114||003050^BloodCount^L|||20060307110114"; + + var parser = new PipeParser(); + + var m = parser.Parse(message) as ORM_O01; + + Assert.That(m, Is.Not.Null); + + var orderDetail = m.GetORDER(0).ORDER_DETAIL; + + Assert.That(orderDetail.OBRRepetitionsUsed, Is.EqualTo(2)); + Assert.That(orderDetail.GetOBR(0).SetIDOBR.Value, Is.EqualTo("1")); + Assert.That(orderDetail.GetOBR(1).SetIDOBR.Value, Is.EqualTo("2")); + } } } \ No newline at end of file