ONCSED01 ;HINES OIFO/SG - EDITS 'RUN BATCH' REQUEST ; 11/6/06 11:48am
 ;;2.2;ONCOLOGY;**1,16,19,20**;Jul 31, 2013;Build 5
 ;..P19
 ;P16 - hwsc encrytion function
 ;--- SOAP REQUST TO THE ONCOLOGY WEB SERVICE
 ;
 ; <?xml version="1.0" encoding="utf-8"?>
 ; <soap:Envelope
 ;   xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
 ;   soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
 ;   <soap:Body>
 ;     <ED-RUN-BATCH [edits-config="..."] ver="2.0"
 ;       xmlns="http://vista.domain.ext/oncology">
 ;       <NAACCR-RECORD> ... </NAACCR-RECORD>
 ;     </ED-RUN-BATCH>
 ;   </soap:Body >
 ; </soap:Envelope>
 ;
 ;--- ATTRIBUTES
 ;
 ; edits-config  Name of the configuration that should be used by
 ;               the server to validate the data.  By default,
 ;               the "DEFAULT" name is used.
 ;
 Q
 ;
 ;***** EXECUTES THE 'RUN BATCH' EDITS REQUEST
 ;
 ; [.ONCSAPI]    Reference to the API descriptor (see ^ONCSAPI)
 ;
 ; .ONC8REQ      Reference to a local variable that stores the
 ;               closed root of the request.
 ;
 ;               Sub-nodes of the variable are used internally
 ;               (see ^ONCSNACR and ^ONCSAPIR for details).
 ;
 ; [ONC8MSG]     Closed root of the buffer for error messages. By
 ;               default ($G(ONC8MSG)=""), the ^TMP("ONCSED01M",$J)
 ;               global node is used.
 ;
 ; @ONC8MSG@(
 ;   0)                  Result descriptor
 ;                         ^01: Number of errors
 ;                         ^02: Number of warnings
 ;                         ^03: Web-service version
 ;                         ^04: Metafile version
 ;   set#,
 ;     0)                Edit set descriptor
 ;                         ^01: Number of errors
 ;                         ^02: Number of warnings
 ;     1)                Edit set name
 ;     "E",
 ;       edit#,
 ;         0)            Edit descriptor
 ;                         ^01: Number of errors
 ;                         ^02: Number of warnings
 ;                         ^03: Edit index
 ;         1)            Edit name
 ;         "F",
 ;           fld#,
 ;             0)        Field descriptor
 ;                         ^01: Start position
 ;           1)          Field name
 ;           2)          Field value
 ;
 ;         "M",
 ;           msg#,
 ;             0)        Message descriptor
 ;                         ^01: Code
 ;                         ^02: Type
 ;             1)        Message text
 ;
 ;   "ES",
 ;     edit#)            set#
 ;
 ; The ^TMP("ONCSED01R",$J) and ^TMP("ONCSED01M",$J) global nodes
 ; are used by this function.
 ;
 ; Return values:
 ;
 ;       <0  Error Descriptor (see ^ONCSAPI for details)
 ;           For example:
 ;             "-6^Parameter 'ONC8REQ' has an invalid value: ''^
 ;              RBQEXEC+3^ONCSED01"
 ;
 ;        0  Ok
 ;
 ;        1  EDITS Warnings
 ;
 ;        2  EDITS Errors
 ;
RBQEXEC(ONCSAPI,ONC8REQ,ONC8MSG) ;
 N ONC8RDAT,RC,TMP,URL,X
 ;--- Validate parameters
 Q:$G(ONC8REQ)?." " $$ERROR^ONCSAPIE(-6,,"ONC8REQ",$G(ONC8REQ))
 S:$G(ONC8MSG)?." " ONC8MSG=$NA(^TMP("ONCSED01M",$J))
 ;--- Initialize variables
 S ONC8RDAT=$NA(^TMP("ONCSED01R",$J))
 K @ONC8RDAT,@ONC8MSG
 ;
 ;--- Finish preparation of the NAACCR record
 D END^ONCSNACR(.ONC8REQ)
 ;
 ;--- Complete the request
 D TRAILER^ONCSAPIR(.ONC8REQ)
 ;
 ;--- Get the server URL ;commented url to use HWSC
 S URL=$$GETCSURL^ONCSAPIU()  Q:URL<0 URL
 ;
 S RC=0  D
 . ;--- Call the web service ; commented run batch request and use HWSC
 . D:$G(ONCSAPI("DEBUG"))
 . . D ZW^ONCSAPIU(ONC8REQ,"*** 'RUN BATCH' REQUEST ***")
 . ;S RC=$$REQUEST^ONCSAPIR(URL,ONC8RDAT,ONC8REQ) Q:RC<0
 . ; P16
 . S ONCEXEC="P" D T3^ONCWEB1
 . D:$G(ONCSAPI("DEBUG"))
 . . D ZW^ONCSAPIU(ONC8RDAT,"*** 'RUN BATCH' RESPONSE ***")
 . ;--- Parse the response
 . D PARSE^ONCWEBP1
 . ;S RC=$$PARSE^ONCSED02(.ONCSAPI,ONC8RDAT,ONC8MSG)
 ;
 ;--- Cleanup
 K ^TMP("ONCSED01R",$J)
 D:RC'<0
 . S TMP=$G(@ONC8MSG@(0))
 . S RC=$S($P(TMP,U,1)>0:2,$P(TMP,U,2)>0:1,1:0)
 Q RC
 ;
 ;***** STARTS PREPARATION OF THE 'RUN BATCH' EDITS REQUEST
 ;
 ; [.ONCSAPI]    Reference to the API descriptor (see ^ONCSAPI)
 ;
 ; .ONC8REQ      Reference to a local variable that stores the
 ;               closed root of the buffer for the request.
 ;
 ;               Sub-nodes of the variable are used internally
 ;               (see ^ONCSNACR and ^ONCSAPIR for details).
 ;
 ; [CFGNAME]     Name of the configuration that should be used by
 ;               the server to validate the data.  By default,
 ;               the default configuration is used.
 ;
 ; Return values:
 ;
 ;       <0  Error Descriptor (see ^ONCSAPI for details)
 ;           For example:
 ;             "-6^Parameter 'ONC8REQ' has an invalid value: ''^
 ;              RBQPREP+3^ONCSED01"
 ;
 ;        0  Ok
 ;
RBQPREP(ONCSAPI,ONC8REQ,CFGNAME) ;
 N ATTS
 D CLEAR^ONCSAPIE()
 ;--- Validate parameters
 Q:$G(ONC8REQ)?." " $$ERROR^ONCSAPIE(-6,,"ONC8REQ",$G(ONC8REQ))
 ;
 ;--- Standard request header
 S:'($G(CFGNAME)?." ") ATTS("edits-config")=CFGNAME
 D HEADER^ONCSAPIR(.ONC8REQ,"ED-RUN-BATCH",.ATTS)
 ;
 ;--- Start preparation of the NAACCR record
 D BEGIN^ONCSNACR(.ONC8REQ)
 ;---
 Q 0
 ;
 ;***** PRINTS 'EDITS' REPORT ON THE CURRENT DEVICE
 ;
 ; [.ONCSAPI]    Reference to the API descriptor (see ^ONCSAPI)
 ;
 ; ONC8MSG       Closed root of the list of parsed error messages
 ;               (generated by the RBQEXEC^ONCSED0101)
 ;
 ; [FLAGS]       Flags that control the output (can be combined):
 ;                 M  Include messages
 ;                 T  Include totals
 ;
 ; Return values:
 ;
 ;       <0  Error Descriptor (see ^ONCSAPI for details)
 ;           For example:
 ;             "-6^Parameter 'ONC8REQ' has an invalid value: ''^
 ;              RBQEXEC+3^ONCSED01"
 ;
 ;        0  Ok
 ;
 ;        1  Timeout
 ;        2  User canceled the output ('^' was entered) 
 ;
REPORT(ONCSAPI,ONC8MSG,FLAGS) ;
 N RC,TMP
 S TMP=$G(@ONC8MSG@(0))
 Q:($P(TMP,U,1)'>0)&($P(TMP,U,2)'>0) 0
 S FLAGS=$G(FLAGS)
 I $TR(FLAGS,"MT")'=FLAGS  W:$E(IOST,1,2)="C-" @IOF
 ;--- EDITS messages
 I FLAGS["M"  D  Q:RC RC
 . S RC=$$MESSAGES^ONCSED03(.ONCSAPI,ONC8MSG,FLAGS)
 ;--- EDITS totals
 I FLAGS["T"  D  Q:RC RC
 . S RC=$$TOTALS^ONCSED03(.ONCSAPI,ONC8MSG,FLAGS)
 ;---
 Q 0
 ;
XMLHDR ;XML header for Edits
 S ONCXMHR="EDIT"  ;for EDIT testing
 S ONCSKEY="d27e1428f71e47239327d7e77e1439c6"
 I $D(ONCCSTP) S:ONCCSTP="U" ONCCSTP="Update"  S:ONCCSTP="N" ONCCSTP="New"
 S ONCT=$$NOW^XLFDT(),ONCTZONE=$$TZ^XLFDT()
 ;S ONCT=$$HLDATE^HLFNC($$NOW^XLFDT())  ;USE this code instead
 S ONCTHR=$E(ONCT,9,10),ONCTMN=$E(ONCT,11,12),ONCTSN=$E(ONCT,13,14)
 S:ONCTSN="" ONCTSN="00"
 S:($L(ONCTSN)=1) ONCTSN="0"_ONCTSN
 S ONCTSN=ONCTSN_".000"_$E(ONCTZONE,1,3)_":"_$E(ONCTZONE,4,5)
 S ONCDTNW=""""_(1700+$E(ONCT,1,3))_"-"_$E(ONCT,4,5)_"-"_$E(ONCT,6,7)_"T"_ONCTHR_":"_ONCTMN_":"_ONCTSN_""""
 S ONCX21=1,ONCXML=6
 S ONCDIC="""http://naaccr.org/naaccrxml/naaccr-dictionary-230.xml"""
 S ONC11=" baseDictionaryUri="
 S ONC22=" recordType=",ONC33=" timeGenerated=",ONC44=" specificationVersion="
 ;For Edits and Collaborative Staging (CS)
 S:ONCXMHR="EDIT" ONCREQT="EditCheckRequest"
 S:ONCXMHR="CS" ONCREQT="CsCheckRequest"
 S ^TMP("ONC",$J,1)="<?xml version=""1.0"" encoding=""utf-8""?>"
 ;S ^TMP("ONC",$J,2)="<soap:Envelope xmlns:soap=""http://www.w3.org/2001/12/soap-envelope"""
 ;S ^TMP("ONC",$J,3)=" soap:encodingStyle=""http://www.w3.org/2001/12/soap-encoding"">"
 ;S ^TMP("ONC",$J,4)="<soap:Body>"
 ;S ^TMP("ONC",$J,5)="<"_ONCREQT_">"
 ;S ^TMP("ONC",$J,6)="<requestId>"_ONCREID_"</requestId>"
 ;S ^TMP("ONC",$J,7)="<caseId>"_ONCCSID_"</caseId>"
 ;S ^TMP("ONC",$J,8)="<caseType>"_ONCCSTP_"</caseType>"
 ;S ^TMP("ONC",$J,9)="<NaaccrData baseDictionaryUri=""http://naaccr.org/naaccrxml/naaccr-dictionary-230.xml"" recordType=""C"" timeGenerated="_ONCDTNW_" specificationVersion=""1.4"" xmlns=""http://naaccr.org/naaccrxml"""_">"
 S ^TMP("ONC",$J,2)="<"_ONCREQT_">"
 ;S ^TMP("ONC",$J,3)="<requestId>"_ONCREID_"</requestId>"
 S ^TMP("ONC",$J,3)="<requestId>"_ONCREID_"</requestId>"  ;test failure
 S ^TMP("ONC",$J,4)="<caseId>"_ONCCSID_"</caseId>"
 S ^TMP("ONC",$J,5)="<caseType>"_ONCCSTP_"</caseType>"
 ;S ^TMP("ONC",$J,6)="<ocpApimSubscriptionKey>"_ONCSKEY_"</ocpApimSubscriptionKey>"
 S ^TMP("ONC",$J,6)="<NaaccrData baseDictionaryUri=""http://naaccr.org/naaccrxml/naaccr-dictionary-230.xml"" recordType=""C"" timeGenerated="_ONCDTNW_" specificationVersion=""1.4"" xmlns=""http://naaccr.org/naaccrxml"""_">"
 Q
XMLEDIT ;Prepares EDIT xml data
 N ONCDE
 ;
 N ONCRTYP,ONCOLD,ONCPOS
 S ONCOLD="TEST",(ONCPOS,POS)="A",ONCRTYP="",ONCIE160(IEN)=IEN
 F  S POS=$O(^ONCO(160.16,EXTRACT,"FIELD","D",POS)) Q:POS=""  D
 .N NODE,ONCXDATA S NODE=0
 .I POS="P" S ONCRTYP="<Patient>"
 .I POS="T" S ONCRTYP="<Tumor>"
 .F  S NODE=$O(^ONCO(160.16,EXTRACT,"FIELD","D",POS,NODE)) Q:NODE<1  D  Q:OUT
 ..N STRING,DEFAULT,FILL,LEN,ONCXDATA
 ..Q:$G(^ONCO(160.16,EXTRACT,"FIELD",NODE,0))=""
 ..S ONCXDATA=$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,0),U,5)
 ..Q:ONCXDATA=""
 ..I (POS'=ONCPOS),(ONCOLD'=ONCRTYP),(ONCRTYP'="") D
 ...S:POS="P" ^TMP("ONC",$J,ONCXML+1)=ONCRTYP,ONCXML=ONCXML+1
 ...S:POS="T" ^TMP("ONC",$J,ONCXML+1)=ONCRTYP,ONCXML=ONCXML+1
 ...S ONCOLD=ONCRTYP,ONCPOS=POS
 ..S LEN=$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,0),U,2)
 ..S STRING=$TR(^ONCO(160.16,EXTRACT,"FIELD",NODE,1),"~","^")
 ..S DEFAULT=$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,2),U,1)
 ..S FILL=$P(^ONCO(160.16,EXTRACT,"FIELD",NODE,3),U,1)
 ..;D DATA^ONCACD1(IEN,ACD160,STRING,DEFAULT,FILL,LEN,JUMP,NODE,POS)
 ..D DATA
 .S ONCXPRT=1
 S ^TMP("ONC",$J,ONCXML+1)="</Tumor>",ONCXML=ONCXML+1
 S ^TMP("ONC",$J,ONCXML+1)="</Patient>",ONCXML=ONCXML+1
 S ^TMP("ONC",$J,ONCXML+1)="</NaaccrData>",ONCXML=ONCXML+1
 S ^TMP("ONC",$J,ONCXML+1)="</EditCheckRequest>",ONCXML=ONCXML+1
 ;S ^TMP("ONC",$J,ONCXML+1)="</soap:Body>",ONCXML=ONCXML+1
 ;S ^TMP("ONC",$J,ONCXML+1)="</soap:Envelope>",ONCXML=ONCXML+1
 ;B  K ^TMP("ONC",$J)
 ;F I=1:1:167 S ^TMP("ONC",$J,I)=^XMB(3.9,3108776,2,I,0)
 ;B
 Q
DATA ;
 N ACDANS,EXIT S EXIT=0
 S:'$D(ONCPHI) ONCPHI=0   ;P2.2*4
 I $G(ONCX21)=1 D
 .;I $G(ONCPRNT)>20,(POS="N") Q
 .X STRING
 .;If value = "", extract DEFAULT value
 .I (ACDANS=""),(DEFAULT="BLANK") Q
 .N I,X S X=""
 .I DEFAULT=8 D
 ..F I=1:1:LEN S ACDANS=ACDANS_@DEFAULT
 .I @DEFAULT="09" S ACDANS=@DEFAULT
 .I (ACDANS["&")!(ACDANS["<")!(ACDANS[">") D STRIP^ONCACD1
 .D XFILL^ONCACD1
 .;S:POS="N" ONCTAB="  "
 .;S:POS="P" ONCTAB="     "
 .;S:POS="T" ONCTAB="       "
 .Q:ACDANS=""
 .S ^TMP("ONC",$J,ONCXML+1)="<Item naaccrId="""_ONCXDATA_""">"_ACDANS_"</Item>",ONCXML=ONCXML+1
 .;S ONCPRNT=ONCPRNT+1
 .Q
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HONCSED01   10867     printed  Sep 23, 2025@20:04:20                                                                                                                                                                                                   Page 2
ONCSED01  ;HINES OIFO/SG - EDITS 'RUN BATCH' REQUEST ; 11/6/06 11:48am
 +1       ;;2.2;ONCOLOGY;**1,16,19,20**;Jul 31, 2013;Build 5
 +2       ;..P19
 +3       ;P16 - hwsc encrytion function
 +4       ;--- SOAP REQUST TO THE ONCOLOGY WEB SERVICE
 +5       ;
 +6       ; <?xml version="1.0" encoding="utf-8"?>
 +7       ; <soap:Envelope
 +8       ;   xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
 +9       ;   soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
 +10      ;   <soap:Body>
 +11      ;     <ED-RUN-BATCH [edits-config="..."] ver="2.0"
 +12      ;       xmlns="http://vista.domain.ext/oncology">
 +13      ;       <NAACCR-RECORD> ... </NAACCR-RECORD>
 +14      ;     </ED-RUN-BATCH>
 +15      ;   </soap:Body >
 +16      ; </soap:Envelope>
 +17      ;
 +18      ;--- ATTRIBUTES
 +19      ;
 +20      ; edits-config  Name of the configuration that should be used by
 +21      ;               the server to validate the data.  By default,
 +22      ;               the "DEFAULT" name is used.
 +23      ;
 +24       QUIT 
 +25      ;
 +26      ;***** EXECUTES THE 'RUN BATCH' EDITS REQUEST
 +27      ;
 +28      ; [.ONCSAPI]    Reference to the API descriptor (see ^ONCSAPI)
 +29      ;
 +30      ; .ONC8REQ      Reference to a local variable that stores the
 +31      ;               closed root of the request.
 +32      ;
 +33      ;               Sub-nodes of the variable are used internally
 +34      ;               (see ^ONCSNACR and ^ONCSAPIR for details).
 +35      ;
 +36      ; [ONC8MSG]     Closed root of the buffer for error messages. By
 +37      ;               default ($G(ONC8MSG)=""), the ^TMP("ONCSED01M",$J)
 +38      ;               global node is used.
 +39      ;
 +40      ; @ONC8MSG@(
 +41      ;   0)                  Result descriptor
 +42      ;                         ^01: Number of errors
 +43      ;                         ^02: Number of warnings
 +44      ;                         ^03: Web-service version
 +45      ;                         ^04: Metafile version
 +46      ;   set#,
 +47      ;     0)                Edit set descriptor
 +48      ;                         ^01: Number of errors
 +49      ;                         ^02: Number of warnings
 +50      ;     1)                Edit set name
 +51      ;     "E",
 +52      ;       edit#,
 +53      ;         0)            Edit descriptor
 +54      ;                         ^01: Number of errors
 +55      ;                         ^02: Number of warnings
 +56      ;                         ^03: Edit index
 +57      ;         1)            Edit name
 +58      ;         "F",
 +59      ;           fld#,
 +60      ;             0)        Field descriptor
 +61      ;                         ^01: Start position
 +62      ;           1)          Field name
 +63      ;           2)          Field value
 +64      ;
 +65      ;         "M",
 +66      ;           msg#,
 +67      ;             0)        Message descriptor
 +68      ;                         ^01: Code
 +69      ;                         ^02: Type
 +70      ;             1)        Message text
 +71      ;
 +72      ;   "ES",
 +73      ;     edit#)            set#
 +74      ;
 +75      ; The ^TMP("ONCSED01R",$J) and ^TMP("ONCSED01M",$J) global nodes
 +76      ; are used by this function.
 +77      ;
 +78      ; Return values:
 +79      ;
 +80      ;       <0  Error Descriptor (see ^ONCSAPI for details)
 +81      ;           For example:
 +82      ;             "-6^Parameter 'ONC8REQ' has an invalid value: ''^
 +83      ;              RBQEXEC+3^ONCSED01"
 +84      ;
 +85      ;        0  Ok
 +86      ;
 +87      ;        1  EDITS Warnings
 +88      ;
 +89      ;        2  EDITS Errors
 +90      ;
RBQEXEC(ONCSAPI,ONC8REQ,ONC8MSG) ;
 +1        NEW ONC8RDAT,RC,TMP,URL,X
 +2       ;--- Validate parameters
 +3        if $GET(ONC8REQ)?." "
               QUIT $$ERROR^ONCSAPIE(-6,,"ONC8REQ",$GET(ONC8REQ))
 +4        if $GET(ONC8MSG)?." "
               SET ONC8MSG=$NAME(^TMP("ONCSED01M",$JOB))
 +5       ;--- Initialize variables
 +6        SET ONC8RDAT=$NAME(^TMP("ONCSED01R",$JOB))
 +7        KILL @ONC8RDAT,@ONC8MSG
 +8       ;
 +9       ;--- Finish preparation of the NAACCR record
 +10       DO END^ONCSNACR(.ONC8REQ)
 +11      ;
 +12      ;--- Complete the request
 +13       DO TRAILER^ONCSAPIR(.ONC8REQ)
 +14      ;
 +15      ;--- Get the server URL ;commented url to use HWSC
 +16       SET URL=$$GETCSURL^ONCSAPIU()
           if URL<0
               QUIT URL
 +17      ;
 +18       SET RC=0
           Begin DoDot:1
 +19      ;--- Call the web service ; commented run batch request and use HWSC
 +20           if $GET(ONCSAPI("DEBUG"))
                   Begin DoDot:2
 +21                   DO ZW^ONCSAPIU(ONC8REQ,"*** 'RUN BATCH' REQUEST ***")
                   End DoDot:2
 +22      ;S RC=$$REQUEST^ONCSAPIR(URL,ONC8RDAT,ONC8REQ) Q:RC<0
 +23      ; P16
 +24           SET ONCEXEC="P"
               DO T3^ONCWEB1
 +25           if $GET(ONCSAPI("DEBUG"))
                   Begin DoDot:2
 +26                   DO ZW^ONCSAPIU(ONC8RDAT,"*** 'RUN BATCH' RESPONSE ***")
                   End DoDot:2
 +27      ;--- Parse the response
 +28           DO PARSE^ONCWEBP1
 +29      ;S RC=$$PARSE^ONCSED02(.ONCSAPI,ONC8RDAT,ONC8MSG)
           End DoDot:1
 +30      ;
 +31      ;--- Cleanup
 +32       KILL ^TMP("ONCSED01R",$JOB)
 +33       if RC'<0
               Begin DoDot:1
 +34               SET TMP=$GET(@ONC8MSG@(0))
 +35               SET RC=$SELECT($PIECE(TMP,U,1)>0:2,$PIECE(TMP,U,2)>0:1,1:0)
               End DoDot:1
 +36       QUIT RC
 +37      ;
 +38      ;***** STARTS PREPARATION OF THE 'RUN BATCH' EDITS REQUEST
 +39      ;
 +40      ; [.ONCSAPI]    Reference to the API descriptor (see ^ONCSAPI)
 +41      ;
 +42      ; .ONC8REQ      Reference to a local variable that stores the
 +43      ;               closed root of the buffer for the request.
 +44      ;
 +45      ;               Sub-nodes of the variable are used internally
 +46      ;               (see ^ONCSNACR and ^ONCSAPIR for details).
 +47      ;
 +48      ; [CFGNAME]     Name of the configuration that should be used by
 +49      ;               the server to validate the data.  By default,
 +50      ;               the default configuration is used.
 +51      ;
 +52      ; Return values:
 +53      ;
 +54      ;       <0  Error Descriptor (see ^ONCSAPI for details)
 +55      ;           For example:
 +56      ;             "-6^Parameter 'ONC8REQ' has an invalid value: ''^
 +57      ;              RBQPREP+3^ONCSED01"
 +58      ;
 +59      ;        0  Ok
 +60      ;
RBQPREP(ONCSAPI,ONC8REQ,CFGNAME) ;
 +1        NEW ATTS
 +2        DO CLEAR^ONCSAPIE()
 +3       ;--- Validate parameters
 +4        if $GET(ONC8REQ)?." "
               QUIT $$ERROR^ONCSAPIE(-6,,"ONC8REQ",$GET(ONC8REQ))
 +5       ;
 +6       ;--- Standard request header
 +7        if '($GET(CFGNAME)?." ")
               SET ATTS("edits-config")=CFGNAME
 +8        DO HEADER^ONCSAPIR(.ONC8REQ,"ED-RUN-BATCH",.ATTS)
 +9       ;
 +10      ;--- Start preparation of the NAACCR record
 +11       DO BEGIN^ONCSNACR(.ONC8REQ)
 +12      ;---
 +13       QUIT 0
 +14      ;
 +15      ;***** PRINTS 'EDITS' REPORT ON THE CURRENT DEVICE
 +16      ;
 +17      ; [.ONCSAPI]    Reference to the API descriptor (see ^ONCSAPI)
 +18      ;
 +19      ; ONC8MSG       Closed root of the list of parsed error messages
 +20      ;               (generated by the RBQEXEC^ONCSED0101)
 +21      ;
 +22      ; [FLAGS]       Flags that control the output (can be combined):
 +23      ;                 M  Include messages
 +24      ;                 T  Include totals
 +25      ;
 +26      ; Return values:
 +27      ;
 +28      ;       <0  Error Descriptor (see ^ONCSAPI for details)
 +29      ;           For example:
 +30      ;             "-6^Parameter 'ONC8REQ' has an invalid value: ''^
 +31      ;              RBQEXEC+3^ONCSED01"
 +32      ;
 +33      ;        0  Ok
 +34      ;
 +35      ;        1  Timeout
 +36      ;        2  User canceled the output ('^' was entered) 
 +37      ;
REPORT(ONCSAPI,ONC8MSG,FLAGS) ;
 +1        NEW RC,TMP
 +2        SET TMP=$GET(@ONC8MSG@(0))
 +3        if ($PIECE(TMP,U,1)'>0)&($PIECE(TMP,U,2)'>0)
               QUIT 0
 +4        SET FLAGS=$GET(FLAGS)
 +5        IF $TRANSLATE(FLAGS,"MT")'=FLAGS
               if $EXTRACT(IOST,1,2)="C-"
                   WRITE @IOF
 +6       ;--- EDITS messages
 +7        IF FLAGS["M"
               Begin DoDot:1
 +8                SET RC=$$MESSAGES^ONCSED03(.ONCSAPI,ONC8MSG,FLAGS)
               End DoDot:1
               if RC
                   QUIT RC
 +9       ;--- EDITS totals
 +10       IF FLAGS["T"
               Begin DoDot:1
 +11               SET RC=$$TOTALS^ONCSED03(.ONCSAPI,ONC8MSG,FLAGS)
               End DoDot:1
               if RC
                   QUIT RC
 +12      ;---
 +13       QUIT 0
 +14      ;
XMLHDR    ;XML header for Edits
 +1       ;for EDIT testing
           SET ONCXMHR="EDIT"
 +2        SET ONCSKEY="d27e1428f71e47239327d7e77e1439c6"
 +3        IF $DATA(ONCCSTP)
               if ONCCSTP="U"
                   SET ONCCSTP="Update"
               if ONCCSTP="N"
                   SET ONCCSTP="New"
 +4        SET ONCT=$$NOW^XLFDT()
           SET ONCTZONE=$$TZ^XLFDT()
 +5       ;S ONCT=$$HLDATE^HLFNC($$NOW^XLFDT())  ;USE this code instead
 +6        SET ONCTHR=$EXTRACT(ONCT,9,10)
           SET ONCTMN=$EXTRACT(ONCT,11,12)
           SET ONCTSN=$EXTRACT(ONCT,13,14)
 +7        if ONCTSN=""
               SET ONCTSN="00"
 +8        if ($LENGTH(ONCTSN)=1)
               SET ONCTSN="0"_ONCTSN
 +9        SET ONCTSN=ONCTSN_".000"_$EXTRACT(ONCTZONE,1,3)_":"_$EXTRACT(ONCTZONE,4,5)
 +10       SET ONCDTNW=""""_(1700+$EXTRACT(ONCT,1,3))_"-"_$EXTRACT(ONCT,4,5)_"-"_$EXTRACT(ONCT,6,7)_"T"_ONCTHR_":"_ONCTMN_":"_ONCTSN_""""
 +11       SET ONCX21=1
           SET ONCXML=6
 +12       SET ONCDIC="""http://naaccr.org/naaccrxml/naaccr-dictionary-230.xml"""
 +13       SET ONC11=" baseDictionaryUri="
 +14       SET ONC22=" recordType="
           SET ONC33=" timeGenerated="
           SET ONC44=" specificationVersion="
 +15      ;For Edits and Collaborative Staging (CS)
 +16       if ONCXMHR="EDIT"
               SET ONCREQT="EditCheckRequest"
 +17       if ONCXMHR="CS"
               SET ONCREQT="CsCheckRequest"
 +18       SET ^TMP("ONC",$JOB,1)="<?xml version=""1.0"" encoding=""utf-8""?>"
 +19      ;S ^TMP("ONC",$J,2)="<soap:Envelope xmlns:soap=""http://www.w3.org/2001/12/soap-envelope"""
 +20      ;S ^TMP("ONC",$J,3)=" soap:encodingStyle=""http://www.w3.org/2001/12/soap-encoding"">"
 +21      ;S ^TMP("ONC",$J,4)="<soap:Body>"
 +22      ;S ^TMP("ONC",$J,5)="<"_ONCREQT_">"
 +23      ;S ^TMP("ONC",$J,6)="<requestId>"_ONCREID_"</requestId>"
 +24      ;S ^TMP("ONC",$J,7)="<caseId>"_ONCCSID_"</caseId>"
 +25      ;S ^TMP("ONC",$J,8)="<caseType>"_ONCCSTP_"</caseType>"
 +26      ;S ^TMP("ONC",$J,9)="<NaaccrData baseDictionaryUri=""http://naaccr.org/naaccrxml/naaccr-dictionary-230.xml"" recordType=""C"" timeGenerated="_ONCDTNW_" specificationVersion=""1.4"" xmlns=""http://naaccr.org/naaccrxml"""_">"
 +27       SET ^TMP("ONC",$JOB,2)="<"_ONCREQT_">"
 +28      ;S ^TMP("ONC",$J,3)="<requestId>"_ONCREID_"</requestId>"
 +29      ;test failure
           SET ^TMP("ONC",$JOB,3)="<requestId>"_ONCREID_"</requestId>"
 +30       SET ^TMP("ONC",$JOB,4)="<caseId>"_ONCCSID_"</caseId>"
 +31       SET ^TMP("ONC",$JOB,5)="<caseType>"_ONCCSTP_"</caseType>"
 +32      ;S ^TMP("ONC",$J,6)="<ocpApimSubscriptionKey>"_ONCSKEY_"</ocpApimSubscriptionKey>"
 +33       SET ^TMP("ONC",$JOB,6)="<NaaccrData baseDictionaryUri=""http://naaccr.org/naaccrxml/naaccr-dictionary-230.xml"" recordType=""C"" timeGenerated="_ONCDTNW_" specificationVersion=""1.4"" xmlns=""http://naaccr.org/naaccrxml"""_">"
 +34       QUIT 
XMLEDIT   ;Prepares EDIT xml data
 +1        NEW ONCDE
 +2       ;
 +3        NEW ONCRTYP,ONCOLD,ONCPOS
 +4        SET ONCOLD="TEST"
           SET (ONCPOS,POS)="A"
           SET ONCRTYP=""
           SET ONCIE160(IEN)=IEN
 +5        FOR 
               SET POS=$ORDER(^ONCO(160.16,EXTRACT,"FIELD","D",POS))
               if POS=""
                   QUIT 
               Begin DoDot:1
 +6                NEW NODE,ONCXDATA
                   SET NODE=0
 +7                IF POS="P"
                       SET ONCRTYP="<Patient>"
 +8                IF POS="T"
                       SET ONCRTYP="<Tumor>"
 +9                FOR 
                       SET NODE=$ORDER(^ONCO(160.16,EXTRACT,"FIELD","D",POS,NODE))
                       if NODE<1
                           QUIT 
                       Begin DoDot:2
 +10                       NEW STRING,DEFAULT,FILL,LEN,ONCXDATA
 +11                       if $GET(^ONCO(160.16,EXTRACT,"FIELD",NODE,0))=""
                               QUIT 
 +12                       SET ONCXDATA=$PIECE(^ONCO(160.16,EXTRACT,"FIELD",NODE,0),U,5)
 +13                       if ONCXDATA=""
                               QUIT 
 +14                       IF (POS'=ONCPOS)
                               IF (ONCOLD'=ONCRTYP)
                                   IF (ONCRTYP'="")
                                       Begin DoDot:3
 +15                                       if POS="P"
                                               SET ^TMP("ONC",$JOB,ONCXML+1)=ONCRTYP
                                               SET ONCXML=ONCXML+1
 +16                                       if POS="T"
                                               SET ^TMP("ONC",$JOB,ONCXML+1)=ONCRTYP
                                               SET ONCXML=ONCXML+1
 +17                                       SET ONCOLD=ONCRTYP
                                           SET ONCPOS=POS
                                       End DoDot:3
 +18                       SET LEN=$PIECE(^ONCO(160.16,EXTRACT,"FIELD",NODE,0),U,2)
 +19                       SET STRING=$TRANSLATE(^ONCO(160.16,EXTRACT,"FIELD",NODE,1),"~","^")
 +20                       SET DEFAULT=$PIECE(^ONCO(160.16,EXTRACT,"FIELD",NODE,2),U,1)
 +21                       SET FILL=$PIECE(^ONCO(160.16,EXTRACT,"FIELD",NODE,3),U,1)
 +22      ;D DATA^ONCACD1(IEN,ACD160,STRING,DEFAULT,FILL,LEN,JUMP,NODE,POS)
 +23                       DO DATA
                       End DoDot:2
                       if OUT
                           QUIT 
 +24               SET ONCXPRT=1
               End DoDot:1
 +25       SET ^TMP("ONC",$JOB,ONCXML+1)="</Tumor>"
           SET ONCXML=ONCXML+1
 +26       SET ^TMP("ONC",$JOB,ONCXML+1)="</Patient>"
           SET ONCXML=ONCXML+1
 +27       SET ^TMP("ONC",$JOB,ONCXML+1)="</NaaccrData>"
           SET ONCXML=ONCXML+1
 +28       SET ^TMP("ONC",$JOB,ONCXML+1)="</EditCheckRequest>"
           SET ONCXML=ONCXML+1
 +29      ;S ^TMP("ONC",$J,ONCXML+1)="</soap:Body>",ONCXML=ONCXML+1
 +30      ;S ^TMP("ONC",$J,ONCXML+1)="</soap:Envelope>",ONCXML=ONCXML+1
 +31      ;B  K ^TMP("ONC",$J)
 +32      ;F I=1:1:167 S ^TMP("ONC",$J,I)=^XMB(3.9,3108776,2,I,0)
 +33      ;B
 +34       QUIT 
DATA      ;
 +1        NEW ACDANS,EXIT
           SET EXIT=0
 +2       ;P2.2*4
           if '$DATA(ONCPHI)
               SET ONCPHI=0
 +3        IF $GET(ONCX21)=1
               Begin DoDot:1
 +4       ;I $G(ONCPRNT)>20,(POS="N") Q
 +5                XECUTE STRING
 +6       ;If value = "", extract DEFAULT value
 +7                IF (ACDANS="")
                       IF (DEFAULT="BLANK")
                           QUIT 
 +8                NEW I,X
                   SET X=""
 +9                IF DEFAULT=8
                       Begin DoDot:2
 +10                       FOR I=1:1:LEN
                               SET ACDANS=ACDANS_@DEFAULT
                       End DoDot:2
 +11               IF @DEFAULT="09"
                       SET ACDANS=@DEFAULT
 +12               IF (ACDANS["&")!(ACDANS["<")!(ACDANS[">")
                       DO STRIP^ONCACD1
 +13               DO XFILL^ONCACD1
 +14      ;S:POS="N" ONCTAB="  "
 +15      ;S:POS="P" ONCTAB="     "
 +16      ;S:POS="T" ONCTAB="       "
 +17               if ACDANS=""
                       QUIT 
 +18               SET ^TMP("ONC",$JOB,ONCXML+1)="<Item naaccrId="""_ONCXDATA_""">"_ACDANS_"</Item>"
                   SET ONCXML=ONCXML+1
 +19      ;S ONCPRNT=ONCPRNT+1
 +20               QUIT 
               End DoDot:1
 +21       QUIT