HDISVAP1 ;BPFO/JRP - Application Programmer API(s);03/07/12  07:37
 ;;1.0;HEALTH DATA & INFORMATICS;**7**;Feb 22, 2005;Build 33
 ;
LABXCPT(ARRAY,TASKIT) ;Transmit Lab SNOMED CT exceptions
 ; Input: ARRAY - Array containing information about the exception
 ;              (FULL GLOBAL REFERENCE)
 ;          @ARRAY@(ETC, n) = Transaction number ^ Time stamp
 ;          @ARRAY@(ETC, n, [x, y, ...]) = Exception specific nodes
 ;
 ;            ETC is a code denoting the type of exception to report
 ;              1 = Load Exception
 ;              2 = Reference Lab
 ;              3 = Add/Edit by Site
 ;
 ;            Time Stamp is in FileMan format
 ;        TASKIT - Flag denoting if the work this API does should
 ;                 be queued to run
 ;                   1 = Queue to run
 ;                   0 = Run now (DEFAULT)
 ;
 ;Output: None
 ;      : The node @ARRAY@("XMZ") will be set equal to the message
 ;        number of the generated message.  A value of zero (0) will
 ;        be used when the message could not be generated.
 ;      : The node @ARRAY@("ZTSK") will be set equal to the task number
 ;        assigned if the TASKIT variable is set to one (1).  A value
 ;        of zero (0) will be used if queuing of this API's work was
 ;        not requested.
 ;      : The node @ARRAY@("ERROR", ETC) will be set equal to error
 ;        text for input exception type codes that are not supported.
 ;      : The node @ARRAY@("ERROR", ETC, n) will be set to error
 ;        text if the exception could not be handled.  This is
 ;        typically set because of a missing input node.  This node
 ;        will not be set for unsupported exception type codes.
 ;
 ; Notes: If this is not a production system the generated message
 ;        will be sent to the currently defined user (i.e. DUZ)
 ;      : The node @ARRAY@("ERROR") will be KILLed on input
 ;      : A pipe (|) is used as the delimiter for the "SA" and "SB"
 ;        nodes.  This is because they mirror the layout of the SNOMED
 ;        CT extract already implemented by the Lab package.
 ;      : A pipe (|) is used as the delimiter for the "RD" node.  This
 ;        is because it mirrors the layout of the resolution data being
 ;        transmitted by ERT to the Lab package for loading.
 ;      : The following text lists the nodes for each exception type
 ;
 ;   Exception Type Code 1: Load Exception
 ;   =====================================
 ;   @ARRAY@(1, n) = Transaction number ^ Time stamp
 ;   @ARRAY@(1, n, "TXT") = Text to describe why the exception was
 ;                          generated.  Contents is up to the
 ;                          discretion of the Lab package.
 ;   @ARRAY@(1, n, "SA") = The pipe delimited row of data for the
 ;                         entry that would be generated by the LR
 ;                         LAB SERVER when fulfilling a SNOMED extract
 ;                         report
 ;   @ARRAY@(1, n, "RD") = The pipe delimited row of data received
 ;                         from STS that the Lab package attempted
 ;                         to load
 ;
 ;   Exception Type Code 2: Reference Lab
 ;   ====================================
 ;   @ARRAY@(2, n) = Transaction number ^ Time stamp
 ;   @ARRAY@(2, n, "TXT") = Text to describe why the exception was
 ;                          generated.  Contents is up to the
 ;                          discretion of the Lab package.
 ;   @ARRAY@(2, n, "SA") = The pipe delimited row of data for the
 ;                         entry that would be generated by the LR
 ;                         LAB SERVER when fulfilling a SNOMED extract
 ;                         report
 ;   @ARRAY@(2, n, "RL") = Location type code ^ Location number ^
 ;                         Location name
 ;   @ARRAY@(2, n, "EC") = Encoding characters from HL-7 message
 ;   @ARRAY@(2, n, "OBX", 3) = Sequence 3 of received OBX segment
 ;   @ARRAY@(2, n, "OBX", 5) = Sequence 5 of received OBX segment
 ;
 ;     Location Type Code:
 ;       1 = DoD              4 = IHS 
 ;       2 = VA               5 = Other 
 ;       3 = Non-government   6 = Unknown
 ;
 ;   Exception Type Code 3: Add/Edit by Site
 ;   =======================================
 ;   @ARRAY@(3, n) = Transaction number ^ Time stamp
 ;   @ARRAY@(3, n, "TXT") = Text to describe why the exception was
 ;                          generated.  Contents is up to the
 ;                          discretion of the Lab package.
 ;   @ARRAY@(3, n, "SA") = The pipe delimited row of data for the
 ;                         entry that would be generated by the LR
 ;                         LAB SERVER when fulfilling a SNOMED extract
 ;                         report
 ;   @ARRAY@(3, n, "SB") = Same definition as the SA node except the
 ;                         values prior to the add/edit are used.
 ;                         Node not present for additions.
 ;
 ;
 ;   Alternate Array Format
 ;   ======================
 ;   Array nodes that are delimited pieces of data can also be broken
 ;   out into their individual pieces of data.  The only node that
 ;   CAN NOT be broken out in this manner is the main node for the
 ;   exception.
 ;   
 ;   Using exception type code 1 (Load Exception) as an example, the
 ;   alternate array format would be:
 ;
 ;     @ARRAY@(1, n) = Transaction number ^ Time stamp
 ;     @ARRAY@(1, n, "TXT") = Some kind of text
 ;     @ARRAY@(1, n, "SA", 1..N) = Piece N of the SA node
 ;     @ARRAY@(1, n, "RD", 1..N) = Piece N of the RD node
 ;
 ;   Note that the primary and alternate formats can not be used at
 ;   the same time for the same node.  If this is done, the data will
 ;   be ignored and the error node for the exception will be set.
 ;
 ;Initialize XMZ & ZTSK output nodes
 SET @ARRAY@("XMZ")=0
 SET @ARRAY@("ZTSK")=0
 SET TASKIT=+$GET(TASKIT)
 ;Queue running ?
 IF TASKIT DO  QUIT
 .;API asked to queue it's running
 .NEW ZTRTN,ZTDESC,ZTDTH,ZTIO,ZTSAVE,ZTSK,TMP
 .SET ZTRTN="TASKIT^HDISVAP1"
 .SET ZTDESC="Transmit Lab SNOMED CT exceptions"
 .SET ZTDTH=$HOROLOG
 .SET ZTIO=""
 .SET ZTSAVE("TASKIT")=1
 .KILL ^TMP("HDISVAP1-TASK",$JOB)
 .MERGE ^TMP("HDISVAP1-TASK",$JOB)=@ARRAY
 .SET ZTSAVE("ARRAY")="^TMP(""HDISVAP1-TASK"",$JOB)"
 .SET ZTSAVE("^TMP(""HDISVAP1-TASK"",$JOB,")=""
 .DO ^%ZTLOAD
 .KILL ^TMP("HDISVAP1-TASK",$JOB)
 .SET @ARRAY@("ZTSK")=$GET(ZTSK)
 .QUIT
TASKIT ;Entry point used when API is asked to queue itself
 NEW XMLDOC,SUMTXT,ENCODED,LINE,SUBJ,LOOP
 ;Initialize
 SET XMLDOC=$NAME(^TMP("HDISVAP1",$JOB,"XMLDOC"))
 SET SUMTXT=$NAME(^TMP("HDISVAP1",$JOB,"SUMTXT"))
 SET ENCODED=$NAME(^TMP("HDISVAP1",$JOB,"ENCODED"))
 KILL @XMLDOC,@SUMTXT,@ENCODED,@ARRAY@("ERROR")
 ;Build XML document & summary text - quit if nothing to encode/send
 IF ('$$BUILD^HDISVAP2(ARRAY,XMLDOC,SUMTXT)) DO  QUIT
 .KILL @XMLDOC,@SUMTXT,@ENCODED
 .QUIT
 ;UUEncode array containing XML document
 SET @XMLDOC@(0)=$$FILENAME^HDISVAP3()
 DO ENCODE^HDISVM03(XMLDOC,ENCODED,1)
 ;Combine UUEncoded array and summary text
 SET LINE=0
 FOR  SET LINE=+$ORDER(@SUMTXT@(LINE)) QUIT:('LINE)  DO
 .SET @ENCODED@(LINE*.000001)=@SUMTXT@(LINE,0)
 ;Build & send message
 SET SUBJ="Lab Exception(s): "_$GET(@SUMTXT@(0))
 IF ($LENGTH(SUBJ)>64) DO
 .FOR LOOP=$LENGTH(SUBJ,","):-1 DO   QUIT:($LENGTH(SUBJ)<59)
 ..SET SUBJ=$PIECE(SUBJ,",",1,LOOP-1)
 .SET SUBJ=SUBJ_", ..."
 SET @ARRAY@("XMZ")=$$SENDMSG^HDISVAP3(ENCODED,SUBJ)
 ;Clean up
 KILL @XMLDOC,@SUMTXT,@ENCODED
 ;Checked for tasked use
 IF $DATA(ZTQUEUED) DO
 .;Delete task & input/output array
 .SET ZTREQ="@"
 .KILL @ARRAY
 .QUIT
 QUIT
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HHDISVAP1   7697     printed  Sep 23, 2025@19:32:43                                                                                                                                                                                                    Page 2
HDISVAP1  ;BPFO/JRP - Application Programmer API(s);03/07/12  07:37
 +1       ;;1.0;HEALTH DATA & INFORMATICS;**7**;Feb 22, 2005;Build 33
 +2       ;
LABXCPT(ARRAY,TASKIT) ;Transmit Lab SNOMED CT exceptions
 +1       ; Input: ARRAY - Array containing information about the exception
 +2       ;              (FULL GLOBAL REFERENCE)
 +3       ;          @ARRAY@(ETC, n) = Transaction number ^ Time stamp
 +4       ;          @ARRAY@(ETC, n, [x, y, ...]) = Exception specific nodes
 +5       ;
 +6       ;            ETC is a code denoting the type of exception to report
 +7       ;              1 = Load Exception
 +8       ;              2 = Reference Lab
 +9       ;              3 = Add/Edit by Site
 +10      ;
 +11      ;            Time Stamp is in FileMan format
 +12      ;        TASKIT - Flag denoting if the work this API does should
 +13      ;                 be queued to run
 +14      ;                   1 = Queue to run
 +15      ;                   0 = Run now (DEFAULT)
 +16      ;
 +17      ;Output: None
 +18      ;      : The node @ARRAY@("XMZ") will be set equal to the message
 +19      ;        number of the generated message.  A value of zero (0) will
 +20      ;        be used when the message could not be generated.
 +21      ;      : The node @ARRAY@("ZTSK") will be set equal to the task number
 +22      ;        assigned if the TASKIT variable is set to one (1).  A value
 +23      ;        of zero (0) will be used if queuing of this API's work was
 +24      ;        not requested.
 +25      ;      : The node @ARRAY@("ERROR", ETC) will be set equal to error
 +26      ;        text for input exception type codes that are not supported.
 +27      ;      : The node @ARRAY@("ERROR", ETC, n) will be set to error
 +28      ;        text if the exception could not be handled.  This is
 +29      ;        typically set because of a missing input node.  This node
 +30      ;        will not be set for unsupported exception type codes.
 +31      ;
 +32      ; Notes: If this is not a production system the generated message
 +33      ;        will be sent to the currently defined user (i.e. DUZ)
 +34      ;      : The node @ARRAY@("ERROR") will be KILLed on input
 +35      ;      : A pipe (|) is used as the delimiter for the "SA" and "SB"
 +36      ;        nodes.  This is because they mirror the layout of the SNOMED
 +37      ;        CT extract already implemented by the Lab package.
 +38      ;      : A pipe (|) is used as the delimiter for the "RD" node.  This
 +39      ;        is because it mirrors the layout of the resolution data being
 +40      ;        transmitted by ERT to the Lab package for loading.
 +41      ;      : The following text lists the nodes for each exception type
 +42      ;
 +43      ;   Exception Type Code 1: Load Exception
 +44      ;   =====================================
 +45      ;   @ARRAY@(1, n) = Transaction number ^ Time stamp
 +46      ;   @ARRAY@(1, n, "TXT") = Text to describe why the exception was
 +47      ;                          generated.  Contents is up to the
 +48      ;                          discretion of the Lab package.
 +49      ;   @ARRAY@(1, n, "SA") = The pipe delimited row of data for the
 +50      ;                         entry that would be generated by the LR
 +51      ;                         LAB SERVER when fulfilling a SNOMED extract
 +52      ;                         report
 +53      ;   @ARRAY@(1, n, "RD") = The pipe delimited row of data received
 +54      ;                         from STS that the Lab package attempted
 +55      ;                         to load
 +56      ;
 +57      ;   Exception Type Code 2: Reference Lab
 +58      ;   ====================================
 +59      ;   @ARRAY@(2, n) = Transaction number ^ Time stamp
 +60      ;   @ARRAY@(2, n, "TXT") = Text to describe why the exception was
 +61      ;                          generated.  Contents is up to the
 +62      ;                          discretion of the Lab package.
 +63      ;   @ARRAY@(2, n, "SA") = The pipe delimited row of data for the
 +64      ;                         entry that would be generated by the LR
 +65      ;                         LAB SERVER when fulfilling a SNOMED extract
 +66      ;                         report
 +67      ;   @ARRAY@(2, n, "RL") = Location type code ^ Location number ^
 +68      ;                         Location name
 +69      ;   @ARRAY@(2, n, "EC") = Encoding characters from HL-7 message
 +70      ;   @ARRAY@(2, n, "OBX", 3) = Sequence 3 of received OBX segment
 +71      ;   @ARRAY@(2, n, "OBX", 5) = Sequence 5 of received OBX segment
 +72      ;
 +73      ;     Location Type Code:
 +74      ;       1 = DoD              4 = IHS 
 +75      ;       2 = VA               5 = Other 
 +76      ;       3 = Non-government   6 = Unknown
 +77      ;
 +78      ;   Exception Type Code 3: Add/Edit by Site
 +79      ;   =======================================
 +80      ;   @ARRAY@(3, n) = Transaction number ^ Time stamp
 +81      ;   @ARRAY@(3, n, "TXT") = Text to describe why the exception was
 +82      ;                          generated.  Contents is up to the
 +83      ;                          discretion of the Lab package.
 +84      ;   @ARRAY@(3, n, "SA") = The pipe delimited row of data for the
 +85      ;                         entry that would be generated by the LR
 +86      ;                         LAB SERVER when fulfilling a SNOMED extract
 +87      ;                         report
 +88      ;   @ARRAY@(3, n, "SB") = Same definition as the SA node except the
 +89      ;                         values prior to the add/edit are used.
 +90      ;                         Node not present for additions.
 +91      ;
 +92      ;
 +93      ;   Alternate Array Format
 +94      ;   ======================
 +95      ;   Array nodes that are delimited pieces of data can also be broken
 +96      ;   out into their individual pieces of data.  The only node that
 +97      ;   CAN NOT be broken out in this manner is the main node for the
 +98      ;   exception.
 +99      ;   
 +100     ;   Using exception type code 1 (Load Exception) as an example, the
 +101     ;   alternate array format would be:
 +102     ;
 +103     ;     @ARRAY@(1, n) = Transaction number ^ Time stamp
 +104     ;     @ARRAY@(1, n, "TXT") = Some kind of text
 +105     ;     @ARRAY@(1, n, "SA", 1..N) = Piece N of the SA node
 +106     ;     @ARRAY@(1, n, "RD", 1..N) = Piece N of the RD node
 +107     ;
 +108     ;   Note that the primary and alternate formats can not be used at
 +109     ;   the same time for the same node.  If this is done, the data will
 +110     ;   be ignored and the error node for the exception will be set.
 +111     ;
 +112     ;Initialize XMZ & ZTSK output nodes
 +113      SET @ARRAY@("XMZ")=0
 +114      SET @ARRAY@("ZTSK")=0
 +115      SET TASKIT=+$GET(TASKIT)
 +116     ;Queue running ?
 +117      IF TASKIT
               Begin DoDot:1
 +118     ;API asked to queue it's running
 +119              NEW ZTRTN,ZTDESC,ZTDTH,ZTIO,ZTSAVE,ZTSK,TMP
 +120              SET ZTRTN="TASKIT^HDISVAP1"
 +121              SET ZTDESC="Transmit Lab SNOMED CT exceptions"
 +122              SET ZTDTH=$HOROLOG
 +123              SET ZTIO=""
 +124              SET ZTSAVE("TASKIT")=1
 +125              KILL ^TMP("HDISVAP1-TASK",$JOB)
 +126              MERGE ^TMP("HDISVAP1-TASK",$JOB)=@ARRAY
 +127              SET ZTSAVE("ARRAY")="^TMP(""HDISVAP1-TASK"",$JOB)"
 +128              SET ZTSAVE("^TMP(""HDISVAP1-TASK"",$JOB,")=""
 +129              DO ^%ZTLOAD
 +130              KILL ^TMP("HDISVAP1-TASK",$JOB)
 +131              SET @ARRAY@("ZTSK")=$GET(ZTSK)
 +132              QUIT 
               End DoDot:1
               QUIT 
TASKIT    ;Entry point used when API is asked to queue itself
 +1        NEW XMLDOC,SUMTXT,ENCODED,LINE,SUBJ,LOOP
 +2       ;Initialize
 +3        SET XMLDOC=$NAME(^TMP("HDISVAP1",$JOB,"XMLDOC"))
 +4        SET SUMTXT=$NAME(^TMP("HDISVAP1",$JOB,"SUMTXT"))
 +5        SET ENCODED=$NAME(^TMP("HDISVAP1",$JOB,"ENCODED"))
 +6        KILL @XMLDOC,@SUMTXT,@ENCODED,@ARRAY@("ERROR")
 +7       ;Build XML document & summary text - quit if nothing to encode/send
 +8        IF ('$$BUILD^HDISVAP2(ARRAY,XMLDOC,SUMTXT))
               Begin DoDot:1
 +9                KILL @XMLDOC,@SUMTXT,@ENCODED
 +10               QUIT 
               End DoDot:1
               QUIT 
 +11      ;UUEncode array containing XML document
 +12       SET @XMLDOC@(0)=$$FILENAME^HDISVAP3()
 +13       DO ENCODE^HDISVM03(XMLDOC,ENCODED,1)
 +14      ;Combine UUEncoded array and summary text
 +15       SET LINE=0
 +16       FOR 
               SET LINE=+$ORDER(@SUMTXT@(LINE))
               if ('LINE)
                   QUIT 
               Begin DoDot:1
 +17               SET @ENCODED@(LINE*.000001)=@SUMTXT@(LINE,0)
               End DoDot:1
 +18      ;Build & send message
 +19       SET SUBJ="Lab Exception(s): "_$GET(@SUMTXT@(0))
 +20       IF ($LENGTH(SUBJ)>64)
               Begin DoDot:1
 +21               FOR LOOP=$LENGTH(SUBJ,","):-1
                       Begin DoDot:2
 +22                       SET SUBJ=$PIECE(SUBJ,",",1,LOOP-1)
                       End DoDot:2
                       if ($LENGTH(SUBJ)<59)
                           QUIT 
 +23               SET SUBJ=SUBJ_", ..."
               End DoDot:1
 +24       SET @ARRAY@("XMZ")=$$SENDMSG^HDISVAP3(ENCODED,SUBJ)
 +25      ;Clean up
 +26       KILL @XMLDOC,@SUMTXT,@ENCODED
 +27      ;Checked for tasked use
 +28       IF $DATA(ZTQUEUED)
               Begin DoDot:1
 +29      ;Delete task & input/output array
 +30               SET ZTREQ="@"
 +31               KILL @ARRAY
 +32               QUIT 
               End DoDot:1
 +33       QUIT