Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: APSPDR3

APSPDR3.m

Go to the documentation of this file.
APSPDR3 ;IHS/OHPRD/JCM - PHARMACY DRUG RECALL;10-Oct-2017 11:35;DU
 ;;7.0;IHS PHARMACY MODIFICATIONS;**1008,1009,1022**;Sep 23, 2004;Build 20
 ;THIS ROUTINE BUILDS THE PHARMACY DRUG RECALL LIST
 ; IHS/MSC/PLS - 01/02/09 - Routine updated
 ;               12/16/09 - Modified GETIEN1 call to GETIEN for File 50
 ;               10/10/17 - Removed trailing Q at SET+4
EN ;
 N APSPBD,APSPED,APSPBDF,APSPEDF,APSPDIV,APSPDRG,APSPDARY
 N QFLG,DCNT
 S (QFLG,DCNT)=0
 K ^TMP($J,"PSODR")
 W @IOF
 W !,"Pharmacy Drug Recall List",!!
 D ASKDATES^APSPUTIL(.APSPBD,.APSPED,.APSPQ,DT,DT)
 Q:APSPQ
 S APSPBDF=$P($TR($$FMTE^XLFDT(APSPBD,"5Z"),"@"," "),":",1,2)
 S APSPEDF=$P($TR($$FMTE^XLFDT(APSPED,"5Z"),"@"," "),":",1,2)
 S APSPBD=APSPBD-.01,APSPED=APSPED+.99
 ;SELECT DIVISION
 S APSPDIV=$$DIR^APSPUTIL("Y","Would you like all pharmacy divisions","Yes",,.APSPQ)
 Q:APSPQ
 I APSPDIV D
 .S APSPDIV="*"
 E  D  Q:APSPQ
 .S APSPDIV=$$GETIEN^APSPUTIL(59,"Select Pharmacy Division: ",.APSPQ)
 F  D  Q:QFLG
 .S APSPDRG=$$GETIEN^APSPUTIL(50,"Select Drug Name: ",,"QM")
 .I APSPDRG<1 S QFLG=1 Q
 .S APSPDARY(APSPDRG)=""
 .S DCNT=DCNT+1
 .S QFLG='$$DIR^APSPUTIL("Y","Want to Select Another Drug","No",,.APSPQ)
 .S:'QFLG QFLG=APSPQ
 Q:'DCNT
 D DEV
 Q
DEV ;
 N XBRP,XBNS
 S XBRP="OUT^APSPDR3"
 S XBNS="APS*"
 D ^XBDBQUE
 Q
OUT ;
 N APSPDT,RXIEN,APSPNOD,FTYPE,DRG
 S APSPDT=APSPBD F  S APSPDT=$O(^PSRX("ZAL",APSPDT)) Q:'APSPDT!(APSPDT>APSPED)  D
 .S RXIEN=0 F  S RXIEN=$O(^PSRX("ZAL",APSPDT,RXIEN)) Q:'RXIEN  D
 ..S APSPNOD=0 F  S APSPNOD=$O(^PSRX("ZAL",APSPDT,RXIEN,APSPNOD)) Q:'APSPNOD  D
 ...S FTYPE="" F  S FTYPE=$O(^PSRX("ZAL",APSPDT,RXIEN,APSPNOD,FTYPE)) Q:FTYPE=""  D CHECK
 D EN^APSPDR4
 Q
CHECK ;EP
 N DIV
 Q:'$D(^PSRX(RXIEN,0))
 S DRG=$P($G(^PSRX(RXIEN,0)),U,6)
 Q:'DRG  ; Must have a drug
 Q:'$D(^PSDRUG(DRG,0))
 Q:'$D(APSPDARY(DRG))  ; Not a selected drug
 S DIV=$$GET1^DIQ($S(FTYPE="P":52.2,FTYPE="R":52.1,1:52),$S("PR"[FTYPE:APSPNOD_","_RXIEN_",",1:RXIEN),$S(FTYPE="P":.09,FTYPE="R":8,1:20),"I")  ; Pharmacy Division IEN
 Q:'$$DIVVRY(DIV,APSPDIV)  ; Check Division
 D SET(RXIEN,DRG,DIV)
 Q
 ; Return boolean flag indicating valid pharmacy division
DIVVRY(RXDIV,RPTDIV) ;EP
 Q:RPTDIV="*" 1
 Q RXDIV=RPTDIV
 ;
SET(RX,DRG,DIV) ;EP
 N STA,RXN,DFN,QTY,DRGNM,NXT
 S STA=$P($G(^PSRX(RX,"STA")),U)
 Q:STA=13  ; Prescription marked as deleted
 ;IHS/MSC/PLS - 10/10/2017
 ;Q:FTYPE="N"&($P($G(^PSRX(RX,2)),U,15)) Q  ; Prescription has been returned to stock
 Q:FTYPE="N"&($P($G(^PSRX(RX,2)),U,15))  ; Prescription has been returned to stock
 S NXT=$O(^TMP($J,"DATA",$C(1)),-1)
 S NXT=NXT+1
 S RXN=$P(^PSRX(RX,0),U) ;PRESCRIPTION NUMBER ON FILE
 S DFN=$P(^PSRX(RX,0),U,2) ;PATIENT NUMBER FOR THE PERSON FILE
 S QTY=$$GET1^DIQ($S(FTYPE="P":52.2,FTYPE="R":52.1,1:52),$S("PR"[FTYPE:APSPNOD_","_RX_",",1:RX),$S(FTYPE="P":.04,FTYPE="R":1,1:7))
 S DRGNM=$P(^PSDRUG(DRG,0),U) ;DRUG NAME
 S ^TMP($J,"PSODR",DIV,DFN,APSPDT,RX,NXT)=""
 S ^TMP($J,"DATA",NXT)=DIV_U_APSPDT_U_DRGNM_U_QTY_U_RXN
 Q