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

PSSDSAPD.m

Go to the documentation of this file.
PSSDSAPD ;BIR/RTR-Main Dose Check API ;09/16/08
 ;;1.0;PHARMACY DATA MANAGEMENT;**117,160,173,201,178,206**;9/30/97;Build 10
 ;
 ;Dose Check API
 ;
 ;Input
 ;PSSDBASE = Name of subscript
 ;PSSDBDFN = Patient Internal Entry Number
 ;PSSDBDS  = Data to use to build actual Input data, for pieces not sent in PSSDBFDB array
 ;PSSDBFDB = Array where if the node exists, just set that data (even if null) directly into the corresponding API piece
DOSE(PSSDBASX,PSSDBDFN,PSSDBDS,PSSDBFDB) ;
 I $G(PSSDBASX(1))="" Q
 N PSSDBASE,PSSDBASF,PSSDBASG,PSSDBASA,PSSDBASB S PSSDBASE=PSSDBASX(1),PSSDBASF=$G(PSSDBASX(2)),PSSDBASG=$G(PSSDBASX(3)) K ^TMP($J,PSSDBASE) K ^TMP($J,"PSSDOSGL") K ^TMP($J,"PSSCNX")
 S PSSDBASA=0 I $G(PSSDBASF)'="" K ^TMP($J,PSSDBASF) S PSSDBASA=1
 S PSSDBASB=0 I $G(PSSDBASG)'="" K ^TMP($J,PSSDBASG) S PSSDBASB=1
 S ^TMP($J,PSSDBASE,"IN","PING")="" D IN^PSSHRQ2(PSSDBASE)
 I $P($G(^TMP($J,PSSDBASE,"OUT",0)),"^")=-1 D DOWN^PSSDSAPK Q
 K ^TMP($J,PSSDBASE)
 N PSSDBLP,PSSDBND1,PSSDBND3,PSSDBAR,PSSDBFST,PSSDBFLG,PSSDBCOT,PSSDBCAR,PSSDBFRC,PSSDBFRB,PSSDBIFL,PSSDBIFG,PSSDBCAX,PSSDBCAZ,PSSDBFTX,PSSDBADJ,PSSDBCDP,PSSDSDPL,PSSDSWHE,PSSENHK,PSSENHKZ,PSSDSIVF,PSSENO,PSSDBSNO,PSSDLEM
 I +$G(PSSDBDFN)'>0 Q
 S (PSSDBFLG,PSSDBSNO)=0 S PSSDSWHE=$S($E($G(PSSDBASE),1,2)="OR":1,1:0) ;2.1 PSSDBSNO added - remains at 0 if all schedules are excluded from all Dosing checks, set in Comp Tag
 F PSSDBLP=0:0 S PSSDBLP=$O(PSSDBFDB(PSSDBLP)) Q:'PSSDBLP  D
 .K PSSDBAR,PSSDBND1,PSSDBND3 S (PSSDBIFL,PSSDBIFG,PSSDSIVF,PSSENO)=0
 .I $G(PSSDBFDB(PSSDBLP,"RX_NUM"))="" Q
 .I $G(PSSDBFDB(PSSDBLP,"DRUG_NM"))="" Q
 .S PSSDBFDB("OI")=$S($G(PSSDBFDB(PSSDBLP,"OI")):$G(PSSDBFDB(PSSDBLP,"OI")),1:$G(PSSDBFDB("OI"))) I $G(PSSDBFDB(PSSDBLP,"DRUG_IEN"))'>0,$G(PSSDBFDB("OI"))'>0 Q
 .I $G(PSSDBFDB(PSSDBLP,"DRUG_IEN"))>0,$$EXMT^PSSDSAPI($G(PSSDBFDB(PSSDBLP,"DRUG_IEN"))) Q
 .S PSSDLEM=$$QORDLEM^PSSDSAPL() Q:PSSDLEM=1
 .D INERR^PSSDSAPM Q:PSSENO  I $G(PSSDBFDB(PSSDBLP,"DRUG_IEN"))'>0 D FDRUG^PSSDSAPM I PSSDBIFG D ONT^PSSDSAPA
 .I PSSDBIFL,'PSSDBIFG D NXDRUG^PSSDSAPM Q
 .D NDINFO
 .I $G(PSSDBND1),$G(PSSDBND3) D
 ..S PSSDBAR("GCN")=$P($$PROD0^PSNAPIS(PSSDBND1,PSSDBND3),"^",7)
 ..S PSSDBAR("VUID")=$$GETVUID^XTID(50.68,,+PSSDBND3_",")
 .S PSSDBAR("NAME")=$G(PSSDBFDB(PSSDBLP,"DRUG_NM"))
 .D AMT I $G(PSSDBAR("AMN"))'="",$L(PSSDBAR("AMN"))>1,$E(PSSDBAR("AMN"),1)="0" S PSSDBAR("AMN")=$E(PSSDBAR("AMN"),2,$L(PSSDBAR("AMN")))
 .D DTYPE
 .S PSSDBAR("DSE")=$S($D(PSSDBFDB(PSSDBLP,"DOSE_RATE")):$G(PSSDBFDB(PSSDBLP,"DOSE_RATE")),1:"DAY")
 .D RTE
 .D SCHD^PSSSCHMS
 .D DURR
 .D DURRAT
 .S PSSDBAR("SPFC")="" S:$G(PSSDBFDB(PSSDBLP,"ENH")) PSSENHK(PSSDBFDB(PSSDBLP,"RX_NUM"))=1
 .S PSSDBFST=$G(PSSDBAR("GCN"))_"^"_$S($P($G(PSSDBAR("VUID")),"^")'=0:$G(PSSDBAR("VUID")),1:"")_"^"_$S('PSSDBIFL:PSSDBFDB(PSSDBLP,"DRUG_IEN"),PSSDBIFL&(PSSDBIFG):PSSDBIFG,1:"")_"^"_PSSDBAR("NAME")
 .S PSSDBFLG=1
 .S ^TMP($J,PSSDBASE,"IN","PROSPECTIVE",PSSDBFDB(PSSDBLP,"RX_NUM"))=PSSDBFST
 .S ^TMP($J,PSSDBASE,"IN","DOSE",PSSDBFDB(PSSDBLP,"RX_NUM"))=PSSDBFST_"^"_$G(PSSDBAR("AMN"))_"^"_$G(PSSDBAR("UNIT"))_"^"_PSSDBAR("DSE")_"^"_PSSDBAR("FREQ")_"^"_PSSDBAR("DUR")_"^"_PSSDBAR("DRR")_"^"_PSSDBAR("RT")_"^"_PSSDBAR("TYPE")
 .S ^TMP($J,PSSDBASE,"IN","DOSE",PSSDBFDB(PSSDBLP,"RX_NUM"))=^TMP($J,PSSDBASE,"IN","DOSE",PSSDBFDB(PSSDBLP,"RX_NUM"))_"^"_PSSDBAR("SPFC")_"^"_$$DFM^PSSDSEXC
 .S PSSDBFRC(PSSDBFDB(PSSDBLP,"RX_NUM"),"CONJ")=$G(PSSDBDS(PSSDBLP,"CONJ")) S PSSDBFRC(PSSDBFDB(PSSDBLP,"RX_NUM"),"SCHEDULE")=$G(PSSDBDS(PSSDBLP,"SCHEDULE"))
 .I $G(PSSDBDS(PSSDBLP,"DRATE"))'="" I PSSDBDS(PSSDBLP,"DRATE")?.N!(PSSDBDS(PSSDBLP,"DRATE")?.N1".".N) S PSSDBDS(PSSDBLP,"DRATE")=PSSDBDS(PSSDBLP,"DRATE")_"D"
 .S PSSDBFRB(PSSDBFDB(PSSDBLP,"RX_NUM"),"DRATE")=$G(PSSDBDS(PSSDBLP,"DRATE")) D ADJU^PSSDSEXC
 .D INFUE^PSSDSAPM
 .D FRQE^PSSDSAPM
 .S ^TMP($J,"PSSCNX","IN","DOSE",PSSDBLP,PSSDBFDB(PSSDBLP,"RX_NUM"))=^TMP($J,PSSDBASE,"IN","DOSE",PSSDBFDB(PSSDBLP,"RX_NUM"))
 D COMP ;Set up complex Doses
 S ^TMP($J,PSSDBASE,"IN","IEN")=PSSDBDFN
 S ^TMP($J,PSSDBASE,"IN","DOSE")=""
 D PAT^PSSDSAPM K ^TMP($J,"PSSCNX")
 N PSSDBDGO ; Only go to interface if you have at least one Dose Sequence that needs to go
 S PSSDBDGO=0 I $D(^TMP($J,PSSDBASE,"IN","EXCEPTIONS")) S (PSSDBDGO,PSSDBSNO)=1
 D ERR ;Set up PSSDBCAX error array and default data
 I PSSDBDGO,PSSDBSNO D:$D(PSSDBFTX) FTX^PSSDSAPK D IN^PSSHRQ2(PSSDBASE) D:$D(PSSDBFTX) FTXRS^PSSDSAPK ;2.1 PSSDBSNO check added
 I PSSDBASA!(PSSDBASB) D FMT^PSSDSEXC I $P($G(^TMP($J,PSSDBASE,"OUT",0)),"^")'=-1 D ADDCT^PSSDSAPM,REM^PSSDSAPA
 Q
AMT ;Set Dose Amount and Dose Unit
 D DPL^PSSDSAPK
 I $D(PSSDBCAZ(PSSDBFDB(PSSDBLP,"RX_NUM"),"NO_DRUG")) D MLTS^PSSDSAPM Q
 N PSSDBUNT,PSSDBFAL,PSSDBXP,PSSDBNOD,PSSDBNT,PSSDSXTD,PSSDBUNA,PSSDBLPD,PSSDSLCL,PSSDSLC1,PSSDSLCT
 S (PSSDBFAL,PSSDBLPD,PSSDSLCT)=0
 I 'PSSDBIFL,$D(PSSDBFDB(PSSDBLP,"DOSE_AMT")),$D(PSSDBFDB(PSSDBLP,"DOSE_UNIT")) S PSSDBAR("AMN")=PSSDBFDB(PSSDBLP,"DOSE_AMT"),PSSDBAR("UNIT")=PSSDBFDB(PSSDBLP,"DOSE_UNIT") D LDZ Q
 I 'PSSDBIFL,$G(PSSDBDS(PSSDBLP,"DRG_AMT")),$G(PSSDBDS(PSSDBLP,"DRG_UNIT"))'="" D
 .;For Drug Units like MG/ML, take first piece of"/"
 .S PSSDBUNT=$S(PSSDBDS(PSSDBLP,"DRG_UNIT")["/":$P(PSSDBDS(PSSDBLP,"DRG_UNIT"),"/"),1:PSSDBDS(PSSDBLP,"DRG_UNIT"))
 .S PSSDBUNT=$$UP^XLFSTR(PSSDBUNT)
 .S PSSDBUNA=$$UNIT^PSSDSAPI(PSSDBUNT)
 .I PSSDBUNA'="" S PSSDBAR("AMN")=PSSDBDS(PSSDBLP,"DRG_AMT"),PSSDBAR("UNIT")=PSSDBUNA,PSSDBFAL=1 D LDZ
 I PSSDBFAL Q
 ;"DOSE" Node should only come from CPRS, for selected Local Possible Dosage
 S PSSDSLCL=$S($G(PSSDBDS(PSSDBLP,"DOSE"))'="":$P(PSSDBDS(PSSDBLP,"DOSE"),"&",5),1:$G(PSSDBDS(PSSDBLP,"DO")))
 I PSSDSLCL["(" D PTH^PSSDSUTL
 I PSSDBIFL D MLT^PSSDSAPM Q
AMTRT ;Retry for Local Dosages with parenthesis
 I PSSDSLCL'="" D
 .F PSSDBXP=0:0 S PSSDBXP=$O(^PSDRUG(PSSDBFDB(PSSDBLP,"DRUG_IEN"),"DOS2",PSSDBXP)) Q:'PSSDBXP!(PSSDBFAL)  D
 ..S PSSDBNOD=$G(^PSDRUG(PSSDBFDB(PSSDBLP,"DRUG_IEN"),"DOS2",PSSDBXP,0))
 ..;ignore package of the Local Possible Dose
 ..I $$MTCH^PSSDSAPK S PSSDBLPD=1 I $P(PSSDBNOD,"^",5),$P(PSSDBNOD,"^",6)'="" D
 ...;XTID Screening out Inactive Dose Units
 ...S PSSDSXTD=+$P(PSSDBNOD,"^",5) I PSSDSXTD,$$SCREEN^XTID(51.24,.01,PSSDSXTD_",") Q
 ...S PSSDBNT=$P($G(^PS(51.24,+$P(PSSDBNOD,"^",5),0)),"^",2)
 ...I PSSDBNT'="" S PSSDBAR("AMN")=$P(PSSDBNOD,"^",6),PSSDBAR("UNIT")=PSSDBNT,PSSDBFAL=1
 .;Only do auto-population logic if Local Possible Dosage was not found at all in File 50
 .I PSSDBFAL Q
 .I PSSDBLPD D DPOP^PSSDSAPK I PSSDBFAL Q
 .D ITEM^PSSDSAPK D:'PSSDBFAL NUM^PSSDSAPL D:'PSSDBFAL RANGE^PSSDSUTL
 I 'PSSDBFAL,PSSDSLCT S PSSDSLCL=PSSDSLC1(PSSDSLCT),PSSDSLCT=PSSDSLCT-1,PSSDBLPD=0 G AMTRT
 Q
LDZ ;
 I $E(PSSDBAR("AMN"))=0,$L(PSSDBAR("AMN"))>1 S PSSDBAR("AMN")=$E(PSSDBAR("AMN"),2,$L(PSSDBAR("AMN")))
 Q
RTE ;Get First DataBank Med Route
 N PSSDBMRT
 K PSSDBMRT
 I $D(PSSDBFDB(PSSDBLP,"ROUTE")) S PSSDBAR("RT")=PSSDBFDB(PSSDBLP,"ROUTE") Q
 I $G(PSSDBDS(PSSDBLP,"MR_IEN")) S PSSDBMRT=$$MRT^PSSDSAPI(PSSDBDS(PSSDBLP,"MR_IEN")) I $P(PSSDBMRT,"^",2)'="" S PSSDBAR("RT")=$P(PSSDBMRT,"^",2) Q
 S PSSDBAR("RT")=""
 Q
DTYPE ;Find Dose Type
 N PSSDBST1,PSSDBST2,PSSDBST3,PSSDBST4,PSSDBSTX
 I $D(PSSDBFDB(PSSDBLP,"DOSE_TYPE")) S PSSDBAR("TYPE")=PSSDBFDB(PSSDBLP,"DOSE_TYPE") Q
 S PSSDBST1=$G(PSSDBDS(PSSDBLP,"SCHEDULE"))
 I PSSDBST1="" S PSSDBAR("TYPE")="MAINTENANCE" Q
 S PSSDBST3=0
 ;PSS*1*206
 I PSSDBST1[" PRN",'$D(^PS(51.1,"APPSJ",PSSDBST1)) S PSSDBSTX=$P(PSSDBST1," PRN",1) S:PSSDBSTX]"" PSSDBST1=PSSDBSTX
 F PSSDBST2=0:0 S PSSDBST2=$O(^PS(51.1,"APPSJ",PSSDBST1,PSSDBST2)) Q:'PSSDBST2!(PSSDBST3)  D
 .S PSSDBST4=$P($G(^PS(51.1,PSSDBST2,0)),"^",5)
 .I PSSDBST4="O"!(PSSDBST4="OC") S PSSDBAR("TYPE")="SINGLE DOSE",PSSDBST3=1
 I 'PSSDBST3 S PSSDBAR("TYPE")="MAINTENANCE"
 Q
DURR ;Set Duration
 I $D(PSSDBFDB(PSSDBLP,"DURATION")) S PSSDBAR("DUR")=PSSDBFDB(PSSDBLP,"DURATION") Q
 S PSSDBAR("DUR")=$S($G(PSSDBAR("TYPE"))="SINGLE DOSE":"",1:1)
 Q
DURRAT ;Set Duration Rate
 I $D(PSSDBFDB(PSSDBLP,"DURATION_RT")) S PSSDBAR("DRR")=PSSDBFDB(PSSDBLP,"DURATION_RT") Q
 S PSSDBAR("DRR")=$S($G(PSSDBAR("TYPE"))="SINGLE DOSE":"",1:"DAY")
 Q
COMP ;Handle complex order, set PSSDBCAR array, see routine PSSDSEXC for PSSBDCAR piece details
 ;if you have to add new create input entry, just add a piece 5 = 1 to the Pharmacy Order Number
 N PSSDBKLP,PSSDBKUN,PSSDBKMR,PSSDBKND,PSSDBKRF,PSSDBKNW,PSSDBKFL,PSSDBKTM,PSSDBKFQ,PSSDBKGG,PSSCNX1,PSSDBCDA,PSSDCLX
 S PSSDBKTM="PSSTTMP"
 K ^TMP($J,PSSDBKTM)
 S PSSDBKFL=0
 F PSSCNX1=0:0 S PSSCNX1=$O(^TMP($J,"PSSCNX","IN","DOSE",PSSCNX1)) Q:'PSSCNX1  S PSSDBKLP=$O(^TMP($J,"PSSCNX","IN","DOSE",PSSCNX1,"")) I PSSDBKLP'=""  D
 .S PSSDBKND=$G(^TMP($J,PSSDBASE,"IN","DOSE",PSSDBKLP)) S PSSDBKFQ=$S($D(PSSDBCAZ(PSSDBKLP,"FRQ_ERROR")):0,1:1) S PSSDBKGG=$S($P(PSSDBKND,"^",12)="SINGLE DOSE":1,1:0)
 .S PSSDBCDA($S($P(PSSDBKND,"^",3)="":"NULL",1:$P(PSSDBKND,"^",3)),$S($P(PSSDBKND,"^",11)="":"NULL",1:$P(PSSDBKND,"^",11)))=PSSDBKLP I $G(PSSDCLX)="" S PSSDCLX=PSSDBKLP ;2.1 removed PSSDSWHE check
 .S PSSDBCAR(PSSDBKLP)="B"_"^"_$P(PSSDBKND,"^",4)_"^"_$P(PSSDBKND,"^",3)_"^"_PSSDBKFQ_"^"_$S($P(PSSDBKND,"^",12)="SINGLE DOSE":0,1:1) S:$G(PSSDBFRC(PSSDBKLP,"CONJ"))="A" $P(PSSDBCAR(PSSDBKLP),"^",7)=1
 .S $P(PSSDBCAR(PSSDBKLP),"^",9)=$P(PSSDBKND,"^",11) D MLTNO^PSSDSAPM,SXCL^PSSDSAPA S:$G(PSSDBFRC(PSSDBKLP,"CONJ"))'=""!($G(PSSDBFRC(PSSDCLX,"CONJ"))'="") $P(PSSDBCAR(PSSDBKLP),"^",16)=1 S PSSDCLX=PSSDBKLP ; 2.1 removed PSSDSWHE check
 .S:'$P(PSSDBCAR(PSSDBKLP),"^",14) PSSDBSNO=1 I $G(PSSDBFRC(PSSDBKLP,"CONJ"))'="A"!($O(^TMP($J,"PSSCNX","IN","DOSE",PSSCNX1))="") S PSSDBKNW($P(PSSDBKLP,";",4),PSSDBKLP)="" D CRT K PSSDBKNW,PSSDBCDA S PSSDBKFL=0 Q
 .S PSSDBKFL=PSSDBKFL+1
 .S PSSDBKNW($P(PSSDBKLP,";",4),PSSDBKLP)=""
 .S $P(PSSDBCAR(PSSDBKLP),"^")="S",$P(PSSDBCAR(PSSDBKLP),"^",12)=1
 I $D(^TMP($J,PSSDBKTM)) M ^TMP($J,PSSDBASE)=^TMP($J,PSSDBKTM)
 K ^TMP($J,PSSDBKTM)
 Q
DRT(PSSDBJV) ;Return number of minutes based on duration, API also called from Inpatient Medications
 ;If only a numeric is passed in, the API will assume Days
 I $G(PSSDBJV)="" Q -1
 I PSSDBJV?.N1".".N1"D"!(PSSDBJV?.N1"D") Q (1440*+PSSDBJV)
 I PSSDBJV?.N1".".N!(PSSDBJV?.N) Q (1440*+PSSDBJV)
 I PSSDBJV?.N1".".N1"H"!(PSSDBJV?.N1"H") Q (60*+PSSDBJV)
 I PSSDBJV?.N1".".N1"M"!(PSSDBJV?.N1"M") Q (+PSSDBJV)
 I PSSDBJV?.N1".".N1"W"!(PSSDBJV?.N1"W") Q (10080*+PSSDBJV)
 I PSSDBJV?.N1".".N1"L"!(PSSDBJV?.N1"L") Q (43200*+PSSDBJV)
 Q -1
CRT ;Possibly create new Input Dose Node just for Daily Dose purposes
 I 'PSSDBKFL!($G(PSSDBFRC(PSSDBKLP,"CONJ"))="A") S $P(PSSDBCAR(PSSDBKLP),"^")=$S($G(PSSDBFRC(PSSDBKLP,"CONJ"))="A":"S",$G(PSSDBKGG):"S",$G(PSSDBFRB(PSSDBKLP,"DRATE"))="":"B",1:"B") D S12 Q
 N PSSDBR1,PSSDBR2,PSSDBR3,PSSDBR4,PSSDBR5,PSSDBR6,PSSDBR7,PSSDBRCT,PSSDBRNO,PSSDBRLS,PSSDBR9,PSSDBR91,PSSDBEQ2,PSSDBEQ3,PSSDBEQ4,PSSDBR8,PSSDBXAX,PSSDBRLP,PSSDBRLA
 S (PSSDBRNO,PSSDBRCT,PSSDBR5)=0
 ;Then or Except Conjunction, or last Dosing Sequence in the series, with previous dosages to add up for Daily Dose
 ;PSSDBKNW array holds all previous dosing sequences and current one
 S PSSDBRLP="" F  S PSSDBRLP=$O(PSSDBKNW(PSSDBRLP)) Q:PSSDBRLP=""  S PSSDBR1=$O(PSSDBKNW(PSSDBRLP,"")) I PSSDBR1'=""  D
 .S PSSDBR2=$G(^TMP($J,PSSDBASE,"IN","DOSE",PSSDBR1))
 .I $O(PSSDBKNW(PSSDBRLP))="" S $P(PSSDBCAR(PSSDBKLP),"^")="S",$P(PSSDBCAR(PSSDBKLP),"^",12)=1
 .I $P(PSSDBR2,"^",12)'="MAINTENANCE" D NX(4)
 .S PSSDBRCT=PSSDBRCT+1
 .I $G(PSSDBFRC(PSSDBR1,"SCHEDULE"))["@" D NX(10)
 .I '$D(PSSDBEQ2(10)),$G(PSSDBFRC(PSSDBR1,"SCHEDULE"))'="" F PSSDBEQ4=0:0 S PSSDBEQ4=$O(^PS(51.1,"APPSJ",$G(PSSDBFRC(PSSDBR1,"SCHEDULE")),PSSDBEQ4)) Q:'PSSDBEQ4!($D(PSSDBEQ2(10)))  D
 ..I $P($G(^PS(51.1,PSSDBEQ4,0)),"^",5)="D" D NX(10)
 .I PSSDBRCT=1 D  Q
 ..I '$P(PSSDBR2,"^",5) D NX(11)
 ..S PSSDBR91=$G(PSSDBFRB(PSSDBR1,"DRATE"))
 ..S PSSDBR3=$P(PSSDBR2,"^",6),PSSDBR4=$P(PSSDBR2,"^",11) I PSSDBR3=""!(PSSDBR4="") S PSSDBRNO=1 D:PSSDBR3="" NX(5) D:PSSDBR4="" NX(6)
 ..S PSSDBR5=$P(PSSDBR2,"^",8)
 ..I $D(PSSDBCAZ(PSSDBR1,"FRQ_ERROR")) D NX(7)
 ..I 'PSSDBRNO S PSSDBR8=$$FRCON^PSSDSAPK(PSSDBR5) S:PSSDBR8'<1 PSSDBR6=$P(PSSDBR2,"^",5)*PSSDBR8 I PSSDBR8<1 D NX(7)
 ..I $G(PSSDBFRB(PSSDBR1,"DRATE"))'="" S PSSDBR7=$$DRT(PSSDBFRB(PSSDBR1,"DRATE")) I PSSDBR7<1440 D NX(9)
 ..I '$O(PSSDBKNW(PSSDBRLP)) S PSSDBRLS=PSSDBR1 ; Get Last entry
 .I '$P(PSSDBR2,"^",5) D NX(11)
 .I PSSDBR3'=$P(PSSDBR2,"^",6) D NX(5)
 .I PSSDBR4'=$P(PSSDBR2,"^",11) D NX(6)
 .I $G(PSSDBFRB(PSSDBR1,"DRATE"))'=PSSDBR91 D NX(8)
 .S PSSDBR5=$P(PSSDBR2,"^",8) I $D(PSSDBCAZ(PSSDBR1,"FRQ_ERROR")) D NX(7)
 .I 'PSSDBRNO S PSSDBR8=$$FRCON^PSSDSAPK(PSSDBR5) S:PSSDBR8'<1 PSSDBR6=PSSDBR6+($P(PSSDBR2,"^",5)*PSSDBR8) I PSSDBR8<1 D NX(7)
 .I $G(PSSDBFRB(PSSDBR1,"DRATE"))'="" S PSSDBR7=$$DRT(PSSDBFRB(PSSDBR1,"DRATE")) I PSSDBR7<1440 D NX(9)
 .I '$O(PSSDBKNW(PSSDBRLP)) S PSSDBRLS=PSSDBR1 ; Get Last entry
 I PSSDBRNO D  S $P(PSSDBCAR(PSSDBRLS),"^",8)=1,$P(PSSDBCAR(PSSDBRLS),"^",7)="" D MLTNP^PSSDSAPM Q  ;2.1 Removed RESET^PSSDSAPA call - works witn GEN+2^PSSDSEXC add back for 2.2
 .S PSSDBRLA="" F  S PSSDBRLA=$O(PSSDBKNW(PSSDBRLA)) Q:PSSDBRLA=""  S PSSDBR9=$O(PSSDBKNW(PSSDBRLA,"")) I PSSDBR9'=""  S $P(PSSDBCAR(PSSDBR9),"^")="S",$P(PSSDBCAR(PSSDBR9),"^",12)=1
 .;Set error message only for last entry where Daily Dose should have been done
 .D ERST^PSSDSAPM
 S ^TMP($J,PSSDBKTM,"IN","DOSE",PSSDBRLS_";1")=^TMP($J,PSSDBASE,"IN","DOSE",PSSDBRLS)
 S ^TMP($J,PSSDBKTM,"IN","PROSPECTIVE",PSSDBRLS_";1")=$P(^TMP($J,PSSDBASE,"IN","DOSE",PSSDBRLS),"^",1,4)
 S $P(^TMP($J,PSSDBKTM,"IN","DOSE",PSSDBRLS_";1"),"^",8)=1
 S $P(^TMP($J,PSSDBKTM,"IN","DOSE",PSSDBRLS_";1"),"^",5)=PSSDBR6
 S PSSDBCAR(PSSDBRLS_";1")="D"_"^"_$P(PSSDBKND,"^",4)_"^"_$P(PSSDBKND,"^",3)_"^"_PSSDBKFQ S $P(PSSDBCAR(PSSDBRLS),"^",11)=1
 Q
NDINFO ;Set National Drug File information
 I 'PSSDBIFL,$G(PSSDBFDB(PSSDBLP,"DRUG_IEN")) S PSSDBND1=$P($G(^PSDRUG(PSSDBFDB(PSSDBLP,"DRUG_IEN"),"ND")),"^"),PSSDBND3=$P($G(^PSDRUG(PSSDBFDB(PSSDBLP,"DRUG_IEN"),"ND")),"^",3) Q
 I $G(PSSDBIFG) S PSSDBND1=$P($G(^PSDRUG(PSSDBIFG,"ND")),"^"),PSSDBND3=$P($G(^PSDRUG(PSSDBIFG,"ND")),"^",3)
 Q
ERR ;Loop through PSSDBCAR, set PSSDBCAX error array
 N PSSDBEB1,PSSDBEB2,PSSDBEB3
 S PSSDBEB3=$S($G(^TMP($J,PSSDBASE,"IN","DOSE","AGE")):1,1:0)
 ;Skip AGE, WT and BSA and newly created Dosages for complex additions
 ;Rx_NUM MUST contain a ";", or you will not set PSSDBDGO
 S PSSDBEB1="" F  S PSSDBEB1=$O(^TMP($J,PSSDBASE,"IN","DOSE",PSSDBEB1)) Q:PSSDBEB1=""  S:'PSSDBEB3&(PSSDBEB1[";") $P(PSSDBCAR(PSSDBEB1),"^",13)=1 D:'$P(PSSDBEB1,";",5)&(PSSDBEB1[";")
 .S PSSDBEB2=$G(^TMP($J,PSSDBASE,"IN","DOSE",PSSDBEB1))
 .I $D(PSSDBCAZ(PSSDBEB1,"INF_ERROR")) D INRATE^PSSDSAPA S PSSDBDGO=1 S $P(PSSDBCAR(PSSDBEB1),"^",13)=1 Q
 .I $P(PSSDBEB2,"^",5)=""!($P(PSSDBEB2,"^",6)="") D BDOSE^PSSDSAPK S $P(PSSDBCAR(PSSDBEB1),"^",13)=1 Q
 .;I $D(PSSDBCAZ(PSSDBEB1,"FRQ_ERROR")) D INFRQ^PSSDSAPA S PSSDBDGO=1 Q  ;; 2.1 change, ensure null freq are sent in line below
 .I $$FCY^PSSDSUTA() D INFRQ^PSSDSAPA S PSSDBDGO=1 Q
 .I '$P(PSSDBCAR(PSSDBEB1),"^",5) D SING^PSSDSAPK S PSSDBDGO=1 Q
 .S PSSDBDGO=1
 Q
EXCPS(PSSDBEQ1) ;Set errors
 I $P(PSSDBCAR(PSSDBEB1),"^",16),PSSDBEQ1=2 Q  ;Complex order - remove in 2.2
 I $P(PSSDBCAR(PSSDBEB1),"^",15),PSSDBEQ1=2 Q  ;2.1 Don't set Frequency error if Schedule excluded from Daily Dose check
 I PSSDBEQ1=2,$D(PSSDBCAZ(PSSDBEB1,"FRQD_ERROR")) S PSSDBCAX(PSSDBEB1,15)="" Q
 S PSSDBCAX(PSSDBEB1,PSSDBEQ1)=""
 Q
S12 ;
 S:$P(PSSDBCAR(PSSDBKLP),"^")="S" $P(PSSDBCAR(PSSDBKLP),"^",12)=1
 Q
NX(PSSNX) ;
 S PSSDBRNO=1
 S PSSDBEQ2(PSSNX)=""
 S PSSDBXAX(PSSNX,PSSDBR1)=""
 Q