RGRPC ;BIRMIO/CMC-RG RPC API ;3 MAY 07
 ;;1.0;CLINICAL INFO RESOURCE NETWORK;**48**;30 Apr 99;Build 3
 ;
 ;
EN(RETURN,ICN,SSN,DFN,BRANGE,ERANGE) ;
 ;RETURN IS THE ARRAY TO HOLD THE RESULTS
 ;ICN is the Integration Control Number of the patient to find exceptions for (optional)
 ;SSN is the social of the patient to find exceptions for (optional)
 ;DFN is the internal entry number of the patient in the PATIENT (#2) file to find exceptions for (optional)
 ;Either ICN, SSN or DFN must be present
 ;BRANGE is the BEGINNING date range specified to find exceptions for the patient
 ;ERANGE is the ENDING date range specified to find exceptions for the patient
 ;
 ;S ^XTMP("CMC")=ICN_"^"_SSN_"^"_DFN_"^"_BRANGE_"^"_ERANGE FOR DEBUGGING
 I $G(ICN)=""&$G(SSN)=""&$G(DFN)="" S RETURN="-1^Patient not specified" Q
 I $G(BRANGE)="" S BRANGE=DT
 I $G(ERANGE)="" S ERANGE=DT
 I BRANGE>ERANGE S RETURN="-1^Beginning date is newer than End date" Q
 ;
 I $G(DFN)="" D
 .;need to get DFN
 .I $G(SSN)'="" S ICN=$$GETICNS^MPIF002(SSN)
 .I $G(ICN)'="" S DFN=$$GETDFN^MPIF001(ICN)
 I $G(DFN)=""!(+$G(DFN)=-1) S RETURN="-1^Can't find Patient" Q
 ;
 ; check if this data can be returned and if sensative pt bulletin needed
 N SENS D PTSEC^DGSEC4(.SENS,DFN,1,"Remote Procedure from MPI^RPC from MPI for RG Exception Information")
 N NOT D NOTICE^DGSEC4(.NOT,DFN,"Remote Procedure from MPI^RPC from MPI for RG Exception Information")
 I SENS(1)=3!(SENS(1)=4)!(SENS(1)=-1) S RETURN="-1^SENSATIVE PT ISSUE "_SENS(2)_" DFN= "_DFN_" ICN= "_ICN Q
 ;
 ;are there any exceptions for this patient?
 N TYP,CNT,IEN,IEN2,ETYP,WHO,X,Y,DIC,WTYP,WSTAT,MCNT S TYP="",CNT=1,MCNT=0
 F  S TYP=$O(^RGHL7(991.1,"ADFN",TYP)) Q:TYP=""  D
 .I $D(^RGHL7(991.1,"ADFN",TYP,DFN)) D
 ..S IEN=0 F  S IEN=$O(^RGHL7(991.1,"ADFN",TYP,DFN,IEN)) Q:IEN=""  D
 ...S IEN2="",ETYP="" F  S IEN2=$O(^RGHL7(991.1,"ADFN",TYP,DFN,IEN,IEN2)) Q:'IEN2  D
 ....S NODE=$G(^RGHL7(991.1,IEN,1,IEN2,0))
 ....S NODE10=$G(^RGHL7(991.1,IEN,1,IEN2,10))
 ....S LOGGED=$P(^RGHL7(991.1,IEN,0),"^",2)
 ....I $P(LOGGED,".")<BRANGE!($P(LOGGED,".")>ERANGE) Q
 ....S RETURN(CNT)="Exception Number: "_$P($G(^RGHL7(991.1,IEN,0)),"^"),CNT=CNT+1,MCNT=MCNT+1
 ....K Y S Y=LOGGED I Y'="" D DD^%DT
 ....S RETURN(CNT)="Exception logged on: "_Y,CNT=CNT+1
 ....S WTYP=$G(^RGHL7(991.11,TYP,10))
 ....S RETURN(CNT)="Exception Type: "_TYP_" - "_WTYP,CNT=CNT+1
 ....S RETURN(CNT)="Patient DFN: "_$P(NODE,"^",4),CNT=CNT+1
 ....S WSTAT=$P(NODE,"^",5) S WSTAT=$S(WSTAT=1:"PROCESSED",WSTAT=0:"NOT PROCESSED",1:"")
 ....S RETURN(CNT)="Exception Status: "_WSTAT,CNT=CNT+1
 ....I $P(NODE,"^",5)=1 D
 .....;MARKED AS PROCESSED
 .....K Y S Y=$P(NODE,"^",6) I Y'="" D DD^%DT
 .....S RETURN(CNT)="Date Processed: "_Y,CNT=CNT+1
 .....S WHO=$P(NODE,"^",7) I WHO'="" K X,Y S DIC="^VA(200,",DIC(0)="ZMO",X="`"_WHO D ^DIC I $G(Y)>1 S WHO=$G(Y(0,0))
 .....S RETURN(CNT)="Processed by: "_WHO,CNT=CNT+1
 ....S RETURN(CNT)="Exception Text: "_NODE10,CNT=CNT+1
 ....I $D(^RGHL7(991.1,IEN,1,IEN2,11)) D
 .....S RETURN(CNT)="Exception Notes:",CNT=CNT+1
 .....N IEN3 S IEN3=0 F  S IEN3=$O(^RGHL7(991.1,IEN,1,IEN2,11,IEN3)) Q:IEN3=""  S RETURN(CNT)=$G(^RGHL7(991.1,IEN,1,IEN2,11,IEN3,0)),CNT=CNT+1
 ....S RETURN(CNT)="**************************",CNT=CNT+1
 I CNT=1 S RETURN(0)="-1^No Exceptions found in date range.",RETURN=0
 S SITE=$$SITE^VASITE
 N PT S PT=$S(ICN'="":"ICN= "_ICN,DFN'="":"DFN= "_DFN,SSN'="":"SSN= "_SSN)
 I CNT>1 S RETURN(0)=MCNT_" exceptions found for "_PT_" at "_$P(SITE,"^",2)_" ("_$P(SITE,"^",3)_")",RETURN=MCNT
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRGRPC   3578     printed  Sep 23, 2025@19:18:47                                                                                                                                                                                                       Page 2
RGRPC     ;BIRMIO/CMC-RG RPC API ;3 MAY 07
 +1       ;;1.0;CLINICAL INFO RESOURCE NETWORK;**48**;30 Apr 99;Build 3
 +2       ;
 +3       ;
EN(RETURN,ICN,SSN,DFN,BRANGE,ERANGE) ;
 +1       ;RETURN IS THE ARRAY TO HOLD THE RESULTS
 +2       ;ICN is the Integration Control Number of the patient to find exceptions for (optional)
 +3       ;SSN is the social of the patient to find exceptions for (optional)
 +4       ;DFN is the internal entry number of the patient in the PATIENT (#2) file to find exceptions for (optional)
 +5       ;Either ICN, SSN or DFN must be present
 +6       ;BRANGE is the BEGINNING date range specified to find exceptions for the patient
 +7       ;ERANGE is the ENDING date range specified to find exceptions for the patient
 +8       ;
 +9       ;S ^XTMP("CMC")=ICN_"^"_SSN_"^"_DFN_"^"_BRANGE_"^"_ERANGE FOR DEBUGGING
 +10       IF $GET(ICN)=""&$GET(SSN)=""&$GET(DFN)=""
               SET RETURN="-1^Patient not specified"
               QUIT 
 +11       IF $GET(BRANGE)=""
               SET BRANGE=DT
 +12       IF $GET(ERANGE)=""
               SET ERANGE=DT
 +13       IF BRANGE>ERANGE
               SET RETURN="-1^Beginning date is newer than End date"
               QUIT 
 +14      ;
 +15       IF $GET(DFN)=""
               Begin DoDot:1
 +16      ;need to get DFN
 +17               IF $GET(SSN)'=""
                       SET ICN=$$GETICNS^MPIF002(SSN)
 +18               IF $GET(ICN)'=""
                       SET DFN=$$GETDFN^MPIF001(ICN)
               End DoDot:1
 +19       IF $GET(DFN)=""!(+$GET(DFN)=-1)
               SET RETURN="-1^Can't find Patient"
               QUIT 
 +20      ;
 +21      ; check if this data can be returned and if sensative pt bulletin needed
 +22       NEW SENS
           DO PTSEC^DGSEC4(.SENS,DFN,1,"Remote Procedure from MPI^RPC from MPI for RG Exception Information")
 +23       NEW NOT
           DO NOTICE^DGSEC4(.NOT,DFN,"Remote Procedure from MPI^RPC from MPI for RG Exception Information")
 +24       IF SENS(1)=3!(SENS(1)=4)!(SENS(1)=-1)
               SET RETURN="-1^SENSATIVE PT ISSUE "_SENS(2)_" DFN= "_DFN_" ICN= "_ICN
               QUIT 
 +25      ;
 +26      ;are there any exceptions for this patient?
 +27       NEW TYP,CNT,IEN,IEN2,ETYP,WHO,X,Y,DIC,WTYP,WSTAT,MCNT
           SET TYP=""
           SET CNT=1
           SET MCNT=0
 +28       FOR 
               SET TYP=$ORDER(^RGHL7(991.1,"ADFN",TYP))
               if TYP=""
                   QUIT 
               Begin DoDot:1
 +29               IF $DATA(^RGHL7(991.1,"ADFN",TYP,DFN))
                       Begin DoDot:2
 +30                       SET IEN=0
                           FOR 
                               SET IEN=$ORDER(^RGHL7(991.1,"ADFN",TYP,DFN,IEN))
                               if IEN=""
                                   QUIT 
                               Begin DoDot:3
 +31                               SET IEN2=""
                                   SET ETYP=""
                                   FOR 
                                       SET IEN2=$ORDER(^RGHL7(991.1,"ADFN",TYP,DFN,IEN,IEN2))
                                       if 'IEN2
                                           QUIT 
                                       Begin DoDot:4
 +32                                       SET NODE=$GET(^RGHL7(991.1,IEN,1,IEN2,0))
 +33                                       SET NODE10=$GET(^RGHL7(991.1,IEN,1,IEN2,10))
 +34                                       SET LOGGED=$PIECE(^RGHL7(991.1,IEN,0),"^",2)
 +35                                       IF $PIECE(LOGGED,".")<BRANGE!($PIECE(LOGGED,".")>ERANGE)
                                               QUIT 
 +36                                       SET RETURN(CNT)="Exception Number: "_$PIECE($GET(^RGHL7(991.1,IEN,0)),"^")
                                           SET CNT=CNT+1
                                           SET MCNT=MCNT+1
 +37                                       KILL Y
                                           SET Y=LOGGED
                                           IF Y'=""
                                               DO DD^%DT
 +38                                       SET RETURN(CNT)="Exception logged on: "_Y
                                           SET CNT=CNT+1
 +39                                       SET WTYP=$GET(^RGHL7(991.11,TYP,10))
 +40                                       SET RETURN(CNT)="Exception Type: "_TYP_" - "_WTYP
                                           SET CNT=CNT+1
 +41                                       SET RETURN(CNT)="Patient DFN: "_$PIECE(NODE,"^",4)
                                           SET CNT=CNT+1
 +42                                       SET WSTAT=$PIECE(NODE,"^",5)
                                           SET WSTAT=$SELECT(WSTAT=1:"PROCESSED",WSTAT=0:"NOT PROCESSED",1:"")
 +43                                       SET RETURN(CNT)="Exception Status: "_WSTAT
                                           SET CNT=CNT+1
 +44                                       IF $PIECE(NODE,"^",5)=1
                                               Begin DoDot:5
 +45      ;MARKED AS PROCESSED
 +46                                               KILL Y
                                                   SET Y=$PIECE(NODE,"^",6)
                                                   IF Y'=""
                                                       DO DD^%DT
 +47                                               SET RETURN(CNT)="Date Processed: "_Y
                                                   SET CNT=CNT+1
 +48                                               SET WHO=$PIECE(NODE,"^",7)
                                                   IF WHO'=""
                                                       KILL X,Y
                                                       SET DIC="^VA(200,"
                                                       SET DIC(0)="ZMO"
                                                       SET X="`"_WHO
                                                       DO ^DIC
                                                       IF $GET(Y)>1
                                                           SET WHO=$GET(Y(0,0))
 +49                                               SET RETURN(CNT)="Processed by: "_WHO
                                                   SET CNT=CNT+1
                                               End DoDot:5
 +50                                       SET RETURN(CNT)="Exception Text: "_NODE10
                                           SET CNT=CNT+1
 +51                                       IF $DATA(^RGHL7(991.1,IEN,1,IEN2,11))
                                               Begin DoDot:5
 +52                                               SET RETURN(CNT)="Exception Notes:"
                                                   SET CNT=CNT+1
 +53                                               NEW IEN3
                                                   SET IEN3=0
                                                   FOR 
                                                       SET IEN3=$ORDER(^RGHL7(991.1,IEN,1,IEN2,11,IEN3))
                                                       if IEN3=""
                                                           QUIT 
                                                       SET RETURN(CNT)=$GET(^RGHL7(991.1,IEN,1,IEN2,11,IEN3,0))
                                                       SET CNT=CNT+1
                                               End DoDot:5
 +54                                       SET RETURN(CNT)="**************************"
                                           SET CNT=CNT+1
                                       End DoDot:4
                               End DoDot:3
                       End DoDot:2
               End DoDot:1
 +55       IF CNT=1
               SET RETURN(0)="-1^No Exceptions found in date range."
               SET RETURN=0
 +56       SET SITE=$$SITE^VASITE
 +57       NEW PT
           SET PT=$SELECT(ICN'="":"ICN= "_ICN,DFN'="":"DFN= "_DFN,SSN'="":"SSN= "_SSN)
 +58       IF CNT>1
               SET RETURN(0)=MCNT_" exceptions found for "_PT_" at "_$PIECE(SITE,"^",2)_" ("_$PIECE(SITE,"^",3)_")"
               SET RETURN=MCNT
 +59       QUIT