[1544] | 1 | C0CMAIL2 ; Communications for MIME Documents and MultiMIME ; 3110420 ; rcr/rcr ; 5/10/12 2:50pm
|
---|
[1586] | 2 | ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
|
---|
[1544] | 3 | ;Copyright 2011 Chris Richardson, Richardson Computer Research
|
---|
| 4 | ; Modified 3110615@1040
|
---|
| 5 | ; rcr@rcresearch.us
|
---|
| 6 | ;
|
---|
[1586] | 7 | ; This program is free software: you can redistribute it and/or modify
|
---|
| 8 | ; it under the terms of the GNU Affero General Public License as
|
---|
| 9 | ; published by the Free Software Foundation, either version 3 of the
|
---|
| 10 | ; License, or (at your option) any later version.
|
---|
[1544] | 11 | ;
|
---|
[1586] | 12 | ; This program is distributed in the hope that it will be useful,
|
---|
| 13 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | ; GNU Affero General Public License for more details.
|
---|
[1544] | 16 | ;
|
---|
[1586] | 17 | ; You should have received a copy of the GNU Affero General Public License
|
---|
| 18 | ; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
[1544] | 19 | ;
|
---|
| 20 | ; ------------------
|
---|
| 21 | ;Entry Points
|
---|
| 22 | ; DETAIL^C0CMAIL(.C0CDATA,IEN) --> Get details of the Mail Message and Attachments
|
---|
| 23 | ; GETMSG^C0CMAIL(.C0CDATA,.C0CINPUT)
|
---|
| 24 | ; Input:
|
---|
| 25 | ; C0CINPUT = "DUZ;MAILBOX_Name[or IEN for box (comma Separated);MALL
|
---|
| 26 | ; or "*" for all boxes, default is "IN" if missing]"
|
---|
| 27 | ; $P(C0CINPUT,";",3)=MALL, default=NUL means "New only",
|
---|
| 28 | ; "*" for All or 9,999 maximum
|
---|
| 29 | ; MALL?1.n = that number of the n most recent
|
---|
| 30 | ; Internally:
|
---|
| 31 | ; BNAM = Box Name
|
---|
| 32 | ; Output:
|
---|
| 33 | ; C0CDATA
|
---|
| 34 | ; = (BNAM,"NUMBER") = Number of NEW Emails in Basket
|
---|
| 35 | ; (BNAM,"MSG",C0CIEN,"FROM")=Name
|
---|
| 36 | ; (BNAM,"MSG",C0CIEN,"TO",n)=DUZ, or EMAIL Address
|
---|
| 37 | ; (BNAM,"MSG",C0CIEN,"TO NAME",n)=Names or EMAIL Address
|
---|
| 38 | ; (BNAM,"MSG",C0CIEN,"TITLE")=EMAIL Title
|
---|
| 39 | ; (BNAM,"MSG",C0CIEN[for File 3.9])=Number of Attachments
|
---|
| 40 | ; (BNAM,"MSG",C0CIEN,num,"CONT") = Free Text
|
---|
| 41 | ; (BNAM,"MSG",C0CIEN,num,"LINES") = Number of Lines of Text
|
---|
| 42 | ; (BNAM,"MSG",C0CIEN,num,"SIZE") = Size of the Message in Bytes
|
---|
| 43 | ; (BNAM,"MSG",C0CIEN,num,"TXT",LINE#) = Message Data (No Attachment)
|
---|
| 44 | ; (BNAM,"MSG",C0CIEN,"SEG",NUM) = First Line^Last Line
|
---|
| 45 | ; (BNAM,"MSG",C0CIEN,"SEG",NUM,"CONT",type) = Message Details
|
---|
| 46 | ; (BNAM,"MSG",C0CIEN,"SEG",NUM,LINE#) = Message Data
|
---|
| 47 | ;
|
---|
| 48 | ; DO DETAIL^C0CMAIL(.OUTBF,D0) ; For each Email Message and Attachments
|
---|
| 49 | ; Input;
|
---|
| 50 | ; D0 - The IEN for the message in file 3.9, MESSAGE global
|
---|
| 51 | ; Output
|
---|
| 52 | ; OUTBF - The array of your choice to save the expanded and decoded message.
|
---|
| 53 | ;
|
---|
| 54 | GETMSG(C0CDATA,C0CINPUT) ; Common Entry Point for Mailbox Data
|
---|
| 55 | K:'$G(C0CDATA("KEEP")) C0CDATA
|
---|
| 56 | N U
|
---|
| 57 | S U="^"
|
---|
| 58 | D:$G(C0CINPUT)
|
---|
| 59 | . N BF,DUZ,I,INPUT,J,L,LST,MBLST,MALL
|
---|
| 60 | . S INPUT=C0CINPUT
|
---|
| 61 | . S DUZ=+INPUT
|
---|
| 62 | . I $D(^VA(200,DUZ))=0!('$D(^VA(200,DUZ,0))) D ERROR("ER06") Q
|
---|
| 63 | . ;
|
---|
| 64 | . D:$D(^XMB(3.7,DUZ,0))#2
|
---|
| 65 | . . S MBLST=$P(INPUT,";",2)
|
---|
| 66 | . . S MALL=$P(INPUT,";",3) ; New or All Mail Flag
|
---|
| 67 | . . S:MALL["*" MALL=99999
|
---|
| 68 | . . ; Only one of these can be correct
|
---|
| 69 | . . D
|
---|
| 70 | . . . ; If nul, make it "IN" only
|
---|
| 71 | . . . I MBLST="" D QUIT
|
---|
| 72 | . . . . S MBLST("IN")=0,I=0
|
---|
| 73 | . . . . D GATHER(DUZ,"IN",.LST)
|
---|
| 74 | . . . .QUIT
|
---|
| 75 | . . . ;
|
---|
| 76 | . . . ; If "*", Get all Mailboxes and look for New Messages
|
---|
| 77 | . . . I MBLST["*" D QUIT
|
---|
| 78 | . . . . N NAM,NUM
|
---|
| 79 | . . . . S NUM=0
|
---|
| 80 | . . . . F S NUM=$O(^XMB(3.7,DUZ,2,NUM)) Q:'NUM D
|
---|
| 81 | . . . . . S NAM=$P(^XMB(3.7,DUZ,2,NUM,0),U)
|
---|
| 82 | . . . . . D GATHER(DUZ,NAM,.LST)
|
---|
| 83 | . . . . .QUIT
|
---|
| 84 | . . . .QUIT
|
---|
| 85 | . . . ;
|
---|
| 86 | . . . ; If comma separated, look for mailboxes with new messages
|
---|
| 87 | . . . I $L(MBLST,",")>1 D QUIT
|
---|
| 88 | . . . . S NAM=""
|
---|
| 89 | . . . . N TN,V
|
---|
| 90 | . . . . F TN=1:1:$L(MBLST,",") S V=$P(MBLST,",",TN) D
|
---|
| 91 | . . . . . I $L(V) D QUIT
|
---|
| 92 | . . . . . . I V S NAM=$P($G(^XMB(3.7,DUZ,2,V,0)),U)
|
---|
| 93 | . . . . . . S:NAM="" NAM=V
|
---|
| 94 | . . . . . . D GATHER(DUZ,NAM,.LST)
|
---|
| 95 | . . . . . .QUIT
|
---|
| 96 | . . . . . ;
|
---|
| 97 | . . . . . D ERROR("ER08")
|
---|
| 98 | . . . . .QUIT
|
---|
| 99 | . . . .QUIT
|
---|
| 100 | . . . ;
|
---|
| 101 | . . . ; If only 1 mailbox named, go get it
|
---|
| 102 | . . . I $L(MBLST) D QUIT
|
---|
| 103 | . . . . I $D(^XMB(3.7,DUZ,2,"B",MBLST)) D GATHER(DUZ,MBLST,.LST) QUIT
|
---|
| 104 | . . . . ;
|
---|
| 105 | . . . . D ERROR("ER07")
|
---|
| 106 | . . .QUIT
|
---|
| 107 | . . MERGE C0CDATA=LST
|
---|
| 108 | . .QUIT
|
---|
| 109 | .QUIT
|
---|
| 110 | QUIT
|
---|
| 111 | ; ===================
|
---|
| 112 | GATHER(DUZ,NAM,LST) ; Gather Data about the Baskets and their mail
|
---|
| 113 | N I,J,K,L
|
---|
| 114 | S (I,K)=0
|
---|
| 115 | S J=$O(^XMB(3.7,DUZ,2,"B",NAM,""))
|
---|
| 116 | F S I=$O(^XMB(3.7,DUZ,2,J,1,I)) Q:'I D
|
---|
| 117 | . S L=$P(^XMB(3.7,DUZ,2,J,1,I,0),U,3)
|
---|
| 118 | . D ; :L
|
---|
| 119 | . . S:L K=K+1,LST(NAM,"MSG",I,"NEW")="" ; Flag NEW emails
|
---|
| 120 | . . S LST(NAM,"MSG",I)=L
|
---|
| 121 | . . D GETTYP(I)
|
---|
| 122 | . .QUIT
|
---|
| 123 | .QUIT
|
---|
| 124 | S LST(NAM,"NUMBER")=K
|
---|
| 125 | QUIT
|
---|
| 126 | ; ===================
|
---|
| 127 | ; D0 is the IEN into the Message Global ^XMB(3.9,D0)
|
---|
| 128 | ; The products of these emails are scanned to identify
|
---|
| 129 | ; the number of documents stored in the MIME package.
|
---|
| 130 | ; The protocol runs like this;
|
---|
| 131 | ; Line 1 is the --separator
|
---|
| 132 | ; Line 2 thru n >Look for Content-[detail type:]Description ; Next CMD
|
---|
| 133 | ; Line n+2 thru t-1 where t does NOT have "Content-"
|
---|
| 134 | ; Line t is Next Section Terminator, or Message Terminator, --separator
|
---|
| 135 | ; Line t+1 should not exist in the data set if Message Terminator
|
---|
| 136 | ; CON = "Content-"
|
---|
| 137 | ; FLG = "--"
|
---|
| 138 | ; SEP = FLG+7 or more characters ; Separator
|
---|
| 139 | ; END = SEP+FLG
|
---|
| 140 | ; SGC = Segment Count
|
---|
| 141 | ; Note: separator is a string of specific characters of
|
---|
| 142 | ; indeterminate length
|
---|
| 143 | ; LST() the transfer array
|
---|
| 144 | ; LST(NAM,"MSG",C0CIEN,"SEG",SGN)=Starting Line^Ending Line
|
---|
| 145 | ; LST(NAM,"MSG",C0CIEN,"SEG",SGN,1:n)=Decoded Message Data
|
---|
| 146 | ;
|
---|
| 147 | GETTYP(D0) ; Look for the goodies in the Mail
|
---|
| 148 | N I,J,N,BCN,CON,CNT,D1,END,FLG,SEP,SGC,XX,XXNM
|
---|
| 149 | S CON="Content-"
|
---|
| 150 | S FLG="--"
|
---|
| 151 | S SEP="" ; Start SEP as null, so we can use this to help identify the type
|
---|
| 152 | S (BCN,CNT,D1,END,SGC)=0
|
---|
| 153 | S XX=$G(^XMB(3.9,D0,0))
|
---|
| 154 | S LST(NAM,"MSG",D0,"TITLE")=$P($G(^XMB(3.9,D0,0)),U,1)
|
---|
| 155 | S LST(NAM,"MSG",D0,"CREATED")=$G(^XMB(3.9,D0,.6))
|
---|
| 156 | F I=4,2 S XXNM=$P(XX,U,I) Q:$L(XXNM)
|
---|
| 157 | S LST(NAM,"MSG",D0,"FROM")=$$NAME(XXNM)
|
---|
| 158 | S LST(NAM,"MSG",D0,"SENT")=$$TIME($P(XX,U,3))
|
---|
| 159 | ; Get the folks the email is sent to.
|
---|
| 160 | S D1=0
|
---|
| 161 | F S D1=$O(^XMB(3.9,D0,1,D1)) Q:'D1 D
|
---|
| 162 | . N T
|
---|
| 163 | . S T=+$G(^XMB(3.9,D0,1,D1,0))
|
---|
| 164 | . S:T T=$P($G(^VA(200,+T,0)),"^")
|
---|
| 165 | . S LST("TO",D1)=T
|
---|
| 166 | . S T=$G(^XMB(3.9,D0,6,D1,0))
|
---|
| 167 | . S:T T=$P($G(^VA(200,+T,0)),"^")
|
---|
| 168 | . S:T="" T="<Unknown>"
|
---|
| 169 | . S LST("TO NAME",D1)=T
|
---|
| 170 | .QUIT
|
---|
| 171 | ; Preload first Segment (0) with beginning on Line 1
|
---|
| 172 | ; if not a 64bit
|
---|
| 173 | S LST(NAM,"MSG",D0,"SEG",0)=1
|
---|
| 174 | S D1=.9999,SEP="@@"
|
---|
| 175 | F S D1=$O(^XMB(3.9,D0,2,D1)) Q:'D1 D
|
---|
| 176 | . ; Clear any control characters (cr/lf/ff) off
|
---|
| 177 | . S X=$TR($G(^XMB(3.9,D0,2,D1,0)),$C(10,12,13))
|
---|
| 178 | . ; Enter once to set the SEP to capture the separator
|
---|
| 179 | . I SEP=FLG&($E(X,1,2)=FLG)&($L(X,FLG)=2)&($L($P(X,FLG,2)>5)) D Q
|
---|
| 180 | . . S SEP=X,END=X_FLG
|
---|
| 181 | . . S (CNT,SGC)=1,BCN=0
|
---|
| 182 | . . S LST(NAM,"MSG",D0,"SEG",SGC)=D1
|
---|
| 183 | . .QUIT
|
---|
| 184 | . ;
|
---|
| 185 | . ; A new separator is set, process original
|
---|
| 186 | . I X=SEP D QUIT
|
---|
| 187 | . . S LST(NAM,"MSG",D0,SGC,"SIZE")=BCN+$L(BF)
|
---|
| 188 | . . S LST(NAM,"MSG",D0,"SEG",SGC)=$G(LST(NAM,"MSG",D0,"SEG",SGC))_"^"_(D1-1)
|
---|
| 189 | . . S SGC=SGC+1,BCN=0
|
---|
| 190 | . . S LST(NAM,"MSG",D0,"SEG",SGC)=D1
|
---|
| 191 | . .QUIT
|
---|
| 192 | . ;
|
---|
| 193 | . S BCN=BCN+$L(X)
|
---|
| 194 | . I X[CON D Q
|
---|
| 195 | . . S J=$P($P(X,";"),CON,2)
|
---|
| 196 | . . S LST(NAM,"MSG",D0,"SEG",SGC,"CONT",CNT,$P(J,":"))=$P(J,":",2)
|
---|
| 197 | . .QUIT
|
---|
| 198 | . ;
|
---|
| 199 | . ; S LST(NAM,"MSG",D0,"SEG",D1)=X
|
---|
| 200 | .QUIT
|
---|
| 201 | QUIT
|
---|
| 202 | ; ===================
|
---|
| 203 | NAME(NM) ; Return the name of the Sender
|
---|
| 204 | N NAME
|
---|
| 205 | S NAME="<Unknown Sender>"
|
---|
| 206 | D
|
---|
| 207 | . ; Look first for a value to use with the NEW PERSON file
|
---|
| 208 | . ;
|
---|
| 209 | . I NM=+NM S NAME=$P(^VA(200,NM,0),U,1) Q
|
---|
| 210 | . ;
|
---|
| 211 | . I $L(NM) S NAME=NM Q
|
---|
| 212 | . ;
|
---|
| 213 | . ; Else, pull the data from the message and display the foreign source
|
---|
| 214 | . ; of the message.
|
---|
| 215 | . N T
|
---|
| 216 | . S VAL=$G(^XMB(3.9,D0,.7))
|
---|
| 217 | . S:VAL T=$P(^VA(200,VAL,0),U)
|
---|
| 218 | . I $L($G(T)) S NAME=T Q
|
---|
| 219 | . ;
|
---|
| 220 | .QUIT
|
---|
| 221 | QUIT NAME
|
---|
| 222 | ; ===================
|
---|
| 223 | TIME(Y) ; The time and date of the sending
|
---|
| 224 | X ^DD("DD")
|
---|
| 225 | QUIT Y
|
---|
| 226 | ; ===================
|
---|
| 227 | ; Segments in Message need to be identified and decoded properly
|
---|
| 228 | ; D DETAIL^C0CMAIL(.ARRAY,D0) ; Call One for each message
|
---|
| 229 | ; ARRAY will have the details of this one call
|
---|
| 230 | ;
|
---|
| 231 | ; Inputs;
|
---|
| 232 | ; C0CINPUT - The IEN of the message to expand
|
---|
| 233 | ; Outputs;
|
---|
| 234 | ; C0CDATA - Carrier for the returned structure of the Message
|
---|
| 235 | ; C0CDATA(D0,"SEG")=number of SEGMENTS
|
---|
| 236 | ; C0CDATA(D0,"SEG",0:n)=SEGMENT n details; First;Last;Type
|
---|
| 237 | ; C0CDATA(D0,"SEG",0:n,"CONTENT",type)=Content details
|
---|
| 238 | ; C0CDATA(D0,"SEG",0:n,"MSG",D3)=Content details
|
---|
| 239 | ; C0CDATA(D0,"SEG",0:n,"HTML",D3)=Content details
|
---|
| 240 | ;
|
---|
| 241 | DETAIL(C0CDATA,C0CINPUT) ; Message Detail Delivery
|
---|
| 242 | N LST,D0,D1,U
|
---|
| 243 | S U="^"
|
---|
| 244 | S D0=+$G(C0CINPUT)
|
---|
| 245 | I D0 D QUIT
|
---|
| 246 | . I $D(^XMB(3.9,D0))<10 D ERROR("ER01") QUIT
|
---|
| 247 | . ;
|
---|
| 248 | . D GETTYP2(D0)
|
---|
| 249 | . I $D(LST) M C0CDATA(D0)=LST Q
|
---|
| 250 | . ;
|
---|
| 251 | . D ERROR("ER02")
|
---|
| 252 | .QUIT
|
---|
| 253 | QUIT
|
---|
| 254 | ; ===================
|
---|
| 255 | ; End note if needed
|
---|
| 256 | ; MSK - Set of characters that do not exist in 64 bit encoding
|
---|
| 257 | GETTYP2(D0) ; Try to get the types and MSK for the
|
---|
| 258 | N I,J,K,N,BCN,BF,CON,CNT,D1,END,FLG,MSK,SEP,SGC,U,XX,ZN,XXNM
|
---|
| 259 | S CON="Content-",U="^"
|
---|
| 260 | S FLG="--"
|
---|
| 261 | S MSK=" !""#$%&'()*,-.:;<>?@[\]^_`{|}~"
|
---|
| 262 | S (BF,SEP)="" ; Start SEP as null, so we can use this to help identify the type
|
---|
| 263 | S (BCN,CNT,D1,END,SGC)=0
|
---|
| 264 | S XX=$G(^XMB(3.9,D0,0))
|
---|
| 265 | ; S K=$P(^XMB(3.9,D0,2,0),U,3)
|
---|
| 266 | S LST("TITLE")=$P($G(^XMB(3.9,D0,0)),U,1)
|
---|
| 267 | S LST("CREATED")=$$TIME($P(XX,U,3))
|
---|
| 268 | F I=4,2 S XXNM=$P(XX,U,I) Q:$L(XXNM)
|
---|
| 269 | S LST("FROM")=$$NAME(XXNM)
|
---|
| 270 | ; Get the folks the email is sent to.
|
---|
| 271 | S D1=0
|
---|
| 272 | F S D1=$O(^XMB(3.9,D0,1,D1)) Q:'D1 D Q:D1=""
|
---|
| 273 | . N I,T
|
---|
| 274 | . S T=$P($G(^XMB(3.9,D0,1,D1,0)),U)
|
---|
| 275 | . S:T T=$P($G(^VA(200,T,0)),"^")
|
---|
| 276 | . S LST("TO",+D1)=T
|
---|
| 277 | . S T=$G(^XMB(3.9,D0,6,+D1,0))
|
---|
| 278 | . S:T="" T=$P($G(^VA(200,+T,0)),"^")
|
---|
| 279 | . S:T="" T="<Unknown>"
|
---|
| 280 | . S LST("TO NAME",D1)=T
|
---|
| 281 | .QUIT
|
---|
| 282 | ; Get the Header for the message
|
---|
| 283 | S D1=0
|
---|
| 284 | F I=1:1 S D1=$O(^XMB(3.9,D0,2,D1)) Q:D1="" Q:(D1>.99999) D
|
---|
| 285 | . S LST("HDR",I)=$G(^XMB(3.9,D0,2,D1,0))
|
---|
| 286 | .QUIT
|
---|
| 287 | ; Start walking the different sections
|
---|
| 288 | S D1=.99999,SEP="@@",SGC=0
|
---|
| 289 | F S D1=$O(^XMB(3.9,D0,2,D1)) Q:'D1 D
|
---|
| 290 | . ; Clear any control characters (cr/lf/ff) off
|
---|
| 291 | . S X=$TR($G(^XMB(3.9,D0,2,D1,0)),$C(10,12,13))
|
---|
| 292 | . ; Enter once to set the SEP to capture the separator
|
---|
| 293 | . I (SEP="@@")&(X?2."--"5.AN.E) D Q
|
---|
| 294 | . . I $L(X,FLG)>2 D ERROR("ER10")
|
---|
| 295 | . . S SEP=X,END=X_FLG
|
---|
| 296 | . . S (CNT,SGC)=1,BCN=0
|
---|
| 297 | . . S LST("SEG",SGC)=D1
|
---|
| 298 | . .QUIT
|
---|
| 299 | . ;
|
---|
| 300 | . ; A new SEGMENT separator is set, process original
|
---|
| 301 | . I X=SEP D QUIT
|
---|
| 302 | . . ; Save Current Values
|
---|
| 303 | . . S LST("SEG",SGC,"SIZE")=BCN+$L(BF)
|
---|
| 304 | . . ; Close this Segment and prepare to start a New Segment
|
---|
| 305 | . . S $P(LST("SEG",SGC),"^",1,2)=$P($G(LST("SEG",SGC)),"^",1)_"^"_(D1-1)
|
---|
| 306 | . . ; Put the result in LST("SEG",SGC,"XML")
|
---|
| 307 | . . I $L(BF) D
|
---|
| 308 | . . . S ZN=1
|
---|
| 309 | . . . N I,T,TBF
|
---|
| 310 | . . . S TBF=BF
|
---|
| 311 | . . . F I=1:1:($L(TBF,"=")) D
|
---|
| 312 | . . . . S BF=$P(TBF,"=",I)_"="
|
---|
| 313 | . . . . I BF'="=" D DECODER
|
---|
| 314 | . . . .QUIT
|
---|
| 315 | . . . S BF=""
|
---|
| 316 | . . .QUIT
|
---|
| 317 | . . S SGC=SGC+1,BCN=0
|
---|
| 318 | . . ; Incriment SGC to start a new Segment
|
---|
| 319 | . . S LST("SEG",SGC)=D1
|
---|
| 320 | . .QUIT
|
---|
| 321 | . ;
|
---|
| 322 | . ; Accumulate the 64 bit encoding
|
---|
| 323 | . I X=$TR(X,MSK)&$L(X) S BF=BF_X QUIT
|
---|
| 324 | . ;
|
---|
| 325 | . ; Ending Condition, close out the Segment
|
---|
| 326 | . I X=END D QUIT
|
---|
| 327 | . . S LST("SEG",SGC)=$G(LST("SEG",SGC))_"^"_(D1-1)
|
---|
| 328 | . . I $L(BF) S ZN=1 D DECODER S BF="" Q
|
---|
| 329 | . .QUIT
|
---|
| 330 | . ;
|
---|
| 331 | . ; Accumulate the lengths of other lines of the message
|
---|
| 332 | . S BCN=BCN+$L(X)
|
---|
| 333 | . ; Split out the Content Info
|
---|
| 334 | . I X[CON D Q
|
---|
| 335 | . . S J=$P(X,CON,2)
|
---|
| 336 | . . I J[" boundary=" D
|
---|
| 337 | . . . S SEP=$P($P(J," boundary=",2),"""",2),END=SEP_FLG
|
---|
| 338 | . . . Q:SEP?2"-"5.ANP
|
---|
| 339 | . . . ;
|
---|
| 340 | . . . D ERROR("ER11")
|
---|
| 341 | . . . Q:SEP'[" "
|
---|
| 342 | . . . ;
|
---|
| 343 | . . . D ERROR("ER12")
|
---|
| 344 | . . .QUIT
|
---|
| 345 | . . S LST("SEG",SGC,"CONTENT",$P(J,":"))=$P(J,":",2,9)
|
---|
| 346 | . .QUIT
|
---|
| 347 | . ;
|
---|
| 348 | . ; Everything else is Text, Check for CCR/CCD.
|
---|
| 349 | . N KK,UBF
|
---|
| 350 | . D
|
---|
| 351 | . . S UBF=$$UPPER(X)
|
---|
| 352 | . . I UBF["<CONTINUITYOFCARERECORD" S $P(LST("SEG",SGC),U,3)="CCR" Q
|
---|
| 353 | . . ;
|
---|
| 354 | . . I UBF["<CLINICALDOCUMENT" S $P(LST("SEG",SGC),U,3)="CCD" Q
|
---|
| 355 | . .QUIT
|
---|
| 356 | . ; Look for directives in the text before it gets published
|
---|
| 357 | . ; Look for "=3D" and replace it with a single "=". I can do more parsing
|
---|
| 358 | . ; but there may be situations where the line has been wrapped.
|
---|
| 359 | . D:X["=3D"
|
---|
| 360 | . . F KK=1:1 S X=$P(X,"=3D",1)_"="_$P(X,"=3D",2,999) Q:X'["=3D"
|
---|
| 361 | . .QUIT
|
---|
| 362 | . S LST("SEG",SGC,"TXT",D1)=X
|
---|
| 363 | .QUIT
|
---|
| 364 | QUIT
|
---|
| 365 | ; ===================
|
---|
| 366 | ; Break down the Buffer Array so it can be saved.
|
---|
| 367 | ; BF is passed in.
|
---|
| 368 | DECODER ;
|
---|
| 369 | N RCNT,TBF,UBF,ZBF,ZI,ZJ,ZK,ZSIZE
|
---|
| 370 | S ZBF=BF
|
---|
| 371 | ; Full Buffer, BF, now check for Encryption and Unpack
|
---|
| 372 | F RCNT=1:1:$L(ZBF,"=") D
|
---|
| 373 | . N BF
|
---|
| 374 | . S BF=$P(ZBF,"=",RCNT)
|
---|
| 375 | . ; Unpacking the 64 bit encoding
|
---|
| 376 | . S TBF=$TR($$DECODE^RGUTUU(BF),$C(10,12,13))
|
---|
| 377 | . D:$L(TBF)
|
---|
| 378 | . . N C,OK,OKCNT,KK,XBF,UBF
|
---|
| 379 | . . D
|
---|
| 380 | . . . S UBF=$$UPPER(TBF)
|
---|
| 381 | . . . I UBF["<CONTINUITYOFCARERECORD XMLNS=" S $P(LST("SEG",SGC),U,3)="CCR" Q
|
---|
| 382 | . . . ;
|
---|
| 383 | . . . I UBF["<CLINICALDOCUMENT XMLNS=" S $P(LST("SEG",SGC),U,3)="CCD" Q
|
---|
| 384 | . . .QUIT
|
---|
| 385 | . . ; Check for Bad Signature Decoding, after 100 bad characters
|
---|
| 386 | . . S OK=1,OKCNT=0
|
---|
| 387 | . . F KK=1:1:$L(UBF) S C=$A(UBF,KK) S:C>126 OKCNT=OKCNT+1 I OKCNT>100 S OK=0 Q
|
---|
| 388 | . . ;
|
---|
| 389 | . . D
|
---|
| 390 | . . . I 'OK S (BF,UBF,TBF,XBF)="<Crypto-Signature redacted>" Q
|
---|
| 391 | . . . ;
|
---|
| 392 | . . . S BF=BF_"="
|
---|
| 393 | . . . D NORMAL(.XBF,.TBF)
|
---|
| 394 | . . .QUIT
|
---|
| 395 | . . M LST("SEG",SGC,"XML",RCNT)=XBF
|
---|
| 396 | . .QUIT
|
---|
| 397 | .QUIT
|
---|
| 398 | QUIT
|
---|
| 399 | ; ===================
|
---|
| 400 | ; OUTXML = OUTBF = OUT = OUTPUT ARRAY TO BE BUILT
|
---|
| 401 | ; BF = INXML = INPUT ARRAY TO PROVIDE INPUT
|
---|
| 402 | ; >D NORMAL^C0CMAIL(.OUT,BF)
|
---|
| 403 | NORMAL(OUTXML,INXML) ;NORMALIZES AN XML STRING PASSED BY NAME IN INXML
|
---|
| 404 | ; INTO AN XML ARRAY RETURNED IN OUTXML, ALSO PASSED BY NAME
|
---|
| 405 | ;
|
---|
| 406 | N ZN,OUTBF,XX,ZSEP
|
---|
| 407 | S INXML=$TR(INXML,$C(10,12,13))
|
---|
| 408 | S ZN=1,ZSEP=">"
|
---|
| 409 | S OUTBF(1)=$P(INXML,"><",1)_ZSEP,XX="<"_$P(INXML,"><",2)_ZSEP,ZN=2,ZL=1
|
---|
| 410 | F ZN=ZN+1:1:$L(INXML,"><") D Q:XX=""
|
---|
| 411 | . S XX=$P(INXML,"><",ZN)
|
---|
| 412 | . S:$E($RE(XX))=">" ZSEP=""
|
---|
| 413 | . Q:XX=""
|
---|
| 414 | . ;
|
---|
| 415 | . S XX="<"_XX_ZSEP
|
---|
| 416 | . D
|
---|
| 417 | . . I $L(XX)<4000 S OUTBF(ZL)=XX,XX=$P(INXML,"><",ZN),ZL=ZL+1 Q
|
---|
| 418 | . . ;
|
---|
| 419 | . . D ERROR("ER05")
|
---|
| 420 | . . F ZL=ZL+1:1 D Q:XX=""
|
---|
| 421 | . . . N XL
|
---|
| 422 | . . . S XL=$E(XX,1,4000)
|
---|
| 423 | . . . S $E(XX,1,4000)="" ; S XX=$E(XX,4001,999999) ; Remove 4K characters
|
---|
| 424 | . . . S OUTBF(ZL)=XL
|
---|
| 425 | . . .QUIT
|
---|
| 426 | . .QUIT
|
---|
| 427 | .QUIT
|
---|
| 428 | M OUTXML=OUTBF
|
---|
| 429 | QUIT
|
---|
| 430 | ; ===================
|
---|
| 431 | UPPER(X) ; Convert any lowercase letters to Uppercase letters
|
---|
| 432 | QUIT $TR(X,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
---|
| 433 | ; ===================
|
---|
| 434 | ; EN is a counter that remains between error events
|
---|
| 435 | ERROR(ER) ; Error Handler
|
---|
| 436 | N TXXQ,XXXQ
|
---|
| 437 | S XXXQ="Unknown Error Encountered = "_ER
|
---|
| 438 | S TXXQ=$P($T(@(ER_"^"_$T(+0))),";;",2,99)
|
---|
| 439 | I TXXQ'="" D
|
---|
| 440 | . I TXXQ["_" X "S TXXQ="_TXXQ
|
---|
| 441 | . S XXXQ=TXXQ
|
---|
| 442 | .QUIT
|
---|
| 443 | S EN(ER)=$G(EN(ER))+1
|
---|
| 444 | S LST("ERR",ER,EN(ER))=XXXQ
|
---|
| 445 | QUIT
|
---|
| 446 | ; ===================
|
---|
| 447 | ER01 ;;Message Missing
|
---|
| 448 | ER02 ;;Message Text Missing
|
---|
| 449 | ER03 ;;Message Not Identifiable
|
---|
| 450 | ER04 ;;Segment is too large
|
---|
| 451 | ER05 ;;Mailbox Missing
|
---|
| 452 | ER06 ;;"User Missing = "_$G(DUZ)
|
---|
| 453 | ER07 ;;"Bad DUZ = "_DUZ
|
---|
| 454 | ER08 ;;"Bad Basket ID = "_MBLST_" >> "_$G(TN)
|
---|
| 455 | ER10 ;;"Bad Separator found = "_X
|
---|
| 456 | ER11 ;;"Non-Standard Separator Found:>"_$G(J)
|
---|
| 457 | ER12 ;;"Spaces are not allowed in Separators:>"_$G(J)
|
---|
| 458 | ; vvvvvvvvvvvvvvv Not Needed vvvvvvvvvvvvvvvvvvvvvvvvvv
|
---|
| 459 | ; End note if needed
|
---|
| 460 | QUIT
|
---|
| 461 | ; ===================
|
---|