-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathXMLOperation.cls
More file actions
96 lines (75 loc) · 3.58 KB
/
Copy pathXMLOperation.cls
File metadata and controls
96 lines (75 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/// HL7 XML operations common class
Class ITB.HL7.BO.XMLOperation Extends ITB.HL7.BO.XMLReplyStandard
{
/// Enable NACK control. A SearchTable MUST be used. Configure a Service to receive async NACK messages and process them in ITB.HL7.BP.NACKProcess
Property NACKControl As %Boolean [ InitialExpression = 0 ];
/// Strip namespace in HL7 XML.
Property StripNamespace As %Boolean [ InitialExpression = 1 ];
Parameter SETTINGS = "StripNamespace,NACKControl,SearchTableClass::selector?context={Ens.ContextSearch/SearchTableClasses?host=EnsLib.HL7.Service.Standard},MessageSchemaCategory:Basic:selector?context={Ens.ContextSearch/SchemaCategories?host=EnsLib.HL7.Service.Standard}";
/// Send EnsLib.HL7.Message as XML
Method SendHL7XML(pRequest As EnsLib.HL7.Message, Output pResponse As EnsLib.HL7.Message, pGetAck As %Boolean = 0) As %Status
{
set ret = $$$OK
try {
if pRequest.DocType="" {
set pRequest.DocType = ##class(ITB.HL7.Util.Convert).CalculateDocType(pRequest,..MessageSchemaCategory)
}
// index HL7 in SearchTable
if ..SearchTableClass'="" {
set tSC = $zobjclassmethod(..SearchTableClass,"IndexDoc",pRequest)
if $$$ISERR(tSC) $$$LOGERROR("SearchTableClass Error: "_##class(%SYSTEM.Status).GetErrorText(tSC))
}
// convert EnsLib.HL7.Message to XML
set tXML = ##class(ITB.HL7.Util.Convert).ER7ToXML(pRequest,.tSC,..MessageSchemaCategory,,,..StripNamespace)
if $$$ISERR(tSC) $$$ThrowStatus(tSC)
// call XML message handler before sending
$$$ThrowOnError(..HandleXMLBeforeSending(tXML, .tXMLToSend))
// send XML through adapter
set tAckXML = ##class(%Stream.GlobalCharacter).%New()
$$$THROWONERROR(tSC, ..AdapterSendStream(tXMLToSend, .tAckXML))
if pGetAck {
// show received XML
$$$TRACE(tAckXML.Read())
do tAckXML.Rewind()
// convert received XML ack to ER7
set tReplyDoc = ##class(ITB.HL7.Util.Convert).XMLToER7(tAckXML,.tSC,..MessageSchemaCategory)
if $$$ISERR(tSC) $$$ThrowStatus(tSC)
set tReplyDoc.OriginalDocId=pRequest.%Id()
set tReplyTypeName=tReplyDoc.Name, tReplyCategory=$s(""'=pRequest.MessageTypeCategory:pRequest.MessageTypeCategory,1:$P(pRequest.DocType,":"))
do ##class(EnsLib.HL7.Schema).ResolveReplyNameAndDocType(tReplyCategory_":"_pRequest.Name,.tReplyDocName,.tReplyDocType,0)
$$$TRACE("Got reply message "_tReplyDoc_" of type "_tReplyTypeName_$S(tReplyTypeName=tReplyDocName:"",1:", expected type "_tReplyDocName))
set tReplyDoc.IsMutable=0
kill ..%ActionHint Set ..%ActionHint("AckType")=tReplyTypeName, ..%ActionHint("ReplyDocName")=tReplyDocName, ..%ActionHint("MsgType")="HL7"
set pResponse = tReplyDoc
}
if ..NACKControl {
set tSC = ##class(ITB.HL7.Data.NACK).RemoveError(pRequest,..%RequestHeader.TargetConfigName)
}
} catch ex {
set ret = ex.AsStatus()
}
quit ret
}
/// Send stream using Adapter (this method should be overwritten in derived operations)
Method AdapterSendStream(pRequest As %Stream.Object, Output pResponse As %Stream.Object) As %Status
{
}
/// Handle XML before sending. This method can be overridden to perform transformations in XML before sending message.
Method HandleXMLBeforeSending(pXML As %Stream.Object, Output pXMLToSend As %Stream.Object) As %Status
{
set pXMLToSend = pXML
quit $$$OK
}
/// Return an array of connections for drawing lines on the config diagram
ClassMethod OnGetConnections(Output pArray As %String, pItem As Ens.Config.Item)
{
do ##super(.pArray,pItem)
if pItem.GetModifiedSetting("TargetConfigNames",.tValue) {
for i=1:1:$L(tValue,",") {
set tOne=$zstrip($p(tValue,",",i),"<>W")
continue:""=tOne
set pArray(tOne)=""
}
}
}
}