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

APSQLAB.m

Go to the documentation of this file.
APSQLAB ;IHS/ITSC/ENM/POC - PRINT MOST RECENT LAB VALUE ON PROFILE ; 5/6/94 [ 11/13/2003  4:13 PM ]
 ;;6.0;OUTPATIENT PHARMACY;**4,5**;09/03/97
 ;;6.0;OUTPATIENT PHARMACY;**100,118,133**;09/03/97;
PRINT ;EP - Prints most recent lab test value on profile.
 ;
 N ARRAY,RETURN,ERR,DATE,VALUE,TEST,INFO,DTBACK
 N MDAYS,TSTSP,TST,INFOPCC,INFOLR,DATEPCC,DATELR,HI,LO
 ;I EXPECT PSODFN TO BE DEFINED BUT..IHS/OKCAO/POC 9/7/2003 MAKE SURE IT IS DEFINED
 S:'$G(PSODFN) PSODFN=$S($G(PSORENW("PSODFN")):PSORENW("PSODFN"),$G(PSOREF("PSODFN")):PSOREF("PSODFN"),1:0)
 I 'PSODFN W !,"I CAN'T FIND A PSODFN SO I'M QUITTING THIS SUBROUTINE...CONTACT YOUR SYSTEMS ADMINISTRATOR" Q
 ;END OF CHANGES IHS/OKCAO/POC 9/7/2003
 ;CHANGE WHERE MDRUG COMES FROM IHS/OKCAO/POC 11/5/2002
 S MDRUG=$S($G(PSODRUG("IEN"))]"":PSODRUG("IEN"),$G(PSOREF("DRUG IEN"))]"":PSOREF("DRUG IEN"),$G(PSORENW("DRUG IEN"))]"":PSORENW("DRUG IEN"),1:0),TST=+$P($G(^PSDRUG(MDRUG,"CLOZ")),"^"),MDAYS=+$P($G(^("CLOZ")),"^",2),TSTSP=+$P($G(^("CLOZ")),"^",3)
 I 'TST!('MDAYS)!('TSTSP) D CLEAN Q
 D TWO,ONE
 I $G(DATEPCC)>$G(DATELR) W !,INFOPCC
 E  W !,INFOLR
 D CLEAN
 Q
 ;
ONE ;
 S DTBACK=$$FMADD^XLFDT(DT,-MDAYS)
 S ARRAY="RETURN("
 ;I EXPECT DFN TO BE DEFINED! BUT WELL SO I'LL USE PSODFN AND MAKE SURE IT IS DEFINED IHS/OKCAO/POC 9/8/2003
 ;S INFO=DFN_"^LAST LAB `"_TST_";DURING "_DTBACK_"-"_DT
 ;S:'$G(MDAYS) INFO=DFN_"^LAST LAB `"_MDRUG
 S INFO=PSODFN_"^LAST LAB `"_TST_";DURING "_DTBACK_"-"_DT
 S:'$G(MDAYS) INFO=PSODFN_"^LAST LAB `"_MDRUG
 ;END OF CHANGES IHS/OKCAO/POC 9/7/2003
 S ERR=$$START1^APCLDF(INFO,ARRAY)
 I $G(RETURN(1))]"" D
 .S DATEPCC=$P(RETURN(1),"^",1)
 .S DATE=$$FMTE^XLFDT(DATEPCC,2)
 .S VALUE=$P(RETURN(1),"^",2)
 .S:$G(TST)]"" TEST=$P(^LAB(60,TST,0),"^",1)
 .S VLABIEN=+$P(RETURN(1),"^",4)
 .S:VLABIEN SITE=$$GET1^DIQ(9000010.09,VLABIEN_",",1103,"I","","ERR")
 .S INFOPCC="***MOST RECENT "_$G(TEST)_" PERFORMED "_DATE_" = "_VALUE_"***(PCC)"
 .I 'SITE!(SITE'=TSTSP) Q  ;QUIT IF SITE OF SPECIMEN NOT SAME AS 60
 .S INFOPCC="W !,""***MOST RECENT ""_$G(TEST)_"" PERFORMED ""_DATE_"" = ""_VALUE_STUFF_""***(PCC)"""
 .S INFOPCC="***MOST RECENT "_$G(TEST)_" PERFORMED "_DATE_" = "_VALUE_$$HILO(TST,TSTSP)_"***(PCC)"
 .I (($G(LO)]"")&(VALUE<$G(LO)))!(($G(HI)]"")&(VALUE>$G(HI))) D  ;IHS
 ..S X="IORVON;IORVOFF"
 ..D ENDR^%ZISS
 ..S INFOPCC="***MOST RECENT "_$G(TEST)_" PERFORMED "_DATE_" = "_IORVON_VALUE_IORVOFF_$$HILO(TST,TSTSP)_"***(PCC)"
 E  S DATEPCC=0
 Q
 ;
TWO ;
 ;CHANGE TO PSODFN IHS/OKCAO/POC 9/7/2003
 ;I '$D(^DPT(DFN,"LR")) S INFOLR="*** NO LAB DATA ON FILE ***(LAB)",DATELR=0 Q
 ;S LRDFN=+$P(^DPT(DFN,"LR"),"^") Q:'LRDFN
 I '$D(^DPT(PSODFN,"LR")) S INFOLR="*** NO LAB DATA ON FILE ***(LAB)",DATELR=0 Q
 S LRDFN=+$P(^DPT(PSODFN,"LR"),"^") Q:'LRDFN
 ;END OF CHANGES IHS/OKCAO/POC 9/7/2003
 ;CHANGE WHERE MDRUG COMES FROM IHS/OKCAO/POC 11/5/2002
 S MDRUG=$S($G(PSODRUG("IEN"))]"":PSODRUG("IEN"),$G(PSOREF("DRUG IEN"))]"":PSOREF("DRUG IEN"),$G(PSORENW("DRUG IEN"))]"":PSORENW("DRUG IEN"),1:0),TST=+$P(^PSDRUG(MDRUG,"CLOZ"),"^"),MDAYS=+$P(^("CLOZ"),"^",2),TSTSP=+$P(^("CLOZ"),"^",3)
 Q:'TST!('MDAYS)!('TSTSP)
 S TSTN=$P($G(^LAB(60,TST,0)),"^"),LDN=$S($D(^(.2)):+^(.2),1:+$P($P($G(^(0)),"^",5),";",2))
 ;I $G(^LAB(60,TST,.2))=""&($P($P($G(^LAB(60,TST,0)),"^",5),";",2)="") W !,"*** RESULTS FOR A PANEL CANNOT BE PRINTED! ONLY A LAB TEST RESULT CAN BE PRINTED FOR MARKED DRUGS." G CLEAN
 I $G(^LAB(60,TST,.2))=""&($P($P($G(^LAB(60,TST,0)),"^",5),";",2)="") S INFOLR="W !,""*** RESULTS FOR A PANEL CANNOT BE PRINTED! ONLY A LAB TEST RESULT CAN BE PRINTED FOR MARKED DRUGS.***(LAB)""" Q
EDATE S X="T-"_MDAYS K %DT D ^%DT S EDT=Y,EDL=(9999999-EDT)_".999999",INDIC=0
BEG F BDL=0:0 S BDL=$O(^LR(LRDFN,"CH",BDL)) Q:BDL=""!(BDL>EDL)  D  Q:INDIC=1
 .Q:'$D(^LR(LRDFN,"CH",BDL,LDN))!('$D(^(0)))
 .;NOTE IT WILL QUIT IF YOUR SITE IS NOT THE SAME AS WHAT IS IN LAB
 .Q:$P(^LR(LRDFN,"CH",BDL,0),"^",3)=""!($P(^(0),"^",5)'=TSTSP)
 .S Y=$S(+$P($P(^LR(LRDFN,"CH",BDL,0),"^"),"."):+$P($P(^(0),"^"),"."),1:$P(^(0),"^",3))
 .S VALUE=$P($G(^LR(LRDFN,"CH",BDL,LDN)),"^")  ;FOR HILO
 .S INFOLR="*** MOST RECENT "_$G(TSTN)_" PERF0RMED "_$E(Y,4,5)_"-"_$E(Y,6,7)_"-"_$E(Y,2,3)_" = "_$P($G(^LR(LRDFN,"CH",BDL,LDN)),"^")_" "_$P($G(^LAB(60,TST,1,TSTSP,0)),"^",7)_$$HILO(TST,TSTSP)_"***(LAB)" S INDIC=1
 .I (($G(LO)]"")&(VALUE<$G(LO)))!(($G(HI)]"")&(VALUE>$G(HI))) D  ;IHS
 ..S X="IORVON;IORVOFF"
 ..D ENDR^%ZISS
 ..S INFOLR="*** MOST RECENT "_$G(TSTN)_" PERF0RMED "_$E(Y,4,5)_"-"_$E(Y,6,7)_"-"_$E(Y,2,3)_" = "_IORVON_$P($G(^LR(LRDFN,"CH",BDL,LDN)),"^")_" "_$P($G(^LAB(60,TST,1,TSTSP,0)),"^",7)_IORVOFF_$$HILO(TST,TSTSP)_"***(LAB)" S INDIC=1
 .S DATELR=$G(Y)
 I INDIC=0 S INFOLR="*** NO RESULTS FOR "_TSTN_" SINCE "_$E(EDT,4,5)_"-"_$E(EDT,6,7)_"-"_$E(EDT,2,3)_"***(LAB)"
 Q
 ;
HILO(TST,TSTSP)  ;CALCULATE LOW AND HIGH REFERENCE VALUES
 S LO=$P($G(^LAB(60,TST,1,TSTSP,0)),"^",2),HI=$P($G(^(0)),"^",3)
 S:'LO LO="X"
 S:'HI HI="X"
 Q " ("_LO_"-"_HI_")"
 ;
CLEAN K BDL,EDL,EDT,INDIC,LDN,LRDFN,MDAYS,MDRUG,TST,TSTN,TSTSP,X,Y
 K DATELR,DATEPCC,INFOLR,INFOPCC
 K ARRAY,RETURN,ERR,DATE,VALUE,TEST,INFO,DTBACK
 K LO,HI
 Q