Skip to content

Commit eb8447b

Browse files
committed
Bug fix for ACK creation and added custom implementations of ACK messages for V2.1 and V2.2
1 parent e145d86 commit eb8447b

File tree

8 files changed

+280
-2
lines changed

8 files changed

+280
-2
lines changed
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Type: NHapi.Model.V23.Message.ACK
2+
// Assembly: NHapi.Model.V23, Version=2.4.0.0, Culture=neutral, PublicKeyToken=d0d8ea960a3440eb
3+
// MVID: C7C4DA77-585C-442A-A512-1978F0E9C9C6
4+
// Assembly location: C:\Source\NHapiTools\References\NHapi.Model.V23.dll
5+
6+
using NHapi.Base;
7+
using NHapi.Base.Log;
8+
using NHapi.Base.Model;
9+
using NHapi.Base.Parser;
10+
using NHapi.Model.V21.Segment;
11+
using System;
12+
13+
namespace NHapiTools.Base.CustomImplementation.V21.Messages
14+
{
15+
/// <summary>
16+
/// Represents a ACK message structure (see chapter ). This structure contains the
17+
/// following elements:
18+
/// <ol><li>0: MSH (Message header segment) </li><li>1: MSA (Message acknowledgement segment) </li><li>2: ERR (Error segment) optional </li></ol>
19+
/// </summary>
20+
[Serializable]
21+
public class ACK : AbstractMessage
22+
{
23+
public override string Version
24+
{
25+
get
26+
{
27+
return "2.1";
28+
}
29+
}
30+
31+
/// <summary>
32+
/// Returns MSH (Message header segment) - creates it if necessary
33+
///
34+
/// </summary>
35+
public MSH MSH
36+
{
37+
get
38+
{
39+
try
40+
{
41+
return (MSH)this.GetStructure("MSH");
42+
}
43+
catch (HL7Exception ex)
44+
{
45+
HapiLogFactory.GetHapiLog(this.GetType()).Error((object)"Unexpected error accessing data - this is probably a bug in the source code generator.", (Exception)ex);
46+
throw new Exception("An unexpected error ocurred", (Exception)ex);
47+
}
48+
}
49+
}
50+
51+
/// <summary>
52+
/// Returns MSA (Message acknowledgement segment) - creates it if necessary
53+
///
54+
/// </summary>
55+
public MSA MSA
56+
{
57+
get
58+
{
59+
try
60+
{
61+
return (MSA)this.GetStructure("MSA");
62+
}
63+
catch (HL7Exception ex)
64+
{
65+
HapiLogFactory.GetHapiLog(this.GetType()).Error((object)"Unexpected error accessing data - this is probably a bug in the source code generator.", (Exception)ex);
66+
throw new Exception("An unexpected error ocurred", (Exception)ex);
67+
}
68+
}
69+
}
70+
71+
/// <summary>
72+
/// Returns ERR (Error segment) - creates it if necessary
73+
///
74+
/// </summary>
75+
public ERR ERR
76+
{
77+
get
78+
{
79+
try
80+
{
81+
return (ERR)this.GetStructure("ERR");
82+
}
83+
catch (HL7Exception ex)
84+
{
85+
HapiLogFactory.GetHapiLog(this.GetType()).Error((object)"Unexpected error accessing data - this is probably a bug in the source code generator.", (Exception)ex);
86+
throw new Exception("An unexpected error ocurred", (Exception)ex);
87+
}
88+
}
89+
}
90+
91+
/// <summary>
92+
/// Creates a new ACK Group with custom IModelClassFactory.
93+
///
94+
/// </summary>
95+
public ACK(IModelClassFactory factory)
96+
: base(factory)
97+
{
98+
this.init(factory);
99+
}
100+
101+
/// <summary>
102+
/// Creates a new ACK Group with DefaultModelClassFactory.
103+
///
104+
/// </summary>
105+
public ACK()
106+
: base((IModelClassFactory)new DefaultModelClassFactory())
107+
{
108+
this.init((IModelClassFactory)new DefaultModelClassFactory());
109+
}
110+
111+
/// <summary>
112+
/// initalize method for ACK. This does the segment setup for the message.
113+
///
114+
/// </summary>
115+
private void init(IModelClassFactory factory)
116+
{
117+
try
118+
{
119+
this.add(typeof(MSH), true, false);
120+
this.add(typeof(MSA), true, false);
121+
this.add(typeof(ERR), false, false);
122+
}
123+
catch (HL7Exception ex)
124+
{
125+
HapiLogFactory.GetHapiLog(this.GetType()).Error((object)"Unexpected error creating ACK - this is probably a bug in the source code generator.", (Exception)ex);
126+
}
127+
}
128+
}
129+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Type: NHapi.Model.V23.Message.ACK
2+
// Assembly: NHapi.Model.V23, Version=2.4.0.0, Culture=neutral, PublicKeyToken=d0d8ea960a3440eb
3+
// MVID: C7C4DA77-585C-442A-A512-1978F0E9C9C6
4+
// Assembly location: C:\Source\NHapiTools\References\NHapi.Model.V23.dll
5+
6+
using NHapi.Base;
7+
using NHapi.Base.Log;
8+
using NHapi.Base.Model;
9+
using NHapi.Base.Parser;
10+
using NHapi.Model.V22.Segment;
11+
using System;
12+
13+
namespace NHapiTools.Base.CustomImplementation.V22.Messages
14+
{
15+
/// <summary>
16+
/// Represents a ACK message structure (see chapter ). This structure contains the
17+
/// following elements:
18+
/// <ol><li>0: MSH (Message header segment) </li><li>1: MSA (Message acknowledgement segment) </li><li>2: ERR (Error segment) optional </li></ol>
19+
/// </summary>
20+
[Serializable]
21+
public class ACK : AbstractMessage
22+
{
23+
public override string Version
24+
{
25+
get
26+
{
27+
return "2.2";
28+
}
29+
}
30+
31+
/// <summary>
32+
/// Returns MSH (Message header segment) - creates it if necessary
33+
///
34+
/// </summary>
35+
public MSH MSH
36+
{
37+
get
38+
{
39+
try
40+
{
41+
return (MSH)this.GetStructure("MSH");
42+
}
43+
catch (HL7Exception ex)
44+
{
45+
HapiLogFactory.GetHapiLog(this.GetType()).Error((object)"Unexpected error accessing data - this is probably a bug in the source code generator.", (Exception)ex);
46+
throw new Exception("An unexpected error ocurred", (Exception)ex);
47+
}
48+
}
49+
}
50+
51+
/// <summary>
52+
/// Returns MSA (Message acknowledgement segment) - creates it if necessary
53+
///
54+
/// </summary>
55+
public MSA MSA
56+
{
57+
get
58+
{
59+
try
60+
{
61+
return (MSA)this.GetStructure("MSA");
62+
}
63+
catch (HL7Exception ex)
64+
{
65+
HapiLogFactory.GetHapiLog(this.GetType()).Error((object)"Unexpected error accessing data - this is probably a bug in the source code generator.", (Exception)ex);
66+
throw new Exception("An unexpected error ocurred", (Exception)ex);
67+
}
68+
}
69+
}
70+
71+
/// <summary>
72+
/// Returns ERR (Error segment) - creates it if necessary
73+
///
74+
/// </summary>
75+
public ERR ERR
76+
{
77+
get
78+
{
79+
try
80+
{
81+
return (ERR)this.GetStructure("ERR");
82+
}
83+
catch (HL7Exception ex)
84+
{
85+
HapiLogFactory.GetHapiLog(this.GetType()).Error((object)"Unexpected error accessing data - this is probably a bug in the source code generator.", (Exception)ex);
86+
throw new Exception("An unexpected error ocurred", (Exception)ex);
87+
}
88+
}
89+
}
90+
91+
/// <summary>
92+
/// Creates a new ACK Group with custom IModelClassFactory.
93+
///
94+
/// </summary>
95+
public ACK(IModelClassFactory factory)
96+
: base(factory)
97+
{
98+
this.init(factory);
99+
}
100+
101+
/// <summary>
102+
/// Creates a new ACK Group with DefaultModelClassFactory.
103+
///
104+
/// </summary>
105+
public ACK()
106+
: base((IModelClassFactory)new DefaultModelClassFactory())
107+
{
108+
this.init((IModelClassFactory)new DefaultModelClassFactory());
109+
}
110+
111+
/// <summary>
112+
/// initalize method for ACK. This does the segment setup for the message.
113+
///
114+
/// </summary>
115+
private void init(IModelClassFactory factory)
116+
{
117+
try
118+
{
119+
this.add(typeof(MSH), true, false);
120+
this.add(typeof(MSA), true, false);
121+
this.add(typeof(ERR), false, false);
122+
}
123+
catch (HL7Exception ex)
124+
{
125+
HapiLogFactory.GetHapiLog(this.GetType()).Error((object)"Unexpected error creating ACK - this is probably a bug in the source code generator.", (Exception)ex);
126+
}
127+
}
128+
}
129+
}

Base/NHapiTools.Base.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@
3535
<Reference Include="NHapi.Base">
3636
<HintPath>..\References\NHapi.Base.dll</HintPath>
3737
</Reference>
38+
<Reference Include="NHapi.Model.V21">
39+
<HintPath>..\References\NHapi.Model.V21.dll</HintPath>
40+
</Reference>
41+
<Reference Include="NHapi.Model.V22">
42+
<HintPath>..\References\NHapi.Model.V22.dll</HintPath>
43+
</Reference>
3844
<Reference Include="System" />
3945
<Reference Include="System.Configuration" />
4046
<Reference Include="System.Core" />
@@ -58,6 +64,8 @@
5864
<Compile Include="Configuration\EncodingRuleElement.cs" />
5965
<Compile Include="Configuration\RuleElementCollection.cs" />
6066
<Compile Include="Configuration\ValidationSection.cs" />
67+
<Compile Include="CustomImplementation\V21\Messages\ACK.cs" />
68+
<Compile Include="CustomImplementation\V22\Messages\ACK.cs" />
6169
<Compile Include="Extensions.cs" />
6270
<Compile Include="IO\HL7FilterBase64AttachmentsStream.cs" />
6371
<Compile Include="IO\HL7InputStreamMessageEnumerator.cs" />

Base/Util/Ack.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,16 @@ public IMessage MakeACK(IMessage inboundMessage, AckTypes ackResult, string erro
7474
// Get an object from the right ACK class
7575
string ackClassType = string.Format("NHapi.Model.V{0}.Message.ACK, NHapi.Model.V{0}", inboundMessage.Version.Replace(".", ""));
7676
Type x = Type.GetType(ackClassType);
77-
ackMessage = (IMessage)Activator.CreateInstance(x);
77+
if (x != null)
78+
ackMessage = (IMessage)Activator.CreateInstance(x);
79+
else
80+
{
81+
// Fix for V2.2 and V2.1 Since tha ACK message class is missing there in NHapi
82+
if (inboundMessage.Version == "2.1")
83+
ackMessage = (IMessage)new NHapiTools.Base.CustomImplementation.V21.Messages.ACK();
84+
if (inboundMessage.Version == "2.2")
85+
ackMessage = (IMessage)new NHapiTools.Base.CustomImplementation.V22.Messages.ACK();
86+
}
7887

7988
Terser inboundTerser = new Terser(inboundMessage);
8089
ISegment inboundHeader = null;
@@ -116,7 +125,7 @@ public IMessage MakeACK(IMessage inboundMessage, AckTypes ackResult, string erro
116125

117126
// Set error message
118127
if (errorMessage != null)
119-
terser.Set("/ERR-7", errorMessage);
128+
terser.Set("/ERR-1-1", errorMessage);
120129

121130
return ackMessage;
122131
}
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

BuildResult/Release notes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ curve and not everything works as easy as it should. NHapiTools aims to improve
1212
- Two sets of context implementation to easily add all or configurable validation rules.
1313

1414
3. Changelog
15+
- V1.5 Release (April 2015)
16+
Fixzed bug in ERR segment. Added custom ACK message classes for HL7 V2.2 and V2.1 since these seem to be missing from NHapi.
17+
1518
- V1.4 Release (December 2014)
1619
Added more HL7 versions. Finished documentation.
1720

0 commit comments

Comments
 (0)