PSOVCC1 ;ORLFO/WLC - PSO VCC RPC CALLS ; Mar 20, 2023@12:57:56
 ;;7.0;OUTPATIENT PHARMACY;**707**;DEC 1997;Build 18
 ;
 ; External calls:
 ;
 ; Description       ICR     Notes
 ; -----------       ------  -------
 ; Reference to ENCODE^XLFJSON in #6682
 ; Reference to GET^DDE in #7008
 ; Reference to FMTHL7^XLFDT, HTFM^XLFDT in #10103
 ; 
 ; 
RFIL(PSOVO,PSOVIEN) ; retrieve ENTITY data for Refill Log (#52.1)
 ; inside a PRESCRIPTION (#52) file entry.
 ;
 ; INPUT:
 ;     PSOVIEN = External # of Prescription
 ; OUTPUT:
 ;     PSOVO(0) - Return value:
 ;            1 = Success, array of values returned in JSON format.
 ;           -1^error message for failure
 ;     PSOVO(1) = Array of values from REFILLS Log
 ;
 N CT,DDEY,ERR,PIEN
 I $G(PSOVIEN)']"" D NORXNER("-1^ Prescription Number is Required") Q
 I '$$RXVAL^PSOUTCRM(PSOVIEN) D NORXNER("-2^ Prescription Number is not recognized") Q
 S PIEN=$O(^TMP($J,"PSOV",-1))
 K PSOVO,ERR D GET^DDE("PSO REFILL LOG",PIEN,,0,,"PSOVO","ERR")
 I $D(ERR) D NORXNER("-1^Error in Retrieval") Q
 I $L(PSOVO(1),"}")<3 D NORXNER("0^No data - there are no REFILL LOG entries for this prescription") Q
 D TIDY^PSOVCC0
 Q
 ;----------
 ; 
ACT(PSOVO,PSOVIEN) ; Activity Log from PRESCRIPTION (#52) file.
 ;
 ;     INPUT:
 ;          PSOVIEN - External # OF PRESCRIPTION (#52) file entry.
 ;     OUTPUT:
 ;          PSOVO(0) - Return value
 ;           1 = Success
 ;          -1^Error message for failure
 ;          PSOVO(1) = Array of values from ACTIVITY Log
 ;
 N CT,DDEY,ERR,JSONER,OC,OD,PIEN,RETVAR,V
 I $G(PSOVIEN)']"" D NORXNER("-1^ Prescription Number is Required") Q
 I '$$RXVAL^PSOUTCRM(PSOVIEN) D NORXNER("-2^ Prescription Number is not recognized") Q
 S PIEN=$O(^TMP($J,"PSOV",-1))
 D GET^DDE("PSO ACTIVITY LOG",PIEN,,0,,"PSOVO","ERR")
 I $L(PSOVO(1),"}")<3 D NORXNER("0^No data - there are no ACTIVITY LOG entries for this prescription") Q
 D TIDY^PSOVCC0
 Q
 ;
 ; ----------
CMOP(PSOVO,PSOVIEN)  ; List CMOP Log
 ;
 ;     INPUT:
 ;          PSOVIEN - External # OF PRESCRIPTION (#52) file entry.
 ;     OUTPUT:
 ;          PSOVO(0) - Return Value: 
 ;            1 for success
 ;           -1^error message for failure
 ;          PSOVO(1) = Array of values from CMOP Log
 ;
 N CT,DDEY,ERR,OC,OD,PIEN,RETVAR,V
 I $G(PSOVIEN)']"" D NORXNER("-1^ Prescription Number is Required") Q
 I '$$RXVAL^PSOUTCRM(PSOVIEN) D NORXNER("-2^ Prescription Number is not recognized") Q
 S PIEN=$O(^TMP($J,"PSOV",-1))
 D GET^DDE("PSO CMOP M",PIEN,,0,,"PSOVO","ERR")
 I $D(ERR) D NORXNER("-1^Error in Retrieval") Q
 I $L(PSOVO(1),"}")<3 D NORXNER("0^No data - there are no CMOP entries for this prescription") Q
 D TIDY^PSOVCC0
 Q
 ;
 ; -------
 ;
PART(PSOVO,PSOVIEN)  ; Partial log
 ;
 ; INPUT:
 ;   PSOVIEN - External # of PRESCRIPTION (#52) file entry.
 ; OUTPUT:
 ;          PSOVO(0) - Return Value: 
 ;            1 for success
 ;           -1^error message for failure
 ;          PSOVO(1) - Array of values from PARTIALS Log
 ;
 N CT,DDEY,ERR,PIEN,RETVAR,V
 I $G(PSOVIEN)']"" D NORXNER("-1^ Prescription Number is Required") Q
 I '$$RXVAL^PSOUTCRM(PSOVIEN) D NORXNER("-2^ Prescription Number is not recognized") Q
 S PIEN=$O(^TMP($J,"PSOV",-1))
 D GET^DDE("PSO PARTIALS LOG",PIEN,,0,,"PSOVO","ERR")
 I $D(ERR) D NORXNER("-1^Error in Retrieval") Q
 I $L(PSOVO(1),"}")<3 D NORXNER("0^No data - there are no PARTIAL entries for this prescription") Q
 D TIDY^PSOVCC0
 Q
 ;
 ; -------
 ;
COPAY(PSOVO,PSOVIEN) ; COPAY transaction log
 ;
 ; INPUT:
 ;   PSOVIEN - External # of PRESCRIPTION (#52) file.
 ; OUTPUT:
 ;          PSOVO(0) - Return Value:
 ;            1 for success
 ;           -1^error message for failure
 ;          PSOVO(1) - Array of values from COPAY Log
 ;
 N CT,DDEY,ERR,PIEN,RETVAR,V
 S PSOVO(0)=0,PIEN=0
 I $G(PSOVIEN)']"" D NORXNER("-1^ Prescription Number is Required") Q
 I '$$RXVAL^PSOUTCRM(PSOVIEN) D NORXNER("-2^ Prescription Number is not recognized") Q
 S PIEN=$O(^TMP($J,"PSOV",-1))
 D GET^DDE("PSO COPAY LOG",PIEN,,0,,"PSOVO","ERR")
 I $D(ERR) D NORXNER("-1^Error in Retrieval") Q
 I $L(PSOVO(1),"}")<3 D NORXNER("0^No data - there are no COPAY entries for this prescription") Q
 D TIDY^PSOVCC0
 Q
  ;
 ; -------
 ;
LABEL(PSOVO,PSOVIEN)  ; Labels Log
 ;
 ; INPUT:
 ;   PSOVIEN - External # of PRESCRIPTION (#52) file.
 ; OUTPUT:
 ;          PSOVO(0) - Return Value:
 ;            1 for success
 ;           -1^error message for failure
 ;          PSOVO(1) - Array of values from LABELS Log
 ;
 N CT,DDEY,ERR,PIEN
 I $G(PSOVIEN)']"" D NORXNER("-1^ Prescription Number is Required") Q
 I '$$RXVAL^PSOUTCRM(PSOVIEN) D NORXNER("-2^ Prescription Number is not recognized") Q
 S PIEN=$O(^TMP($J,"PSOV",-1))
 D GET^DDE("PSO LABEL LOG",PIEN,,0,,"PSOVO","ERR")
 I $D(ERR) D NORXNER("-1^Error in Retrieval") Q
 I $L(PSOVO(1),"}")<3 D NORXNER("0^No data - there are no LABEL entries for this prescription") Q
 D TIDY^PSOVCC0
 Q
 ;
 ; -------
 ;
NORXNER(ERROR) ; handle messages for input parameter issue or no data
 ;
 N ZXC,DDEY
 S DDEY="PSOVO"
 S ECMER=ERROR
 D MERGE(0)
 K PSOVO(0)
 K PSOVO(1)
 D ENCODE^XLFJSON("ECM",.DDEY)
 S ZXC=@(DDEY_"(1)")
 S ZXC=$$SWAP^PSOUTCRM(ZXC,"\/","/")
 S @DDEY=ZXC
 K ECM,ECMER
 Q
 ;
MERGE(CT) ; merge into output array as json
 ;
 M ECM("data","items")=ECMER
 S ECM("data","updated")=$$FMTHL7^XLFDT($$HTFM^XLFDT($H))
 S ECM("data","total items")=CT
 Q
 ;
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSOVCC1   5509     printed  Sep 23, 2025@20:12:38                                                                                                                                                                                                     Page 2
PSOVCC1   ;ORLFO/WLC - PSO VCC RPC CALLS ; Mar 20, 2023@12:57:56
 +1       ;;7.0;OUTPATIENT PHARMACY;**707**;DEC 1997;Build 18
 +2       ;
 +3       ; External calls:
 +4       ;
 +5       ; Description       ICR     Notes
 +6       ; -----------       ------  -------
 +7       ; Reference to ENCODE^XLFJSON in #6682
 +8       ; Reference to GET^DDE in #7008
 +9       ; Reference to FMTHL7^XLFDT, HTFM^XLFDT in #10103
 +10      ; 
 +11      ; 
RFIL(PSOVO,PSOVIEN) ; retrieve ENTITY data for Refill Log (#52.1)
 +1       ; inside a PRESCRIPTION (#52) file entry.
 +2       ;
 +3       ; INPUT:
 +4       ;     PSOVIEN = External # of Prescription
 +5       ; OUTPUT:
 +6       ;     PSOVO(0) - Return value:
 +7       ;            1 = Success, array of values returned in JSON format.
 +8       ;           -1^error message for failure
 +9       ;     PSOVO(1) = Array of values from REFILLS Log
 +10      ;
 +11       NEW CT,DDEY,ERR,PIEN
 +12       IF $GET(PSOVIEN)']""
               DO NORXNER("-1^ Prescription Number is Required")
               QUIT 
 +13       IF '$$RXVAL^PSOUTCRM(PSOVIEN)
               DO NORXNER("-2^ Prescription Number is not recognized")
               QUIT 
 +14       SET PIEN=$ORDER(^TMP($JOB,"PSOV",-1))
 +15       KILL PSOVO,ERR
           DO GET^DDE("PSO REFILL LOG",PIEN,,0,,"PSOVO","ERR")
 +16       IF $DATA(ERR)
               DO NORXNER("-1^Error in Retrieval")
               QUIT 
 +17       IF $LENGTH(PSOVO(1),"}")<3
               DO NORXNER("0^No data - there are no REFILL LOG entries for this prescription")
               QUIT 
 +18       DO TIDY^PSOVCC0
 +19       QUIT 
 +20      ;----------
 +21      ; 
ACT(PSOVO,PSOVIEN) ; Activity Log from PRESCRIPTION (#52) file.
 +1       ;
 +2       ;     INPUT:
 +3       ;          PSOVIEN - External # OF PRESCRIPTION (#52) file entry.
 +4       ;     OUTPUT:
 +5       ;          PSOVO(0) - Return value
 +6       ;           1 = Success
 +7       ;          -1^Error message for failure
 +8       ;          PSOVO(1) = Array of values from ACTIVITY Log
 +9       ;
 +10       NEW CT,DDEY,ERR,JSONER,OC,OD,PIEN,RETVAR,V
 +11       IF $GET(PSOVIEN)']""
               DO NORXNER("-1^ Prescription Number is Required")
               QUIT 
 +12       IF '$$RXVAL^PSOUTCRM(PSOVIEN)
               DO NORXNER("-2^ Prescription Number is not recognized")
               QUIT 
 +13       SET PIEN=$ORDER(^TMP($JOB,"PSOV",-1))
 +14       DO GET^DDE("PSO ACTIVITY LOG",PIEN,,0,,"PSOVO","ERR")
 +15       IF $LENGTH(PSOVO(1),"}")<3
               DO NORXNER("0^No data - there are no ACTIVITY LOG entries for this prescription")
               QUIT 
 +16       DO TIDY^PSOVCC0
 +17       QUIT 
 +18      ;
 +19      ; ----------
CMOP(PSOVO,PSOVIEN) ; List CMOP Log
 +1       ;
 +2       ;     INPUT:
 +3       ;          PSOVIEN - External # OF PRESCRIPTION (#52) file entry.
 +4       ;     OUTPUT:
 +5       ;          PSOVO(0) - Return Value: 
 +6       ;            1 for success
 +7       ;           -1^error message for failure
 +8       ;          PSOVO(1) = Array of values from CMOP Log
 +9       ;
 +10       NEW CT,DDEY,ERR,OC,OD,PIEN,RETVAR,V
 +11       IF $GET(PSOVIEN)']""
               DO NORXNER("-1^ Prescription Number is Required")
               QUIT 
 +12       IF '$$RXVAL^PSOUTCRM(PSOVIEN)
               DO NORXNER("-2^ Prescription Number is not recognized")
               QUIT 
 +13       SET PIEN=$ORDER(^TMP($JOB,"PSOV",-1))
 +14       DO GET^DDE("PSO CMOP M",PIEN,,0,,"PSOVO","ERR")
 +15       IF $DATA(ERR)
               DO NORXNER("-1^Error in Retrieval")
               QUIT 
 +16       IF $LENGTH(PSOVO(1),"}")<3
               DO NORXNER("0^No data - there are no CMOP entries for this prescription")
               QUIT 
 +17       DO TIDY^PSOVCC0
 +18       QUIT 
 +19      ;
 +20      ; -------
 +21      ;
PART(PSOVO,PSOVIEN) ; Partial log
 +1       ;
 +2       ; INPUT:
 +3       ;   PSOVIEN - External # of PRESCRIPTION (#52) file entry.
 +4       ; OUTPUT:
 +5       ;          PSOVO(0) - Return Value: 
 +6       ;            1 for success
 +7       ;           -1^error message for failure
 +8       ;          PSOVO(1) - Array of values from PARTIALS Log
 +9       ;
 +10       NEW CT,DDEY,ERR,PIEN,RETVAR,V
 +11       IF $GET(PSOVIEN)']""
               DO NORXNER("-1^ Prescription Number is Required")
               QUIT 
 +12       IF '$$RXVAL^PSOUTCRM(PSOVIEN)
               DO NORXNER("-2^ Prescription Number is not recognized")
               QUIT 
 +13       SET PIEN=$ORDER(^TMP($JOB,"PSOV",-1))
 +14       DO GET^DDE("PSO PARTIALS LOG",PIEN,,0,,"PSOVO","ERR")
 +15       IF $DATA(ERR)
               DO NORXNER("-1^Error in Retrieval")
               QUIT 
 +16       IF $LENGTH(PSOVO(1),"}")<3
               DO NORXNER("0^No data - there are no PARTIAL entries for this prescription")
               QUIT 
 +17       DO TIDY^PSOVCC0
 +18       QUIT 
 +19      ;
 +20      ; -------
 +21      ;
COPAY(PSOVO,PSOVIEN) ; COPAY transaction log
 +1       ;
 +2       ; INPUT:
 +3       ;   PSOVIEN - External # of PRESCRIPTION (#52) file.
 +4       ; OUTPUT:
 +5       ;          PSOVO(0) - Return Value:
 +6       ;            1 for success
 +7       ;           -1^error message for failure
 +8       ;          PSOVO(1) - Array of values from COPAY Log
 +9       ;
 +10       NEW CT,DDEY,ERR,PIEN,RETVAR,V
 +11       SET PSOVO(0)=0
           SET PIEN=0
 +12       IF $GET(PSOVIEN)']""
               DO NORXNER("-1^ Prescription Number is Required")
               QUIT 
 +13       IF '$$RXVAL^PSOUTCRM(PSOVIEN)
               DO NORXNER("-2^ Prescription Number is not recognized")
               QUIT 
 +14       SET PIEN=$ORDER(^TMP($JOB,"PSOV",-1))
 +15       DO GET^DDE("PSO COPAY LOG",PIEN,,0,,"PSOVO","ERR")
 +16       IF $DATA(ERR)
               DO NORXNER("-1^Error in Retrieval")
               QUIT 
 +17       IF $LENGTH(PSOVO(1),"}")<3
               DO NORXNER("0^No data - there are no COPAY entries for this prescription")
               QUIT 
 +18       DO TIDY^PSOVCC0
 +19       QUIT 
 +20      ;
 +21      ; -------
 +22      ;
LABEL(PSOVO,PSOVIEN) ; Labels Log
 +1       ;
 +2       ; INPUT:
 +3       ;   PSOVIEN - External # of PRESCRIPTION (#52) file.
 +4       ; OUTPUT:
 +5       ;          PSOVO(0) - Return Value:
 +6       ;            1 for success
 +7       ;           -1^error message for failure
 +8       ;          PSOVO(1) - Array of values from LABELS Log
 +9       ;
 +10       NEW CT,DDEY,ERR,PIEN
 +11       IF $GET(PSOVIEN)']""
               DO NORXNER("-1^ Prescription Number is Required")
               QUIT 
 +12       IF '$$RXVAL^PSOUTCRM(PSOVIEN)
               DO NORXNER("-2^ Prescription Number is not recognized")
               QUIT 
 +13       SET PIEN=$ORDER(^TMP($JOB,"PSOV",-1))
 +14       DO GET^DDE("PSO LABEL LOG",PIEN,,0,,"PSOVO","ERR")
 +15       IF $DATA(ERR)
               DO NORXNER("-1^Error in Retrieval")
               QUIT 
 +16       IF $LENGTH(PSOVO(1),"}")<3
               DO NORXNER("0^No data - there are no LABEL entries for this prescription")
               QUIT 
 +17       DO TIDY^PSOVCC0
 +18       QUIT 
 +19      ;
 +20      ; -------
 +21      ;
NORXNER(ERROR) ; handle messages for input parameter issue or no data
 +1       ;
 +2        NEW ZXC,DDEY
 +3        SET DDEY="PSOVO"
 +4        SET ECMER=ERROR
 +5        DO MERGE(0)
 +6        KILL PSOVO(0)
 +7        KILL PSOVO(1)
 +8        DO ENCODE^XLFJSON("ECM",.DDEY)
 +9        SET ZXC=@(DDEY_"(1)")
 +10       SET ZXC=$$SWAP^PSOUTCRM(ZXC,"\/","/")
 +11       SET @DDEY=ZXC
 +12       KILL ECM,ECMER
 +13       QUIT 
 +14      ;
MERGE(CT) ; merge into output array as json
 +1       ;
 +2        MERGE ECM("data","items")=ECMER
 +3        SET ECM("data","updated")=$$FMTHL7^XLFDT($$HTFM^XLFDT($HOROLOG))
 +4        SET ECM("data","total items")=CT
 +5        QUIT 
 +6       ;