YSCLTST6 ;HINOI/RBN-TRANSMISSION FOR REAL-TIME CLOZAPINE ORDERS (OUTPATIENT ;23 March 16
 ;;5.01;MENTAL HEALTH;**122**;Dec 30, 1994;Build 18
 ;
OUTPT ; Build outpatient clozapine data for transmision
 N PSOPAT,PSOIOF,YSCLCNTR,YSCLDFN
 S YSCLRET=""
 S PSOPAT=DFN
 S PSODFN=DFN
 S PSOIOF=IOF
 S YSCLCNTR=0
 S $P(^XTMP("YSCLTRN",0),"^",1)=DT+365,$P(^XTMP("YSCLTRN",0),"^",2)=DT ;_"^CLOZAPINE DAILY ROLLUP DATA"
 S:'$G(^XTMP("YSCLTRN",DT)) ^XTMP("YSCLTRN",DT)=0
 ; Get patient and facility demographic data
 D DMG^YSCLTST5
 D DMG1^YSCLTST5
 D GET^YSCLTST5
 S DFN=PSODFN
 S YSCL1=PSONEW("IRXN")
 S YSCLLD=PSOX("STOP DATE")
 D CHECK
 D LOAD
 ;/RBN - Removed because of change in requirement from real-time to daily (for now).
 ;D TRANSMIT^YSCLTST2  ; Real time transmit the data to NCCC
 S IOF=PSOIOF
 D END
 Q
 ;
CHECK ;for data to send
 K ^TMP($J),^TMP("YSCL",$J) S YSCLIEN=0
 S YSCLIEN=$O(^YSCL(603.01,"C",DFN,YSCLIEN)),YSCL=^DPT(DFN,0),YSCLX=$E($P($P(YSCL,"^"),",",2))_$E(YSCL)_"^"_$P(YSCL,"^",9)
 S YSCLPHY="",$P(YSCLX,"^",6)=$P(YSCLDEMO,"^",5),$P(YSCLX,"^",11)=$P($P($G(^YSCL(603.01,YSCLIEN,0)),"^"),"^"),$P(YSCLX,"^",16)=DT
 S YSCLT=0
 S $P(YSSTOP,",",3)=3 Q:$$S^%ZTLOAD
 S YSCLLD=$P(^PS(55,DFN,"SAND"),U,6) ;/RBN ADDED 04/12/2016
 K PNM,SEX,DOB,AGE,SSN D DEM^VADPT I 'VAERR S PNM=VADM(1),SEX=$P(VADM(5),U),DOB=$P(VADM(3),U),AGE=VADM(4),SSN=$P(VADM(2),U)
 I YSCLLD=0,$P($G(^PS(55,DFN,"SAND")),"^",2)="P" Q  ;no transmit for pretreatment
 I YSCLLD,YSCLLD<YSCLM56 S $P(^PS(55,DFN,"SAND"),"^",2)="D" ;force discontinued
 I YSCLLD,YSCLLD<YSCLM180 Q  ;Don't report if over 6 months old.
 S YSCLT=1,YSCLRX=$G(^PSRX(YSCL1,0)),YSCLRX2=$G(^PSRX(YSCL1,2)) ;we've got something
 S YSCL=$O(YSCLA("")) I 'YSCL D LAB S YSCLT=1 ;Q  ;get latest WBC results even if no script.
 S YSCLGL=$S($D(^PS(59)):"^PS",1:"^DIC")
 ;YSCLGL is used to indirectly hold the global reference for file 59. This is necessary due to changes in the file location. The $select may be expanded to cover future moves. DBIA 273-B
 S YSCLD=+$P($G(^PSRX(YSCL1,2)),"^",9),YSCLD=$G(@YSCLGL@(59,YSCLD,"SAND")),$P(YSCLX,"^",10)=$P(YSCLD,"^"),$P(YSCLX,"^",12)=$P(YSCLD,"^",2)
 ;site DEA# (p10), site pointer (p12)
 I YSCLLD<YSCLM7 S YSCLWBC="",$P(^PS(55,DFN,"SAND"),"^",2)="H",$P(YSCLX,"^",5)="H" ;Place on hold status
 ;here if active
 I $P(YSCLX,"^",5)'="H" S $P(^PS(55,DFN,"SAND"),"^",2)="A",$P(YSCLX,"^",5)="A" ;force active
 S $P(YSCLX,"^",13)=1,$P(YSCLX,"^",9)=$P(YSCLRX,"^",13),YSCLD1=$G(^PSRX(YSCL1,"SAND")),$P(YSCLX,"^",8)=+YSCLD1
 ;status(p5),dosage(p8),rx count(p13),issue date(p9)
 S YSCLLO=$O(^PS(52.52,"A",YSCL1,0)) I YSCLLO S YSCLLO=^PS(52.52,YSCLLO,0),$P(YSCLX,"^",14)=$P(YSCLLO,"^",5),YSCLLO=+$P(YSCLLO,"^",4),$P(YSCLX,"^",15)=$P(^VA(200,YSCLLO,0),"^")
 ;lockout reason (p14), approving official (p15)
 S $P(YSSTOP,",",4)=4 Q:$$S^%ZTLOAD
 S YSCLPHY=$G(^VA(200,+$P(YSCLRX,"^",4),0)),$P(YSCLX,"^",7)=$P($G(^VA(200,+$P(YSCLRX,"^",4),"PS")),"^",2),YSCLPHY=$P(YSCLPHY,"^")
 S $P(YSCLX,"^",4)=$P(YSCLD1,"^",2),$P(YSCLX,"^",3)=$P(YSCLD1,"^",3) I $P(YSCLD1,"^",2)]"",$P(YSCLD1,"^",3)'>YSCLED,$P(YSCLD1,"^",3)'<YSCLM7 S YSCLWBC=1
 ;wbc(p4),date(p3)
 ; add if prescription on same day for different drug and different dose
 S $P(YSCLX,"^",21)=$P(YSCLRX2,"^",7) ;Add NDC to string
 S ^XTMP("YSCLTRN",DT,DFN,PSOX("LOGIN DATE"),YSCLCNTR)=0
 S YSCLCNTR=YSCLCNTR+1
 S ^XTMP("YSCLTRN",DT,DFN,PSOX("LOGIN DATE"),YSCLCNTR)=YSCLX
 Q
 ;
LAB ;get most recent
 S $P(YSSTOP,",",5)=5 Q:$$S^%ZTLOAD
 S YSCLLDT="",J=9999998-YSCLED,K=9999998-YSCLM7 I $P(YSCLX,"^",9) S J=9999998-$P(YSCLX,"^",9)
 S YSCLR=$$CL^YSCLTST2(DFN) D  ;Set 3,4,17,19,20,22,23
  . S $P(YSCLX,"^",3)=$P(YSCLR,"^",6) ;WBC Date
  . S $P(YSCLX,"^",4)=$P(YSCLR,"^",2) ;WBC Results
  . S $P(YSCLX,"^",19)=$P(YSCLR,"^",6) ;ANC Date
  . S $P(YSCLX,"^",20)=$P(YSCLR,"^",4) ;ANC Results
  . S $P(YSCLX,"^",22)=$P(YSCLR,"^",3) ;WBC Name
  . S $P(YSCLX,"^",23)=$P(YSCLR,"^",5) ;ANC Name
 Q
 ;
LOAD ;
 S $P(YSSTOP,",",6)=6 Q:$$S^%ZTLOAD
 ; don't send for pretest or older that 28 days
 S YSCLNSTE=$P($G(^PS(59,+$P($G(^PSRX(YSCL1,2)),"^",9),0)),"^",6)
 S YSCLNST1=$P($$SITE^VASITE,"^",2),YSCLNSTE=$P($$SITE^VASITE,"^",3)
 S YSCLLN=YSCLLN+1,$P(YSCLX,"^",18)=YSCLRET,^TMP($J,YSCLLN,0)=YSCLX,YSCLLN=YSCLLN+1,^TMP($J,YSCLLN,0)=YSCLPHY_"^"_YSCLDEMO_"^"_YSCLNSTE_"^"_YSCLNST1
 S YSCLCNTR=YSCLCNTR+1
 S ^XTMP("YSCLTRN",DT,DFN,PSOX("LOGIN DATE"),YSCLCNTR)=^TMP($J,YSCLLN,0)
 ;site number and name
 S YSCLLLN=YSCLLLN+1,^TMP("YSCL",$J,YSCLLLN,0)=$P(^DPT(DFN,0),"^",9)_"   "_$P(^(0),"^")_"  (R) "_$S($P(YSCLX,"^",13)="":"NO RX   ",1:$$FMTE^XLFDT($P(YSCLX,"^",9),"D"))_" (W) "
 S ^TMP("YSCL",$J,YSCLLLN,0)=^TMP("YSCL",$J,YSCLLLN,0)_$S($P(YSCLX,"^",3)="":"NO WBC   ",1:$$FMTE^XLFDT($P(YSCLX,"^",3),"D"))_" (N) "_$S($P(YSCLX,"^",20)="":"NO NEUT  ",1:$$FMTE^XLFDT($P(YSCLX,"^",19),"D"))
 S YSCLCNTR=YSCLCNTR+1
 S ^XTMP("YSCLTRN",DT,DFN,PSOX("LOGIN DATE"),YSCLCNTR)=^TMP("YSCL",$J,YSCLLLN,0)
 ; Increment the counter for the date and the given patient
 S YSCLCNTR=YSCLCNTR+1
 S ^XTMP("YSCLTRN",DT,0)=+$G(^XTMP("YSCLTRN",DT,0))+1
 Q
 ;
END ; Clean up
 K ^TMP("YSCL"),^TMP("YSCLL")
 Q
 ;