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

APSAPPIP.m

Go to the documentation of this file.
APSAPPIP ;IHS/ITSC/POC/ENM - PRINT A MEDICATION INSTRUCTION SHEET [ 08/27/2003  8:53 AM ]
 ;;6.1;IHS PHARMACY MODIFICATIONS;**4**;01/10/2002
 ;REWRITE OF APSAPPIP WITH ^DIWP
 ;TO VARY PAGESETUP IHS/OKCAO/POC 1/16/2002
 ;TAKES ADVANTAGE OF PRINTING PMI USING MARGINS IHS/OKCAO/POC 11/11/2002
EP1 ;FROM APSEPPID
 D INIT
 D CONT
 Q
EP2 ;EP FROM APSAPPIM
 D END,INIT
 D CONT
 Q
 ;
PICK ;EP SELECT A DRUG FROM FILE 50
 D END,INIT
 I $D(PSNDRUG) Q
 I '$D(^APSAPPI) W !,"PATIENT MEDICATION INSTRUCTION SHEETS' DATA HAS NOT BEEN INSTALLED",!! H 3 Q
 S DIC=50,DIC(0)="AEQMZ",DIC("S")="D DICS^APSAPPIP" D ^DIC K DIC Q:Y<0  S DRG=+Y
 S X=$P($G(^PSDRUG(DRG,2)),U,4) Q:X=""  D ^APSPMDD S NDC=X D ECK I '+PPI S PPI=.5,P2=1 ;GET NDC AND REMOVE DASHES
 I XNDC="" S PPI=.5,P2=1
 ;
CONT ;
 D SH
 D DISC
 D HDR
 D WRITE
 I '$G(QUIT),$E(IOST,1,2)="C-" K DIR S DIR(0)="E" D ^DIR  ;FOR THE VERY END OF PRI NT IF TO SCREEN
 D END1
 Q
 ;
SH ;PRINT OUT MAIN BODY
 N IEN S IEN=0
 F  S IEN=$O(^APSAPPI(PPI,1,IEN)) Q:'+IEN!QUIT  D PRINTIT(^(IEN,0))
 Q
 ;
PRINTIT(X) ;PRINT THE LINE
 Q:QUIT
 F  Q:$E(X,$L(X))'=" "  S X=$E(X,1,$L(X)-1) ;GET RID OF SPACE AT END OF LINE
 S X=X_" "  ;ADD A SPACE BACK AT END OF LINE
 N WORD,STOP S STOP=0
 F WORD="COMMON USES","HOW TO USE THIS MEDICINE","CAUTIONS","ALCOHOL WARNING","WOMEN","POSSIBLE SIDE EFFECTS","BEFORE USING THIS MEDICINE","OVERDOSE INFORMATION","ADDITIONAL INFORMATION" I X[WORD_":" D  S STOP=1 Q
 .N FIRST,SECOND
 .S FIRST=$P(X,WORD_":",1)
 .S SECOND=$P(X,WORD_":",2,99)
 .I FIRST]"" S X=FIRST D ^DIWP
 .D LASTLINE
 .S X=WORD_":" D ^DIWP,LASTLINE
 .S X=SECOND D ^DIWP
 .Q
 D:'STOP ^DIWP
 Q
ECK ;
 S RN=0,PPI=0,XNDC=0 F  S XNDC=$O(^APSAMDF("B",XNDC)) Q:XNDC=""  I XNDC=NDC  D  Q
 .S RN=$O(^APSAMDF("B",XNDC,RN))
 .S PPI=^APSAMDF(RN,3)
 .I $G(^APSAPPI(PPI,0))="" S PPI=.5
 Q
 ;
END1 ;
 K NAM
END ;KILL THE VARIABLES
 K DRUG,QUIT,DIC,RN,P2,XNDC,NDC,DIWL,DIWR,DIWF
 K PG,NUM,APSAIOSL
 K ^UTILITY($J,"W")
 Q
 ;
INIT ;INIT SOME VARIABLES
 S PG=1,QUIT=0,NUM=1
 S DIWL=5,DIWR=IOM-5
 I $E(IOST,1,2)="C-" S APSAIOSL=IOSL-2
 E  S APSAIOSL=IOSL  ;DIWF="B4"  ;BOTTOM OF PAGE
 I $G(PSNTRADE)'="" S DRUG=PSNTRADE
 N X,J,K
 I '$D(DRUG) S DRUG=$P(^PSDRUG(DRG,0),U),X=$G(^("ND")),J=+X,K=+$P(X,U,3),X=$P($G(^PSNDF(J,5,K,2)),U) I X]"" S DRUG=X
 D:$D(PSNDFN)
 .S DFN=PSNDFN,NAM=$P(^DPT(DFN,0),U) D DEM^VADPT
 Q
 ;
DICS ;SCREEN
 I $S('$G(^PSDRUG(+Y,"I")):1,DT'>^("I"):1,1:0)
 Q
 ;
LASTLINE ;PA THE LAST LINE IN UTILITY TO MAXIMUM
 N LASTLINE,LEN,SPACE
 S LASTLINE=$G(^UTILITY($J,"W",DIWL))
 Q:'+LASTLINE
 Q:'$D(^UTILITY($J,"W",DIWL,LASTLINE,0))!($G(^(0))="")  ;DONT PAD A LINE THAT IS NULL
 S LEN=DIWR-DIWL-$L($G(^UTILITY($J,"W",DIWL,LASTLINE,0)))
 Q:LEN<1
 S $P(SPACE," ",LEN)=" "
 S ^(0)=^UTILITY($J,"W",DIWL,LASTLINE,0)_SPACE
 Q
 ;
HDR ;HEADER INFO
 S (CNT,IEN)=0
 F  S IEN=$O(^UTILITY($J,"W",DIWL,IEN)) Q:'+IEN  D
 .I '(CNT#APSAIOSL) D HDR1,HDR2
 .S CNT=CNT+1
 .S ^UTILITY($J,"X",DIWL,CNT,0)=^UTILITY($J,"W",DIWL,IEN,0)
 S ^UTILITY($J,"X",DIWL)=CNT
 K ^UTILITY($J,"W")
 M ^("W")=^UTILITY($J,"X")
 K ^UTILITY($J,"X")
 Q
 ;
HDR1 D
 .N SPACE
 .S $P(SPACE," ",43)=" ",X="DRUG NAME: "_DRUG_SPACE,X=$E(X,1,43)
 .K SPACE S $P(SPACE," ",56)=" ",X=X_"RX#: "_$G(PSRX)_SPACE,X=$E(X,1,56)
 .K SPACE S $P(SPACE," ",DIWR)=" ",X=X_"PAGE "_PG_SPACE,X=$E(X,1,DIWR)
 .S CNT=CNT+1
 .S ^UTILITY($J,"X",DIWL,CNT,0)=X
 .S PG=PG+1
 .Q
 Q
 ;
HDR2 D:$D(PSNDFN)
 .N NAM
 .S DFN=PSNDFN,NAM=$P(^DPT(DFN,0),U) D DEM^VADPT
 .N SPACE
 .S $P(SPACE," ",30)=" ",X="PATIENT: "_NAM_SPACE,X=$E(X,1,30)
 .K SPACE S $P(SPACE," ",53)=" ",X=X_"PROVIDER: "_APSDNAM_SPACE,X=$E(X,1,53),X=X_$$HTE^XLFDT(+$H)
 .K SPACE S $P(SPACE," ",DIWR)=" ",X=X_SPACE,X=$E(X,1,DIWR)
 .S CNT=CNT+1
 .S ^UTILITY($J,"X",DIWL,CNT,0)=X
 .Q
 Q
 ;
DISC ;
 ;PRINT TRAILER COPYRIGHT AND DISCLAIMER ON MONOGRAPH
 D LASTLINE
 S CR=$P(^APSAPPI(.5,0),U),ED=$P(^APSAPPI(.5,0),U,5),ED1=$E(ED,1,4),ED2=$E(ED,5,6)
 S ED3=$S(ED2="01":"JANUARY",ED2="02":"FEBRUARY",ED2="03":"MARCH",ED2="04":"APRIL",ED2="05":"MAY",ED2="06":"JUNE",ED2="07":"JULY",ED2="08":"AUGUST",ED2="09":"SEPTEMBER",ED2="10":"OCTOBER",ED2="11":"NOVEMBER",ED2="12":"DECEMBER",1:"")
 S X=CR D PRINTIT(X)
 S X="Expires "_ED3_" "_ED1_"." D PRINTIT(X)
 N IEN S IEN=0
 F  S IEN=$O(^APSAPPI(.5,2,IEN)) Q:'+IEN!QUIT  D
 .S X=^APSAPPI(.5,2,IEN,0)
 .D PRINTIT(X)
 S X=$P(^APSAPPI(.5,3,1,0),"  ",1) D PRINTIT(X)
 Q
 ;
WRITE ;MY DIWW FOR ^DIWW
 U IO
 N UTLIEN
 W:$Y'=0 @IOF
 S UTLIEN=0 F  S UTLIEN=$O(^UTILITY($J,"W",DIWL,UTLIEN)) Q:'+UTLIEN!QUIT  D
 .W ?DIWL,^UTILITY($J,"W",DIWL,UTLIEN,0),!
 .D:'(UTLIEN#APSAIOSL)
 ..I $E(IOST,1,2)="C-" K DIR S DIR(0)="E" D ^DIR K DIR S:'Y QUIT=1
 ..W @IOF
 Q