RORAPI01 ;HCIOFO/SG - CLINICAL REGISTRIES API ; 5/12/05 1:59pm
 ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
 ;
 ;***** EXAMPLE
 ;
 N BUF,IPD,IRD,PATIEN,RC,REGIEN
 W !,"   Patient  Registries"
 W !,"   -------  ----------"
 ;--- Initialize the patient iterator
 S RC=$$PATITER^RORAPI01(.IPD,"VA HEPC")
 I RC<0  W "RC= ",RC,!  Q
 ;--- Browse through the registry patients
 F  S PATIEN=$$NEXTPAT^RORAPI01(.IPD)  Q:PATIEN'>0  D
 . W !,$J(PATIEN,10),"  "
 . ;--- Initialize the registry iterator
 . S RC=$$REGITER^RORAPI01(.IRD,PATIEN)
 . I RC<0  W "RC= ",RC  Q
 . ;--- Browse through the patient's registry records
 . S BUF=""
 . F  S REGIEN=$$NEXTREG^RORAPI01(.IRD)  Q:REGIEN'>0  D
 . . S BUF=BUF_","_REGIEN
 . W $P(BUF,",",2,999)
 ;---
 W !
 Q
 ;
 ;***** RETURNS THE NEXT PATIENT IN THE REGISTRY
 ;
 ; .IDESC        Reference to the iterator descriptor created
 ;               by PATITER^RORAPI01
 ;
 ; Return Values:
 ;       <0  Error code
 ;       ""  No more patients in the registry
 ;       >0  Patient IEN^empty
 ;
NEXTPAT(IDESC) ;
 N RC
 F  D  Q:$G(RC)
 . ;--- Get IEN of the next registry record
 . S IDESC("IEN")=$O(^RORDATA(798,"AC",IDESC("REGIEN"),IDESC("IEN")))
 . I IDESC("IEN")'>0  S RC="1^END"  Q
 . Q:'$$ACTIVE^RORDD(IDESC("IEN"))
 . ;--- Load the patient IEN (DFN)
 . S RC=$P($G(^RORDATA(798,IDESC("IEN"),0)),U)
 Q $S(RC="1^END":"",1:RC)
 ;
 ;***** RETURNS THE NEXT REGISTRY FOR THE PATIENT
 ;
 ; .IDESC        Reference to the iterator descriptor created
 ;               by REGITER^RORAPI01
 ;
 ; Return Values:
 ;       <0  Error code
 ;       ""  No more registries for the patient
 ;       >0  Registry IEN^empty
 ;
NEXTREG(IDESC) ;
 N RC
 F  D  Q:$G(RC)
 . ;--- Get IEN of the next registry record
 . S IDESC("IEN")=$O(^RORDATA(798,"B",IDESC("PATIEN"),IDESC("IEN")))
 . I IDESC("IEN")'>0  S RC="1^END"  Q
 . Q:'$$ACTIVE^RORDD(IDESC("IEN"))
 . ;--- Load the registry IEN
 . S RC=$P($G(^RORDATA(798,IDESC("IEN"),0)),U,2)
 Q $S(RC="1^END":"",1:RC)
 ;
 ;***** CREATES AN ITERATOR OF PATIENTS IN THE REGISTRY
 ;
 ; .IDESC        Reference to a local variable where an iterator
 ;               descriptor will be created
 ; REGNAME       Registry name
 ; [MODE]        Bit flags that define iteration mode (3 by default)
 ;                 1  Active patients
 ;                 2  Reserved
 ;
 ; Return Values:
 ;       <0  Error code
 ;        0  Ok
 ;
PATITER(IDESC,REGNAME,MODE) ;
 N REGIEN  K IDESC
 ;--- Get an IEN of the Registry Parameters
 S REGIEN=$$REGIEN^RORUTL02(REGNAME)
 Q:REGIEN<0 REGIEN
 ;--- Setup the descriptor
 S MODE=$S($G(MODE):MODE,1:3)
 S IDESC("REGNAME")=REGNAME
 S IDESC("REGIEN")=REGIEN
 S IDESC("ACT")=MODE#2
 S IDESC("ROOT")=$$ROOT^DILFD(798,"",1)
 S IDESC("IEN")=0
 Q 0
 ;
 ;***** CREATES AN ITERATOR OF THE PATIENT REGISTRIES
 ;
 ; .IDESC        Reference to a local variable where an iterator
 ;               descriptor will be created
 ; PATIEN        Patient IEN
 ; [MODE]        Bit flags that define iteration mode (3 by default)
 ;                 1  Registries where the patient is active
 ;                 2  Reserved
 ;
 ; Return Values:
 ;       <0  Error code
 ;        0  Ok
 ;
REGITER(IDESC,PATIEN,MODE) ;
 K IDESC
 ;--- Setup the descriptor
 S MODE=$S($G(MODE):MODE,1:3)
 S IDESC("PATIEN")=PATIEN
 S IDESC("ACT")=MODE#2
 S IDESC("ROOT")=$$ROOT^DILFD(798,"",1)
 S IDESC("IEN")=0
 Q 0
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRORAPI01   3466     printed  Sep 23, 2025@19:17:20                                                                                                                                                                                                    Page 2
RORAPI01  ;HCIOFO/SG - CLINICAL REGISTRIES API ; 5/12/05 1:59pm
 +1       ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
 +2       ;
 +3       ;***** EXAMPLE
 +4       ;
 +5        NEW BUF,IPD,IRD,PATIEN,RC,REGIEN
 +6        WRITE !,"   Patient  Registries"
 +7        WRITE !,"   -------  ----------"
 +8       ;--- Initialize the patient iterator
 +9        SET RC=$$PATITER^RORAPI01(.IPD,"VA HEPC")
 +10       IF RC<0
               WRITE "RC= ",RC,!
               QUIT 
 +11      ;--- Browse through the registry patients
 +12       FOR 
               SET PATIEN=$$NEXTPAT^RORAPI01(.IPD)
               if PATIEN'>0
                   QUIT 
               Begin DoDot:1
 +13               WRITE !,$JUSTIFY(PATIEN,10),"  "
 +14      ;--- Initialize the registry iterator
 +15               SET RC=$$REGITER^RORAPI01(.IRD,PATIEN)
 +16               IF RC<0
                       WRITE "RC= ",RC
                       QUIT 
 +17      ;--- Browse through the patient's registry records
 +18               SET BUF=""
 +19               FOR 
                       SET REGIEN=$$NEXTREG^RORAPI01(.IRD)
                       if REGIEN'>0
                           QUIT 
                       Begin DoDot:2
 +20                       SET BUF=BUF_","_REGIEN
                       End DoDot:2
 +21               WRITE $PIECE(BUF,",",2,999)
               End DoDot:1
 +22      ;---
 +23       WRITE !
 +24       QUIT 
 +25      ;
 +26      ;***** RETURNS THE NEXT PATIENT IN THE REGISTRY
 +27      ;
 +28      ; .IDESC        Reference to the iterator descriptor created
 +29      ;               by PATITER^RORAPI01
 +30      ;
 +31      ; Return Values:
 +32      ;       <0  Error code
 +33      ;       ""  No more patients in the registry
 +34      ;       >0  Patient IEN^empty
 +35      ;
NEXTPAT(IDESC) ;
 +1        NEW RC
 +2        FOR 
               Begin DoDot:1
 +3       ;--- Get IEN of the next registry record
 +4                SET IDESC("IEN")=$ORDER(^RORDATA(798,"AC",IDESC("REGIEN"),IDESC("IEN")))
 +5                IF IDESC("IEN")'>0
                       SET RC="1^END"
                       QUIT 
 +6                if '$$ACTIVE^RORDD(IDESC("IEN"))
                       QUIT 
 +7       ;--- Load the patient IEN (DFN)
 +8                SET RC=$PIECE($GET(^RORDATA(798,IDESC("IEN"),0)),U)
               End DoDot:1
               if $GET(RC)
                   QUIT 
 +9        QUIT $SELECT(RC="1^END":"",1:RC)
 +10      ;
 +11      ;***** RETURNS THE NEXT REGISTRY FOR THE PATIENT
 +12      ;
 +13      ; .IDESC        Reference to the iterator descriptor created
 +14      ;               by REGITER^RORAPI01
 +15      ;
 +16      ; Return Values:
 +17      ;       <0  Error code
 +18      ;       ""  No more registries for the patient
 +19      ;       >0  Registry IEN^empty
 +20      ;
NEXTREG(IDESC) ;
 +1        NEW RC
 +2        FOR 
               Begin DoDot:1
 +3       ;--- Get IEN of the next registry record
 +4                SET IDESC("IEN")=$ORDER(^RORDATA(798,"B",IDESC("PATIEN"),IDESC("IEN")))
 +5                IF IDESC("IEN")'>0
                       SET RC="1^END"
                       QUIT 
 +6                if '$$ACTIVE^RORDD(IDESC("IEN"))
                       QUIT 
 +7       ;--- Load the registry IEN
 +8                SET RC=$PIECE($GET(^RORDATA(798,IDESC("IEN"),0)),U,2)
               End DoDot:1
               if $GET(RC)
                   QUIT 
 +9        QUIT $SELECT(RC="1^END":"",1:RC)
 +10      ;
 +11      ;***** CREATES AN ITERATOR OF PATIENTS IN THE REGISTRY
 +12      ;
 +13      ; .IDESC        Reference to a local variable where an iterator
 +14      ;               descriptor will be created
 +15      ; REGNAME       Registry name
 +16      ; [MODE]        Bit flags that define iteration mode (3 by default)
 +17      ;                 1  Active patients
 +18      ;                 2  Reserved
 +19      ;
 +20      ; Return Values:
 +21      ;       <0  Error code
 +22      ;        0  Ok
 +23      ;
PATITER(IDESC,REGNAME,MODE) ;
 +1        NEW REGIEN
           KILL IDESC
 +2       ;--- Get an IEN of the Registry Parameters
 +3        SET REGIEN=$$REGIEN^RORUTL02(REGNAME)
 +4        if REGIEN<0
               QUIT REGIEN
 +5       ;--- Setup the descriptor
 +6        SET MODE=$SELECT($GET(MODE):MODE,1:3)
 +7        SET IDESC("REGNAME")=REGNAME
 +8        SET IDESC("REGIEN")=REGIEN
 +9        SET IDESC("ACT")=MODE#2
 +10       SET IDESC("ROOT")=$$ROOT^DILFD(798,"",1)
 +11       SET IDESC("IEN")=0
 +12       QUIT 0
 +13      ;
 +14      ;***** CREATES AN ITERATOR OF THE PATIENT REGISTRIES
 +15      ;
 +16      ; .IDESC        Reference to a local variable where an iterator
 +17      ;               descriptor will be created
 +18      ; PATIEN        Patient IEN
 +19      ; [MODE]        Bit flags that define iteration mode (3 by default)
 +20      ;                 1  Registries where the patient is active
 +21      ;                 2  Reserved
 +22      ;
 +23      ; Return Values:
 +24      ;       <0  Error code
 +25      ;        0  Ok
 +26      ;
REGITER(IDESC,PATIEN,MODE) ;
 +1        KILL IDESC
 +2       ;--- Setup the descriptor
 +3        SET MODE=$SELECT($GET(MODE):MODE,1:3)
 +4        SET IDESC("PATIEN")=PATIEN
 +5        SET IDESC("ACT")=MODE#2
 +6        SET IDESC("ROOT")=$$ROOT^DILFD(798,"",1)
 +7        SET IDESC("IEN")=0
 +8        QUIT 0