PSUCS17 ;BIR/DJE,DJM - GENERATE PSU CS RECORDS (TYPE 17) ;25 AUG 1998
 ;;4.0;PHARMACY BENEFITS MANAGEMENT;;MARCH, 2005
 ;
 ;DBIA'S
 ; Reference to file #58.81 supported by DBIA 2520
 ; Reference to file #50    supported by DBIA 221
 ;
 ; ***
 ; TYPE 17 - "Logged for patient"
 ; ***
EN ;EP  scan the ^XTMP(job,"MC",loc,pat,drug,qt)=PSUIENDA
 ;  where type 17 were stored combining multiples for a patient
 S PSULOC="",PSUMCHK=0,PSUTYP=17
 F  S PSULOC=$O(^XTMP(PSUCSJB,"MC",PSULOC)) Q:PSULOC=""  D
 . S DFN=0
 . F  S DFN=$O(^XTMP(PSUCSJB,"MC",PSULOC,DFN)) Q:DFN'>0  D DRUG
 Q
DRUG ;EP loop drugs within patient
 S Z=0
 F  S Z=$O(^XTMP(PSUCSJB,"MC",PSULOC,DFN,Z)) Q:Z=""  S X=^(Z) D
 . S PSUPIEN(73)=DFN
 . S PSUIENDA=X,PSUDRG=Z
 . S PSUDTM(3)=$$VALI^PSUTL(58.81,PSUIENDA,3),SENDER=PSUSNDR
 . ;S PSURI="H"   DAM TEST
 . N Z
 . D TYP17
 . I 'PSUTQY(5) Q  ; do not send if QTY=0
 . D BUILDREC^PSUCS5
 . K PSUSSN,PSUPLC
 Q
 ;     
TYP17 ; Processing the transaction for dispensing type 17 
 ;('logged for patient'). If the dispensing type=17 and a patient IEN 
 ;is identified, one can use this information one find the ward location
 ;if the patient is still an inpatient when the extract is done.
 D FACILTY
 ;     
 ; (type 17 specific call)
 ; Patient SSN
 D SSN
 ;
 ; Generic name, Location type.
 D GNAME^PSUCS4,LOCTYP^PSUCS4
 ; Requirement 3.2.5.7
 Q:"N"'[PSULTP(1)
 ;
 ;
 ;VA Drug class, Formulary/Non-formulary, National formulary Indicator.
 D NDC^PSUCS4,FORMIND^PSUCS4,NFIND^PSUCS4
 ;
 ;(type 17 specific call)
 ; Dispense unit, unit cost, Quantity
 D DUNIT,UNITC,QTY17
 ;
 ; VA Product name, VA drug class, Packaging
 D VPNAME^PSUCS4,VDC^PSUCS4
 ;
 Q 
 ;
 ;
 ; 
 ; Type 17 specific calls
 ; 
 ;
 ;           
FACILTY ;
 D DIVISION^PSUCS2
 Q
 ;
SSN ;Field # 58.81,73 [PATIENT]  Points to File # 2
 ;Field # 2,.09 [SOCIAL SECURITY NUMBER]**Field to be extracted
 Q:$G(PSUPIEN(73))=""
 S DFN=PSUPIEN(73) D PID^VADPT
 S PSUSSN(.09)=$TR(VA("PID"),"-","")
 Q
 ; 
DUNIT ;Dispense Unit
 ;Field # 50,14.5 [DISPENSE UNIT]**Field to be extracted
 S PSUDUN(14.5)=$$VALI^PSUTL(50,PSUDRG(4),"14.5")
 S UNIT=PSUDUN(14.5)
 Q
 ;
UNITC ;Unit Cost
 ;Field # 50,16 [PRICE PER DISPENSE UNIT]**Field to be extracted
 S PSUPDU(16)=$$VALI^PSUTL(50,PSUDRG(4),"16")
 Q
 ;
QTY17 ;For transactions with a dispensing type =17, total the number of doses
 ;dispensed for the same drug (Field # 58.81,4), regardless of the date 
 ;dispensed within the reporting month. The dispensed (transaction) date
 ;will be the date the first dose was administered to the patient during
 ;the reporting period. The data will be transmitted as a single data
 ;record.
 ;Sum of Values # 58.81,5 [TOTAL QUANTITY]**Field to be extracted
 ;  Store in ^XTMP(job,"MC",loc,dfn,drg,qt)
 S PSUTQY(5)=^XTMP(PSUCSJB,"MC",PSULOC,DFN,PSUDRG,"QT")
 Q
 
--- Routine Detail   --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HPSUCS17   2896     printed  Sep 23, 2025@20:03:13                                                                                                                                                                                                     Page 2
PSUCS17   ;BIR/DJE,DJM - GENERATE PSU CS RECORDS (TYPE 17) ;25 AUG 1998
 +1       ;;4.0;PHARMACY BENEFITS MANAGEMENT;;MARCH, 2005
 +2       ;
 +3       ;DBIA'S
 +4       ; Reference to file #58.81 supported by DBIA 2520
 +5       ; Reference to file #50    supported by DBIA 221
 +6       ;
 +7       ; ***
 +8       ; TYPE 17 - "Logged for patient"
 +9       ; ***
EN        ;EP  scan the ^XTMP(job,"MC",loc,pat,drug,qt)=PSUIENDA
 +1       ;  where type 17 were stored combining multiples for a patient
 +2        SET PSULOC=""
           SET PSUMCHK=0
           SET PSUTYP=17
 +3        FOR 
               SET PSULOC=$ORDER(^XTMP(PSUCSJB,"MC",PSULOC))
               if PSULOC=""
                   QUIT 
               Begin DoDot:1
 +4                SET DFN=0
 +5                FOR 
                       SET DFN=$ORDER(^XTMP(PSUCSJB,"MC",PSULOC,DFN))
                       if DFN'>0
                           QUIT 
                       DO DRUG
               End DoDot:1
 +6        QUIT 
DRUG      ;EP loop drugs within patient
 +1        SET Z=0
 +2        FOR 
               SET Z=$ORDER(^XTMP(PSUCSJB,"MC",PSULOC,DFN,Z))
               if Z=""
                   QUIT 
               SET X=^(Z)
               Begin DoDot:1
 +3                SET PSUPIEN(73)=DFN
 +4                SET PSUIENDA=X
                   SET PSUDRG=Z
 +5                SET PSUDTM(3)=$$VALI^PSUTL(58.81,PSUIENDA,3)
                   SET SENDER=PSUSNDR
 +6       ;S PSURI="H"   DAM TEST
 +7                NEW Z
 +8                DO TYP17
 +9       ; do not send if QTY=0
                   IF 'PSUTQY(5)
                       QUIT 
 +10               DO BUILDREC^PSUCS5
 +11               KILL PSUSSN,PSUPLC
               End DoDot:1
 +12       QUIT 
 +13      ;     
TYP17     ; Processing the transaction for dispensing type 17 
 +1       ;('logged for patient'). If the dispensing type=17 and a patient IEN 
 +2       ;is identified, one can use this information one find the ward location
 +3       ;if the patient is still an inpatient when the extract is done.
 +4        DO FACILTY
 +5       ;     
 +6       ; (type 17 specific call)
 +7       ; Patient SSN
 +8        DO SSN
 +9       ;
 +10      ; Generic name, Location type.
 +11       DO GNAME^PSUCS4
           DO LOCTYP^PSUCS4
 +12      ; Requirement 3.2.5.7
 +13       if "N"'[PSULTP(1)
               QUIT 
 +14      ;
 +15      ;
 +16      ;VA Drug class, Formulary/Non-formulary, National formulary Indicator.
 +17       DO NDC^PSUCS4
           DO FORMIND^PSUCS4
           DO NFIND^PSUCS4
 +18      ;
 +19      ;(type 17 specific call)
 +20      ; Dispense unit, unit cost, Quantity
 +21       DO DUNIT
           DO UNITC
           DO QTY17
 +22      ;
 +23      ; VA Product name, VA drug class, Packaging
 +24       DO VPNAME^PSUCS4
           DO VDC^PSUCS4
 +25      ;
 +26       QUIT 
 +27      ;
 +28      ;
 +29      ; 
 +30      ; Type 17 specific calls
 +31      ; 
 +32      ;
 +33      ;           
FACILTY   ;
 +1        DO DIVISION^PSUCS2
 +2        QUIT 
 +3       ;
SSN       ;Field # 58.81,73 [PATIENT]  Points to File # 2
 +1       ;Field # 2,.09 [SOCIAL SECURITY NUMBER]**Field to be extracted
 +2        if $GET(PSUPIEN(73))=""
               QUIT 
 +3        SET DFN=PSUPIEN(73)
           DO PID^VADPT
 +4        SET PSUSSN(.09)=$TRANSLATE(VA("PID"),"-","")
 +5        QUIT 
 +6       ; 
DUNIT     ;Dispense Unit
 +1       ;Field # 50,14.5 [DISPENSE UNIT]**Field to be extracted
 +2        SET PSUDUN(14.5)=$$VALI^PSUTL(50,PSUDRG(4),"14.5")
 +3        SET UNIT=PSUDUN(14.5)
 +4        QUIT 
 +5       ;
UNITC     ;Unit Cost
 +1       ;Field # 50,16 [PRICE PER DISPENSE UNIT]**Field to be extracted
 +2        SET PSUPDU(16)=$$VALI^PSUTL(50,PSUDRG(4),"16")
 +3        QUIT 
 +4       ;
QTY17     ;For transactions with a dispensing type =17, total the number of doses
 +1       ;dispensed for the same drug (Field # 58.81,4), regardless of the date 
 +2       ;dispensed within the reporting month. The dispensed (transaction) date
 +3       ;will be the date the first dose was administered to the patient during
 +4       ;the reporting period. The data will be transmitted as a single data
 +5       ;record.
 +6       ;Sum of Values # 58.81,5 [TOTAL QUANTITY]**Field to be extracted
 +7       ;  Store in ^XTMP(job,"MC",loc,dfn,drg,qt)
 +8        SET PSUTQY(5)=^XTMP(PSUCSJB,"MC",PSULOC,DFN,PSUDRG,"QT")
 +9        QUIT