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

PSSDSAPI.m

Go to the documentation of this file.
PSSDSAPI ;BIR/RTR-Dose Check APIs routine ;06/09/08
 ;;1.0;PHARMACY DATA MANAGEMENT;**117,160,173,178,206,224**;9/30/97;Build 3
 ;
EXMT(PSSVLIEN) ;Test if Drug should have Dose Call performed on it
 ;PSSVLIEN=File 50 internal entry number 
 ;1=exempt from Dose Check, 0=not exempt from Dose check
 N PSSVLND,PSSVLND1,PSSVLND3,PSSVLNDF,PSSVLDOV,PSSVLZR,PSSVLDF
 S PSSVLZR=$G(^PSDRUG(PSSVLIEN,0))
 I $P(PSSVLZR,"^",3)["S"!($E($P(PSSVLZR,"^",2),1,2)="XA") Q 1
 S PSSVLND=$G(^PSDRUG(PSSVLIEN,"ND"))
 S PSSVLND1=$P(PSSVLND,"^"),PSSVLND3=$P(PSSVLND,"^",3)
 S PSSVLDOV="" K PSSVLDF
 I $T(OVRIDE^PSNAPIS)]"",PSSVLND1,PSSVLND3 S PSSVLDOV=$$OVRIDE^PSNAPIS(PSSVLND1,PSSVLND3)
 I PSSVLND1,PSSVLND3 S PSSVLNDF=$$DFSU^PSNAPIS(PSSVLND1,PSSVLND3) S PSSVLDF=$P(PSSVLNDF,"^")
 I $G(PSSVLDF)'>0,$P($G(^PSDRUG(PSSVLIEN,2)),"^") S PSSVLDF=$P($G(^PS(50.7,+$P($G(^PSDRUG(PSSVLIEN,2)),"^"),0)),"^",2)
 I PSSVLDOV=""!('$G(PSSVLDF))!($P($G(^PS(50.606,+$G(PSSVLDF),1)),"^")="") Q 0
 I $P($G(^PS(50.606,+$G(PSSVLDF),1)),"^"),'PSSVLDOV Q 1
 I '$P($G(^PS(50.606,+$G(PSSVLDF),1)),"^"),PSSVLDOV Q 1
 Q 0
 ;
 ;
SUP(PSSSPLIN) ;Screen for Drug Interaction and Duplicate Therapy
 ;PSSSPLIN = File 50 internal entry number
 ;1=exempt, 0=not exempt
 N PSSSPLZR
 S PSSSPLZR=$G(^PSDRUG(PSSSPLIN,0))
 I $P(PSSSPLZR,"^",3)["S"!($E($P(PSSSPLZR,"^",2),1,2)="XA") Q 1
 Q 0
 ;
 ;
MRT(PSSRS1) ;Return Standard Medication Route and First DataBank Route
 N PSSRS2,PSSRS3,PSSRS4,PSSRTNAM,PSSRTIEN,PSSRTARR,PSSPKGU,PSSRS4SM I '$G(PSSRS1) S PSSRS2="" G MRTX
 S (PSSRTNAM,PSSRTIEN,PSSRS2,PSSRS4,PSSRS4SM)="",PSSRTNAM=$$GET1^DIQ(51.2,PSSRS1,.01) I $G(PSSRTNAM)="" S PSSRS2="" G MRTX
 F  S PSSRTIEN=$O(^PS(51.2,"B",PSSRTNAM,PSSRTIEN)) Q:PSSRTIEN=""  D  ;check for duplicate route names; if mapped, defined and has a valid effective date set array
 .S PSSRS3="",PSSRS3=$P($G(^PS(51.2,PSSRTIEN,1)),"^")
 .Q:'$G(PSSRS3)
 .Q:'$D(^PS(51.23,+PSSRS3,0))
 .Q:$$SCREEN^XTID(51.23,.01,+PSSRS3_",")
 .S PSSPKGU="",PSSPKGU=$$GET1^DIQ(51.2,PSSRTIEN,3,"I") S:PSSPKGU="" PSSPKGU=0 S PSSRTARR(PSSPKGU,PSSRTIEN)=+PSSRS3
 ;If duplicate route names, select 1st "ALL Package" route for PACKAGE USE field in file 51.2.  If no "ALL Package" route, select 1st "NDF Only" route.  Otherwise, return nothing to indicate "invalid or undefined" route.
 ;If no duplicate route names, use the route passed in regardless of Packge Use value but only if mapped to route has valid effective date.
 I $D(PSSRTARR) D
 .I $D(PSSRTARR(1)) S PSSRS4=$O(PSSRTARR(1,PSSRS4)),PSSRS4SM=PSSRTARR(1,PSSRS4) Q
 .S:$D(PSSRTARR(0)) PSSRS4=$O(PSSRTARR(0,PSSRS4)),PSSRS4SM=PSSRTARR(0,PSSRS4)
 I PSSRS4="" G MRTX
 S PSSRS2=$G(^PS(51.23,+PSSRS4SM,0))
MRTX ;
 Q $P(PSSRS2,"^")_"^"_$P(PSSRS2,"^",2)
 ;
 ;
UNIT(PSSVUTUN) ;Find First DataBank Unit, can't do DIC Lookup because of exact match check
 ;Returns Null or First DataBank Unit for text passed in
 N PSSVUTX,PSSVUTZ,PSSVUTAA,PSSVUTFL
 S PSSVUTFL=0 I $G(PSSVUTUN)="" S PSSVUTZ="" G UNITX
 S PSSVUTAA=$$UP^XLFSTR(PSSVUTUN)
UNITP ;
 K PSSVUTZ S PSSVUTX=$O(^PS(51.24,"B",PSSVUTAA,0)) I PSSVUTX,'$$SCREEN^XTID(51.24,.01,PSSVUTX_",") S PSSVUTZ=$P($G(^PS(51.24,PSSVUTX,0)),"^",2) I PSSVUTZ'="" G UNITX
 K PSSVUTZ S PSSVUTX=$O(^PS(51.24,"C",PSSVUTAA,0)) I PSSVUTX,'$$SCREEN^XTID(51.24,.01,PSSVUTX_",") S PSSVUTZ=$P($G(^PS(51.24,PSSVUTX,0)),"^",2) I PSSVUTZ'="" G UNITX
 K PSSVUTZ S PSSVUTX=$O(^PS(51.24,"D",PSSVUTAA,0)) I PSSVUTX,'$$SCREEN^XTID(51.24,.01,PSSVUTX_",") S PSSVUTZ=$P($G(^PS(51.24,PSSVUTX,0)),"^",2) I PSSVUTZ'="" G UNITX
 I 'PSSVUTFL,$G(PSSVUTUN)["/" S PSSVUTFL=1,PSSVUTAA=$P(PSSVUTUN,"/"),PSSVUTAA=$$UP^XLFSTR(PSSVUTAA) G:PSSVUTAA'="" UNITP
UNITX ;
 Q $G(PSSVUTZ)
 ;
 ;
FRQ(PSSFWSCC,PSSFWFR,PSSFWPK,PSSFWDRL,PSSDRG) ;Return Daily Frequency for Daily Dose Check
 ;
 ;Input variables:
 ;PSSFWSC = Free Text Schedule
 ;PSSFWFR = Frequency in Minutes
 ;PSSFWPK = Package  "O" for Outpatient, "I" for Inpatient
 ;PSSFWDRL = Duration
 ;PSSDRG = IEN from file 50 (added for MOCHA 2.1-PSS*1*178)
 ;Output: 2 pieces (More information see Forum DBIA 5425)
 ;piece 1 - Adjusted Daily Frequency, (May need adjusted if Duration is passed in)
 ;piece 2 - Daily Frequency solely based on Schedule
 ;
 N PSSFWPR1,PSSFWPR2,PSSFWPR3,PSSFWPR4,PSSFWPR5,PSSFWPR6,PSSFWPR7,PSSOSN,PSSOMEDN,PSSX,PSSDECNO,PSSMLTFG
 I $G(PSSFWSCC)="" Q "^"
 S PSSX=$$OLDSCH^PSSSCHMS(PSSFWSCC),PSSFWSCC=$P(PSSX,U),PSSOSN=$P(PSSX,U,2)
 S PSSFWPR1=0
 S PSSFWPR2=$$FRQZ
 I '$G(PSSMLTFG),($G(PSSFWFR)="D"),(PSSFWPR2="") Q ""
 I PSSFWPR1 Q PSSFWPR2_"^"_$G(PSSFWPR7)
 S PSSFWPR3=$L(PSSFWSCC) I PSSFWPR3<5 Q PSSFWPR2_"^"_$G(PSSFWPR7)
 S PSSFWPR4=$E(PSSFWSCC,(PSSFWPR3-3),PSSFWPR3) S PSSFWPR4=$$UP^XLFSTR(PSSFWPR4)
 I '$D(^PS(51.1,"APPSJ",PSSFWSCC)) Q $$MULTSCH^PSSSCHMS(PSSFWSCC,$G(PSSFWFR),$G(PSSFWPK),$G(PSSFWDRL))
 S PSSFWPR5=PSSFWSCC
 S PSSFWSCC=$E(PSSFWSCC,1,(PSSFWPR3-4)) K PSSFWPR7
 S PSSFWPR6=$$FRQZ
 S PSSFWSCC=PSSFWPR5
 Q PSSFWPR6_"^"_$G(PSSFWPR7)
 ;
 ;
FRQZ() ;
 N PSSFWRST,PSSFWFLG,PSSFWSC,PSSX
 S PSSFWSC=$$UP^XLFSTR(PSSFWSCC)
 K PSSFWRST
 I $G(PSSFWPK)'="O",$G(PSSFWPK)'="I" Q ""
 I $G(PSSFWFR)="D" D DAY Q $G(PSSFWRST)
 D STN I PSSFWFLG Q PSSFWRST
 ; Need to check for DCF & old name from 51.
 I ($G(PSSFWSCC)]""),($G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RGH=$P(PSSX,U),PSSOSN=$P(PSSX,U,2) D  Q:($G(PSSFWRST)]"")
 . I +$G(PSSOSN) S PSSFWLP1=PSSOSN D DAY1 Q:($G(PSSFWRST)]"")
 . I '+$G(PSSOSN) F PSSFWLP1=0:0 S PSSFWLP1=$O(^PS(51.1,"APPSJ",PSSFWRGH,PSSFWLP1)) Q:'PSSFWLP1!($G(PSSFWRST)]"")  D DAY1
 I $G(PSSFWRST)]"" S PSSFWPR1=1 Q
 I PSSFWRGH'="" F PSSFWLP1=0:0 S PSSFWLP1=$O(^PS(51.1,"APPSJ",PSSFWRGH,PSSFWLP1)) Q:'PSSFWLP1!($G(PSSFWRST)]"")!$G(PSSDIVFG)  D
 .K PSSFWQZ,PSSFWDIV
 .S PSSDCF=$$DCFSCH^PSSSCHMS(PSSFWLP1,$G(PSSDRG),$G(PSSFWDRL))
 .I PSSDCF]"" S PSSFWRST=$P(PSSDCF,U),PSSFWPR1=1 Q
 .S PSSFWQZ=$P($G(^PS(51.1,PSSFWLP1,0)),"^",3)
 .Q:'$G(PSSFWQZ)
 .S PSSFWDIV=1440/PSSFWQZ
 .I PSSFWDIV'>1 S PSSX=$$CONVSCH^PSSSCHMS(PSSFWQZ) S:$P(PSSX,U)="" PSSDIVFG=1 S PSSFWRST=$P(PSSX,U),PSSFWFLG=+$P(PSSX,U,2) Q
 .I PSSFWDIV?.N S PSSFWRST=PSSFWDIV,PSSFWPR1=1
 I +$G(PSSDIVFG) Q
 I $G(PSSFWRST)]"" Q
 I PSSFWPK="O" D DAYOUT Q:$G(PSSFWRST)
 I PSSFWRGH?1"Q"1N.N1"H" S PSSFWRST=PSSFWRGH,PSSFWPR1=1 Q
 I $G(PSSFWSC)'["@" S PSSFWRST=1 Q
 I $E(PSSFWSC,$L(PSSFWSC))="@" S PSSFWRST=1 Q
 Q
 ;
DAY1 ;Process schedule for the second piece of DOW@SCHEDULE
 I '+$G(PSSOSN),($P($G(^PS(51.1,PSSFWLP1,0)),"^",5)'="D")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WKZ8'>1 S PSSFWRST=1 Q
 I PSSFWKZ8?.N S PSSFWRST=PSSFWKZ8,PSSFWPR1=1
 Q
 ;
NUMB ;Frequency passed in as a number
 ;*** Remove for MOCHA 2.1 - IP will be doing it in UND24HRS^PSJOCDS
 S PSSFWFLG=0 K PSSFWRST
 N PSSFWDIS,PSSFWGRT,PSSFWMNT,PSSFWEEK,PSSFWXWK,PSSFWXMN
 S PSSFWDIS=1440/PSSFWFR I PSSFWDIS?.N S PSSFWFLG=1,PSSFWRST=PSSFWDIS,PSSFWPR1=1 Q
 I PSSFWDIS'<1 Q
 S PSSFWGRT=PSSFWFR/1440
 I PSSFWGRT?.N D  Q
 .S PSSFWMNT=PSSFWGRT/30 I PSSFWMNT?.N S PSSFWFLG=1,PSSFWRST="Q"_PSSFWMNT_"L",PSSFWPR1=1 Q
 .S PSSFWEEK=PSSFWGRT/7 I PSSFWEEK?.N S PSSFWFLG=1,PSSFWRST="Q"_PSSFWEEK_"W",PSSFWPR1=1 Q
 .S PSSFWFLG=1,PSSFWRST="Q"_PSSFWGRT_"D",PSSFWPR1=1 Q
 I PSSFWFR'>10080 S PSSFWXWK=10080/PSSFWFR I PSSFWXWK?.N S PSSFWFLG=1,PSSFWRST="X"_PSSFWXWK_"W",PSSFWPR1=1 Q
 S PSSFWXMN=43200/PSSFWFR I PSSFWXMN?.N S PSSFWFLG=1,PSSFWRST="X"_PSSFWXMN_"L",PSSFWPR1=1 Q
 Q
 ;
STN ;Standard Logic
 S PSSFWFLG=0 K PSSFWRST I $G(PSSFWSC)="" Q
 N PSSFWLP2,PSSFWAA,PSSFWAAD,PSSFWAAM,PSSFWAMN,PSSFWAWK,PSSFWAXL,PSSFWAXW,PSSDCF,PSSDCFLG,PSSDIVFG
 I $G(PSSOSN)]"" S PSSFWLP2=PSSOSN D STN1
 ;PSS*1*224
 I $G(PSSOSN)="" S PSSFWSC=$$PRNSCHD^PSSDSUTL(PSSFWSC) F PSSFWLP2=0:0 S PSSFWLP2=$O(^PS(51.1,"APPSJ",PSSFWSC,PSSFWLP2)) Q:'PSSFWLP2!(PSSFWFLG)!$G(PSSDCFLG)!$G(PSSDIVFG)  D STN1
 K PSSDIVFG
 Q:$G(PSSDCFLG)
 I PSSFWFLG D DURLS I PSSFWFLG S PSSFWPR1=1 Q
 Q
 ;
STN1 ;Standard Logic continue
 K PSSFWAA,PSSFWAAD
 S PSSDCF=$$DCFSCH^PSSSCHMS(PSSFWLP2,$G(PSSDRG),$G(PSSFWDRL))
 ;PSS*1*206
 I PSSDCF="",(PSSFWSC[" PRN") D
 . NEW PSSX
 . S PSSX=PSSFWLP2
 . I ($P(PSSFWSC," PRN",1)'=""),($P(PSSFWSC," PRN",1)'?." ") S PSSFWLP2=$O(^PS(51.1,"APPSJ",$P(PSSFWSC," PRN",1),0))
 . S:+PSSFWLP2 PSSDCF=$$DCFSCH^PSSSCHMS(PSSFWLP2,$G(PSSDRG),$G(PSSFWDRL))
 . S PSSFWLP2=PSSX
 I PSSDCF]"" S (PSSFWPR1,PSSFWFLG,PSSDCFLG)=1,PSSFWRST=$P(PSSDCF,U),PSSFWPR7=$P(PSSDCF,U,2) Q
 S PSSFWAA=$P($G(^PS(51.1,PSSFWLP2,0)),"^",3)
 Q:'$G(PSSFWAA)
 S PSSFWAAD=1440/PSSFWAA
 I PSSFWAAD?.N S PSSFWRST=PSSFWAAD,PSSFWFLG=1 Q
 I (PSSFWAA<1440),((PSSFWAA/60)?.N) S PSSFWRST="Q"_(PSSFWAA/60)_"H",PSSFWFLG=1 Q
 I PSSFWAAD>1 Q
 S PSSFWAAM=PSSFWAA/1440
 I PSSFWAAM'?.N D  Q
 . S PSSFWFLG=1,PSSFWRST="",PSSDIVFG=1
 . I (PSSFWAA/60)?.N S PSSFWRST="Q"_(PSSFWAA/60)_"H"
 I PSSFWAAM?.N D  Q
 .S PSSFWAMN=PSSFWAAM/30 I PSSFWAMN?.N S PSSFWFLG=1,PSSFWRST="Q"_PSSFWAMN_"L" Q
 .S PSSFWAWK=PSSFWAAM/7 I PSSFWAWK?.N S PSSFWFLG=1,PSSFWRST="Q"_PSSFWAWK_"W" Q
 .S PSSFWFLG=1,PSSFWRST="Q"_PSSFWAAM_"D" Q
 I PSSFWAA'>10080 S PSSFWAXW=10080/PSSFWAA I PSSFWAXW?.N S PSSFWFLG=1,PSSFWRST="X"_PSSFWAXW_"W" Q
 S PSSFWAXL=43200/PSSFWAA I PSSFWAXL?.N S PSSFWFLG=1,PSSFWRST="X"_PSSFWAXL_"L" Q
 Q
 ;
STNO ;Standard Logic part 2, using File 51, For Outpatient Orders only
 S PSSFWFLG=0 K PSSFWRST I $G(PSSFWSC)="" Q
 N PSSFWLP3,PSSFWBA,PSSFWBAD,PSSFWBAM,PSSFWBMN,PSSFWBWK,PSSFWBXL,PSSFWBXW,PSSDCFLG,PSSDIVFG
 I $G(PSSOMEDN)]"" S PSSFWLP3=PSSOMEDN D STNO1
 ;PSS*1*224
 I $G(PSSOMEDN)="" S PSSFWSC=$$PRNMI^PSSDSUTL(PSSFWSC) F PSSFWLP3=0:0 S PSSFWLP3=$O(^PS(51,"B",PSSFWSC,PSSFWLP3)) Q:'PSSFWLP3!(PSSFWFLG)!$G(PSSDIVFG)  D STNO1
 K PSSDIVFG
 Q:$G(PSSDCFLG)
 Q:$G(PSSDECNO)
 I PSSFWFLG D DURLS I PSSFWFLG S PSSFWPR1=1 Q
 I PSSFWSC?1"Q"1N.N1"H" S PSSFWRST=PSSFWSC,PSSFWFLG=1 D DURLS I PSSFWFLG S PSSFWPR1=1
 Q
 ;
STNO1 ;Standard Logic part 2, using File 51, For Outpatient Orders only
 K PSSFWBA,PSSFWBAD
 S PSSDCF=$$DCF51^PSSSCHMS(PSSFWLP3,$G(PSSDRG),$G(PSSFWDRL))
 I PSSDCF]"" S (PSSFWPR1,PSSFWFLG,PSSDCFLG)=1,PSSFWRST=$P(PSSDCF,U),PSSFWPR7=$P(PSSDCF,U,2) Q
 S PSSFWBA=$P($G(^PS(51,PSSFWLP3,0)),"^",8)
 Q:'$G(PSSFWBA)
 S PSSFWBAD=1440/PSSFWBA
 I PSSFWBAD?.N S PSSFWRST=PSSFWBAD,PSSFWFLG=1 Q
 I (PSSFWBA<1440),((PSSFWBA/60)?.N) S PSSFWRST="Q"_(PSSFWBA/60)_"H",PSSFWFLG=1 Q
 ;PSSDECNO=1 when the admin time is not a whole #(dosing error message should display)
 I PSSFWBAD>1 S PSSFWFLG=0,PSSDECNO=1 Q
 S PSSFWBAM=PSSFWBA/1440
 I PSSFWBAM'?.N S PSSFWFLG=1,PSSFWRST="",PSSDIVFG=1 Q
 I PSSFWBAM?.N D  Q
 .S PSSFWBMN=PSSFWBAM/30 I PSSFWBMN?.N S PSSFWFLG=1,PSSFWRST="Q"_PSSFWBMN_"L" Q
 .S PSSFWBWK=PSSFWBAM/7 I PSSFWBWK?.N S PSSFWFLG=1,PSSFWRST="Q"_PSSFWBWK_"W" Q
 .S PSSFWFLG=1,PSSFWRST="Q"_PSSFWBAM_"D" Q
 I PSSFWBA'>10080 S PSSFWBXW=10080/PSSFWBA I PSSFWBXW?.N S PSSFWFLG=1,PSSFWRST="X"_PSSFWBXW_"W" Q
 S PSSFWBXL=43200/PSSFWBA I PSSFWBXL?.N S PSSFWFLG=1,PSSFWRST="X"_PSSFWBXL_"L" Q
 Q
 ;
DS() ; Return 1 if Dose Checks are enabled, return 0 if Dose Checks are not enabled, 2.0 message to OR & 2.1 message to IP & OP
 Q $S($P($G(^PS(59.7,1,81)),"^"):1,+$G(PSSDSWHE)=1:$$DS1(),1:$$DS2())
 ;;
DS1() ; called from $$DS to break line length
 Q "0^Maximum Single Dose Order Check is not available; please complete a manual check for appropriate Dosing."
 ;;
DS2() ; called from $$DS to break line length
 Q "0^Dosing Checks are not available; please complete a manual check for appropriate Dosing."
 ;; 
IV(PSSADFOI) ;Return Additive Frequency default to CPRS, Forum DBIA 5425
 ;PSSADFOI = File 50.7 Internal Entry Number
 N PSSADFRS,PSSADFIN,PSSADFLP,PSSADFXX,PSSADFHD,PSSADFNN,PSSADFER,PSSADFCT
 S PSSADFRS="",(PSSADFXX,PSSADFCT)=0
 I '$G(PSSADFOI) Q PSSADFRS
 F PSSADFLP=0:0 S PSSADFLP=$O(^PS(52.6,"AOI",PSSADFOI,PSSADFLP)) Q:'PSSADFLP!(PSSADFXX)  D
 .S PSSADFIN=$P($G(^PS(52.6,PSSADFLP,"I")),"^")
 .I PSSADFIN,PSSADFIN'>DT Q
 .S PSSADFNN=PSSADFLP_","
 .S PSSADFHD=$$GET1^DIQ(52.6,PSSADFNN,18,"I",,"PSSADFER") I PSSADFHD="" S PSSADFXX=1 Q
 .I 'PSSADFCT S PSSADFRS=PSSADFHD S PSSADFCT=1 Q
 .I PSSADFHD'=PSSADFRS S PSSADFXX=1
 I PSSADFXX S PSSADFRS=""
 Q PSSADFRS
 ;
 ;
BSA(PSSBSADF) ;
 I '$G(PSSBSADF) Q "0^0"
 N DFN,VADM,VAPTYP,VAHOW,VAROOT,VAERR,VA,X1,X2,X,%Y,PSSBSAW1,PSSBSAW2,PSSBSAH1,PSSBSAH2,GMRVSTR,PSSBSAB2,PSSBSAH3
 S DFN=PSSBSADF
 S (PSSBSAW2,PSSBSAH2,PSSBSAB2,PSSBSAH3)=0
 S GMRVSTR="WT" K X D EN6^GMRVUTL
 S PSSBSAW1=$P(X,"^",8) I PSSBSAW1 S PSSBSAW2=PSSBSAW1/2.2
 S DFN=PSSBSADF
 S GMRVSTR="HT" K X D EN6^GMRVUTL
 S PSSBSAH1=$P(X,"^",8) I PSSBSAH1 S PSSBSAH2=.0254*PSSBSAH1,PSSBSAH3=$J(PSSBSAH1*2.54,0,2)
 ;Using DuBios formula for BSA calculation, and sending in 2 decimal places
 I $G(PSSBSAW2),$G(PSSBSAH2) S PSSBSAB2=.20247*(PSSBSAH2**.725)*(PSSBSAW2**.425)
 Q PSSBSAH3_"^"_PSSBSAW2_"^"_PSSBSAB2
 ;
 ;
UNITD(PSSVUTUN) ;Find First DataBank Unit, can't do DIC Lookup because of exact match check
 ;Returns Null or First DataBank Unit for text passed in
 N PSSVUTX,PSSVUTZ,PSSVUTAA,PSSVUTFL
 S PSSVUTFL=0 I $G(PSSVUTUN)="" S PSSVUTZ="" G UNITDX
 S PSSVUTAA=$$UP^XLFSTR(PSSVUTUN)
UNITDP ;
 K PSSVUTZ S PSSVUTX=$O(^PS(51.24,"B",PSSVUTAA,0)) I PSSVUTX,'$$SCREEN^XTID(51.24,.01,PSSVUTX_",") S PSSVUTZ=$P($G(^PS(51.24,PSSVUTX,0)),"^",2) I PSSVUTZ'="",$P($G(^PS(51.24,PSSVUTX,0)),"^",3)=0 G UNITDX
 K PSSVUTZ S PSSVUTX=$O(^PS(51.24,"C",PSSVUTAA,0)) I PSSVUTX,'$$SCREEN^XTID(51.24,.01,PSSVUTX_",") S PSSVUTZ=$P($G(^PS(51.24,PSSVUTX,0)),"^",2) I PSSVUTZ'="",$P($G(^PS(51.24,PSSVUTX,0)),"^",3)=0 G UNITDX
 K PSSVUTZ S PSSVUTX=$O(^PS(51.24,"D",PSSVUTAA,0)) I PSSVUTX,'$$SCREEN^XTID(51.24,.01,PSSVUTX_",") S PSSVUTZ=$P($G(^PS(51.24,PSSVUTX,0)),"^",2) I PSSVUTZ'="",$P($G(^PS(51.24,PSSVUTX,0)),"^",3)=0 G UNITDX
 K PSSVUTZ I 'PSSVUTFL,$G(PSSVUTUN)["/" S PSSVUTFL=1,PSSVUTAA=$P(PSSVUTUN,"/"),PSSVUTAA=$$UP^XLFSTR(PSSVUTAA) G:PSSVUTAA'="" UNITDP
UNITDX ;
 Q $G(PSSVUTZ)
 ;
 ;
DURLS ;If Duration is less that 24 hours, make Frequency adjustments if applicable
 ;Only check Frequencies of a whole number or in the format of Q#H
 N PSSDK1,PSSDK2,PSSDK3,PSSDK4,PSSDK5,PSSDK6,PSSDSCNT
 S (PSSDK4,PSSFWPR7)=PSSFWRST
 I $G(PSSFWDRL)="" Q
 S PSSDK1=$$DRT^PSSDSAPD(PSSFWDRL) I PSSDK1'<1440!(PSSDK1'>0) Q
 S PSSDSCNT=$$CHKIPDUR^PSSSCHMS()
 I +PSSDSCNT S PSSFWRST=$P(PSSDSCNT,U,2) Q
 S PSSDK2=1440/PSSDK1
 I PSSDK4?.N D  Q
 .S PSSDK5=PSSDK4/PSSDK2
 .I PSSDK5<1 K PSSFWRST S PSSFWFLG=0 Q
 .;PSS*1*178 - rounding up makes more sense
 .S PSSDK6=$S((PSSDK5?.N):PSSDK5,1:$J((PSSDK5+.5),0,0))
 .S PSSFWRST=PSSDK6
 I PSSDK4?1"Q"1N.N1"H" D  Q
 .S PSSDK3=$$FRCON^PSSDSAPK(PSSDK4)
 .S PSSDK5=PSSDK3/PSSDK2
 .I PSSDK5<1 K PSSFWRST S PSSFWFLG=0 Q
 .S PSSDK6=$J(PSSDK5,0,0)
 .S PSSFWRST=PSSDK6
 Q
 ;
 ;
DLTM(PSSNVTOI) ;Check if all drugs for a Non-VA Med order are exempt, if so, kill Input exceptions and Quit
 N PSSNVT1,PSSNVTFL,PSSNVTIN
 S PSSNVTFL=1
 F PSSNVT1=0:0 S PSSNVT1=$O(^PSDRUG("ASP",PSSNVTOI,PSSNVT1)) Q:'PSSNVT1!('PSSNVTFL)  D
 .I $P($G(^PSDRUG(PSSNVT1,2)),"^",3)'["X" Q
 .S PSSNVTIN=$P($G(^PSDRUG(PSSNVT1,"I")),"^") I PSSNVTIN,PSSNVTIN<DT Q
 .S PSSNVTFL=$$EXMT^PSSDSAPI(PSSNVT1)
 Q PSSNVTFL
 ;
 ;
EMSY() ;Return 1 if there are matched supplies, no active drugs, regardless of Package use
 N PSSKST1,PSSKST2,PSSKST3,PSSKST4,PSSKST5,PSSKST6,PSSKST9
 S (PSSKST9,PSSKST6)=0
 F PSSKST1=0:0 S PSSKST1=$O(^PSDRUG("ASP",PSSNBOI,PSSKST1)) Q:'PSSKST1!(PSSKST9)  D
 .S PSSKST4=0,PSSKST2=$P($G(^PSDRUG(PSSKST1,"I")),"^") I PSSKST2,PSSKST2'>DT S PSSKST4=1
 .S PSSKST5=$$SUP(PSSKST1)
 .I 'PSSKST5,'PSSKST4 S PSSKST9=1 Q
 .I 'PSSKST4,PSSKST5 S PSSKST6=1
 I 'PSSKST9,PSSKST6 S $P(PSSNBRS,";",5)=0 Q 0
 Q 1