RORRP041 ;HCIOFO/SG - RPC: REGISTRY-SPECIFIC LAB RESULTS ; 8/25/05 12:24pm
 ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
 ;
 Q
 ;
 ;***** LOADS AND PROCESSES CD4 AND VIRAL LOAD RESULTS
 ;
 ; .ROR8DST(     Reference to the Lab search descriptor.
 ;               See the $$LTSEARCH^RORUTL10 for details
 ;
 ;   "RORPTR")   Index of the last node in the destination buffer
 ;
 ;   "RORSTATS",
 ;     Group,
 ;       "LAST") Latest
 ;                 ^01: Result Value
 ;                 ^02: Date
 ;       "MAX")  Highest
 ;                 ^01: Result Value
 ;                 ^02: Date
 ;       "MIN")  Lowest
 ;                 ^01: Result Value
 ;                 ^02: Date
 ;
 ; INVDT         IEN of the Lab test (inverted date)
 ;
 ; .RESULT       Reference to a local variable, which contains the
 ;               result in the same format as it is stored into
 ;               the destination array by default.
 ;
 ; Return Values:
 ;       <0  Error code (the search will be aborted)
 ;        0  Ok
 ;        1  Skip this result
 ;        2  Skip this and all remaining results
 ;
LOADLT(ROR8DST,INVDT,RESULT) ;
 N BUF,GROUP,LTDT,LTVAL,TMP
 S LTDT=$P($G(RESULT(1)),U,2)    Q:LTDT'>0 1   ; Date of the test
 S LTVAL=$$TRIM^XLFSTR($P(RESULT(1),U,3))      ; Result value
 S GROUP=+$P($G(RESULT(2)),U,3)  Q:GROUP'>0 1  ; Code of the group
 ;
 ;=== Create and store the segment
 S BUF="LTR"_U_$P(RESULT(1),U)
 S $P(BUF,U,3,4)=LTDT_U_LTVAL
 S $P(BUF,U,5,8)=$P(RESULT(2),U,1,4)
 S ROR8DST("RORPTR")=$G(ROR8DST("RORPTR"))+1
 S @ROR8DST@(ROR8DST("RORPTR"))=BUF
 ;
 ;=== Most recent result of the group
 D:LTDT>$P($G(ROR8DST("RORSTATS",GROUP,"LAST")),U,2)
 . S ROR8DST("RORSTATS",GROUP,"LAST")=LTVAL_U_LTDT
 ;
 ;=== Numeric results
 D:$$NUMERIC^RORUTL05(LTVAL)
 . ;--- Lowest result value of the group
 . S TMP=+$G(ROR8DST("RORSTATS",GROUP,"MIN"))
 . S:'TMP!(LTVAL<TMP) ROR8DST("RORSTATS",GROUP,"MIN")=LTVAL_U_LTDT
 . ;--- Highest result value of the group
 . S TMP=+$G(ROR8DST("RORSTATS",GROUP,"MAX"))
 . S:LTVAL>TMP ROR8DST("RORSTATS",GROUP,"MAX")=LTVAL_U_LTDT
 ;
 ;=== Success
 Q 0
 ;
 ;***** LOADS THE PATIENT'S REGISTRY-SPECIFIC LAB RESULTS
 ; RPC: [ROR PATIENT REGISTRY LABS]
 ;
 ; .RESULTS      Reference to a local variable where the results
 ;               are returned to.
 ;
 ; REGIEN        Registry IEN
 ;
 ; PATIEN        IEN of the registry patient (DFN)
 ;
 ; Return Values:
 ;
 ; A negative value of the first "^"-piece of the RESULTS(0)
 ; indicates an error (see the RPCSTK^RORERR procedure for more
 ; details).
 ;
 ; Otherwise, zero is returned in the @RESULTS@(0) and the
 ; subsequent nodes of the global array contain the data.
 ; 
 ; @RESULTS@(0)          0
 ;
 ; @RESULTS@(i)          Registry-specific Lab Result
 ;                         ^01: "LTR"
 ;                         ^02: Result IEN (inverted date/time)
 ;                         ^03: Date/time of the test (FileMan)
 ;                         ^04: Result
 ;                         ^05: Test IEN (in file #60)
 ;                         ^06: Test name
 ;                         ^07: Code of the group
 ;                         ^08: Group name
 ;
 ; @RESULTS@(i)          Lab Group Statistics
 ;                         ^01: "LTG"
 ;                         ^02: Code of the group
 ;                         ^03: Group name
 ;                         ^04: Latest result value
 ;                         ^05: Date of the latest result (FileMan)
 ;                         ^06: Lowest result value
 ;                         ^07: Date of the lowest value (FileMan)
 ;
LOADPRL(RESULTS,REGIEN,PATIEN) ;
 N BUF,GRP,NAME,PTR,RC,RORBUF,RORERRDL,TMP
 D CLEAR^RORERR("LOAD^RORRP041",1)
 K RESULTS  S RESULTS=$$ALLOC^RORTMP()  S @RESULTS@(0)=0
 ;
 ;=== Check the parameters
 S RC=0  D  I RC<0  D RPCSTK^RORERR(.RESULTS,RC)  Q
 . ;--- Registry IEN
 . I $G(REGIEN)'>0  D  Q
 . . S RC=$$ERROR^RORERR(-88,,,,"REGIEN",$G(REGIEN))
 . S REGIEN=+REGIEN
 . ;--- Patient IEN
 . I $G(PATIEN)'>0  D  Q
 . . S RC=$$ERROR^RORERR(-88,,,,"PATIEN",$G(PATIEN))
 . S PATIEN=+PATIEN
 ;
 ;=== Search for registry-specific lab results
 S RORBUF=RESULTS
 S RORBUF("RORCB")="$$LOADLT^RORRP041"
 S RC=$$LTSEARCH^RORUTL10(PATIEN,+REGIEN,.RORBUF)
 I RC<0  D RPCSTK^RORERR(.RESULTS,RC)  Q
 ;
 ;=== Store the group statistics
 S PTR=+$O(@RESULTS@(""),-1)
 S GRP=0
 F  S GRP=$O(RORBUF("RORSTATS",GRP))  Q:GRP'>0  D
 . S TMP=$$ITEMIEN^RORUTL09(3,REGIEN,GRP,.NAME)
 . S BUF="LTG"_U_GRP_U_NAME
 . S $P(BUF,U,4,5)=$G(RORBUF("RORSTATS",GRP,"LAST"))
 . S $P(BUF,U,6,7)=$G(RORBUF("RORSTATS",GRP,"MIN"))
 . S PTR=PTR+1,@RESULTS@(PTR)=BUF
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HRORRP041   4720     printed  Sep 23, 2025@19:19:20                                                                                                                                                                                                    Page 2
RORRP041  ;HCIOFO/SG - RPC: REGISTRY-SPECIFIC LAB RESULTS ; 8/25/05 12:24pm
 +1       ;;1.5;CLINICAL CASE REGISTRIES;;Feb 17, 2006
 +2       ;
 +3        QUIT 
 +4       ;
 +5       ;***** LOADS AND PROCESSES CD4 AND VIRAL LOAD RESULTS
 +6       ;
 +7       ; .ROR8DST(     Reference to the Lab search descriptor.
 +8       ;               See the $$LTSEARCH^RORUTL10 for details
 +9       ;
 +10      ;   "RORPTR")   Index of the last node in the destination buffer
 +11      ;
 +12      ;   "RORSTATS",
 +13      ;     Group,
 +14      ;       "LAST") Latest
 +15      ;                 ^01: Result Value
 +16      ;                 ^02: Date
 +17      ;       "MAX")  Highest
 +18      ;                 ^01: Result Value
 +19      ;                 ^02: Date
 +20      ;       "MIN")  Lowest
 +21      ;                 ^01: Result Value
 +22      ;                 ^02: Date
 +23      ;
 +24      ; INVDT         IEN of the Lab test (inverted date)
 +25      ;
 +26      ; .RESULT       Reference to a local variable, which contains the
 +27      ;               result in the same format as it is stored into
 +28      ;               the destination array by default.
 +29      ;
 +30      ; Return Values:
 +31      ;       <0  Error code (the search will be aborted)
 +32      ;        0  Ok
 +33      ;        1  Skip this result
 +34      ;        2  Skip this and all remaining results
 +35      ;
LOADLT(ROR8DST,INVDT,RESULT) ;
 +1        NEW BUF,GROUP,LTDT,LTVAL,TMP
 +2       ; Date of the test
           SET LTDT=$PIECE($GET(RESULT(1)),U,2)
           if LTDT'>0
               QUIT 1
 +3       ; Result value
           SET LTVAL=$$TRIM^XLFSTR($PIECE(RESULT(1),U,3))
 +4       ; Code of the group
           SET GROUP=+$PIECE($GET(RESULT(2)),U,3)
           if GROUP'>0
               QUIT 1
 +5       ;
 +6       ;=== Create and store the segment
 +7        SET BUF="LTR"_U_$PIECE(RESULT(1),U)
 +8        SET $PIECE(BUF,U,3,4)=LTDT_U_LTVAL
 +9        SET $PIECE(BUF,U,5,8)=$PIECE(RESULT(2),U,1,4)
 +10       SET ROR8DST("RORPTR")=$GET(ROR8DST("RORPTR"))+1
 +11       SET @ROR8DST@(ROR8DST("RORPTR"))=BUF
 +12      ;
 +13      ;=== Most recent result of the group
 +14       if LTDT>$PIECE($GET(ROR8DST("RORSTATS",GROUP,"LAST")),U,2)
               Begin DoDot:1
 +15               SET ROR8DST("RORSTATS",GROUP,"LAST")=LTVAL_U_LTDT
               End DoDot:1
 +16      ;
 +17      ;=== Numeric results
 +18       if $$NUMERIC^RORUTL05(LTVAL)
               Begin DoDot:1
 +19      ;--- Lowest result value of the group
 +20               SET TMP=+$GET(ROR8DST("RORSTATS",GROUP,"MIN"))
 +21               if 'TMP!(LTVAL<TMP)
                       SET ROR8DST("RORSTATS",GROUP,"MIN")=LTVAL_U_LTDT
 +22      ;--- Highest result value of the group
 +23               SET TMP=+$GET(ROR8DST("RORSTATS",GROUP,"MAX"))
 +24               if LTVAL>TMP
                       SET ROR8DST("RORSTATS",GROUP,"MAX")=LTVAL_U_LTDT
               End DoDot:1
 +25      ;
 +26      ;=== Success
 +27       QUIT 0
 +28      ;
 +29      ;***** LOADS THE PATIENT'S REGISTRY-SPECIFIC LAB RESULTS
 +30      ; RPC: [ROR PATIENT REGISTRY LABS]
 +31      ;
 +32      ; .RESULTS      Reference to a local variable where the results
 +33      ;               are returned to.
 +34      ;
 +35      ; REGIEN        Registry IEN
 +36      ;
 +37      ; PATIEN        IEN of the registry patient (DFN)
 +38      ;
 +39      ; Return Values:
 +40      ;
 +41      ; A negative value of the first "^"-piece of the RESULTS(0)
 +42      ; indicates an error (see the RPCSTK^RORERR procedure for more
 +43      ; details).
 +44      ;
 +45      ; Otherwise, zero is returned in the @RESULTS@(0) and the
 +46      ; subsequent nodes of the global array contain the data.
 +47      ; 
 +48      ; @RESULTS@(0)          0
 +49      ;
 +50      ; @RESULTS@(i)          Registry-specific Lab Result
 +51      ;                         ^01: "LTR"
 +52      ;                         ^02: Result IEN (inverted date/time)
 +53      ;                         ^03: Date/time of the test (FileMan)
 +54      ;                         ^04: Result
 +55      ;                         ^05: Test IEN (in file #60)
 +56      ;                         ^06: Test name
 +57      ;                         ^07: Code of the group
 +58      ;                         ^08: Group name
 +59      ;
 +60      ; @RESULTS@(i)          Lab Group Statistics
 +61      ;                         ^01: "LTG"
 +62      ;                         ^02: Code of the group
 +63      ;                         ^03: Group name
 +64      ;                         ^04: Latest result value
 +65      ;                         ^05: Date of the latest result (FileMan)
 +66      ;                         ^06: Lowest result value
 +67      ;                         ^07: Date of the lowest value (FileMan)
 +68      ;
LOADPRL(RESULTS,REGIEN,PATIEN) ;
 +1        NEW BUF,GRP,NAME,PTR,RC,RORBUF,RORERRDL,TMP
 +2        DO CLEAR^RORERR("LOAD^RORRP041",1)
 +3        KILL RESULTS
           SET RESULTS=$$ALLOC^RORTMP()
           SET @RESULTS@(0)=0
 +4       ;
 +5       ;=== Check the parameters
 +6        SET RC=0
           Begin DoDot:1
 +7       ;--- Registry IEN
 +8            IF $GET(REGIEN)'>0
                   Begin DoDot:2
 +9                    SET RC=$$ERROR^RORERR(-88,,,,"REGIEN",$GET(REGIEN))
                   End DoDot:2
                   QUIT 
 +10           SET REGIEN=+REGIEN
 +11      ;--- Patient IEN
 +12           IF $GET(PATIEN)'>0
                   Begin DoDot:2
 +13                   SET RC=$$ERROR^RORERR(-88,,,,"PATIEN",$GET(PATIEN))
                   End DoDot:2
                   QUIT 
 +14           SET PATIEN=+PATIEN
           End DoDot:1
           IF RC<0
               DO RPCSTK^RORERR(.RESULTS,RC)
               QUIT 
 +15      ;
 +16      ;=== Search for registry-specific lab results
 +17       SET RORBUF=RESULTS
 +18       SET RORBUF("RORCB")="$$LOADLT^RORRP041"
 +19       SET RC=$$LTSEARCH^RORUTL10(PATIEN,+REGIEN,.RORBUF)
 +20       IF RC<0
               DO RPCSTK^RORERR(.RESULTS,RC)
               QUIT 
 +21      ;
 +22      ;=== Store the group statistics
 +23       SET PTR=+$ORDER(@RESULTS@(""),-1)
 +24       SET GRP=0
 +25       FOR 
               SET GRP=$ORDER(RORBUF("RORSTATS",GRP))
               if GRP'>0
                   QUIT 
               Begin DoDot:1
 +26               SET TMP=$$ITEMIEN^RORUTL09(3,REGIEN,GRP,.NAME)
 +27               SET BUF="LTG"_U_GRP_U_NAME
 +28               SET $PIECE(BUF,U,4,5)=$GET(RORBUF("RORSTATS",GRP,"LAST"))
 +29               SET $PIECE(BUF,U,6,7)=$GET(RORBUF("RORSTATS",GRP,"MIN"))
 +30               SET PTR=PTR+1
                   SET @RESULTS@(PTR)=BUF
               End DoDot:1
 +31       QUIT