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

BHLBPS1.m

Go to the documentation of this file.
BHLBPS1 ; IHS/TUCSON/DCP - HL7 - FILE VISIT/V MED FROM COTS PHARMACY ;
 ;;1.0;IHS SUPPORT FOR HL7 INTERFACES;;JUL 7, 1997
 ;
 ; This routine is a continuation of BHLBPS.
 ; It is not independently callable.
 ;
START ; ENTRY POINT from BHLBPS
 ;
 N BHLBIDX,BHLEIDX,BHLMIDX,BHLBMSG,XMB,PCPRVNAM
 S BHLEIDX=7        ; last non-error field on bulletin
 S BHLMIDX=12       ; last error field on bulletin
 S BHLBIDX=BHLEIDX  ; initialize bulletin field pointer
 D INIT
 I BHLERR="" D @BHLACT
 I $G(BHLDBUG) D LOGAPCD ; log APCDALVR array if debugging
 D SENDBULL
EOJ ;KILL VARS AND EXIT
 K APCDALVR,APCDANE,APCDTCDT,APCDTDAY,APCDTEXK,APCDTNTD,APCDTPRV,APCDTQTY,APCDTRX,APCDTSIG,APCDTOPR
 K BHLBPSR,BHLDOB,BHLF,BHLFILE,BHLJ,BHLSEX,BHLSSN,BHLDUZ2,BHLACT,BHLXKEY
 K IEN,SEX,DOB,SSN
 D KILL^AUPNPAT
 K C,F,I,DIC,DIE,DIK,DR,D0,DO,DI
 Q
 ;
A ;add a new prescription
 D EDIT
 I BHLERR'="" Q
 S APCDALVR("APCDAUTO")=""
 S APCDALVR("APCDANE")=""
 D ^APCDALV
 I $D(APCDALVR("APCDAFLG")) S BHLERR="VISIT CREATION FAILED" Q
 S APCDALVR("APCDATMP")="[APCDALVR 9000010.14 (ADD)]"
 D ^APCDALVR
 I $D(APCDALVR("APCDAFLG")) S BHLERR="V MED CREATION FAILED" Q
 Q
 ;
D ;delete a v med
 S DA=$O(^AUPNVMED("AXK",BHLXKEY,0)) I DA="" S BHLERR="CANNOT FIND V MED FOR DELETE",BHLEDATA="V MED = "_BHLXKEY Q
 S DIK="^AUPNVMED(" D ^DIK
 K DIK,DA
 Q
 ;
E ;edit an existing v med
 S DA=$O(^AUPNVMED("AXK",BHLXKEY,0)) I DA="" S BHLERR="CANNOT FIND V MED FOR EDIT",BHLEDATA="V MED = "_BHLXKEY Q
 S APCDALVR("APCDVSIT")=$P(^AUPNVMED(DA,0),U,3)
 S APCDALVR("APCDPAT")=$P(^AUPNVMED(DA,0),U,2)
 S DIK="^AUPNVMED(" D ^DIK K DIK,DA
 D EMED
 Q:BHLERR'=""
 S APCDALVR("APCDATMP")="[APCDALVR 9000010.14 (ADD)]"
 D ^APCDALVR
 I $D(APCDALVR("APCDAFLG")) S BHLERR="V MED FAILED ON EDIT" Q
 Q
 ;
INIT ;
 ;check to be sure that all required pieces of data are present
 ;if not, set error and quit
 N X,Y
 K APCDALVR
 I BHLBPS("MED")="" S BHLERR="MISSING MED INFO" Q
 S BHLACT=$P(BHLBPS("MED"),BHLFS,6)
 I "^A^E^D^"'[(U_BHLACT_U) S BHLERR="INVALID ACTION",BHLEDATA="ACTION = "_BHLACT Q
 S BHLXKEY=$P(BHLBPS("MED"),BHLFS,5)
 I BHLXKEY="" S BHLERR="MISSING EXTERNAL KEY" Q
 Q:BHLACT="D"
 I BHLBPS("PAT DEMO")="" S BHLERR="MISSING PATIENT DEMOGRAPHICS" Q
 I BHLBPS("VISIT")="" S BHLERR="MISSING VISIT INFO" Q
 S Y="NAME^DOB^SEX^SSN^CHART^FACILITY"
 F X=1,2,3,5,6 I $P(BHLBPS("PAT DEMO"),BHLFS,X)="" S BHLERR=BHLERR_","_$P(Y,U,X)
 S Y="VISIT DATE^SVC CAT^FACILITY"
 F X=1:1:3 I $P(BHLBPS("VISIT"),BHLFS,X)="" S BHLERR=BHLERR_","_$P(Y,U,X)
 S Y="RX NUMBER^QTY^DAYS PRESCRIBED^DISP DATE^EXTKEY^ACTION^REF^NDC^DRUG^UNITS^SIG^PROVIDER DEA#^PROVIDER NAME^RPH CODE^RPH NAME"
 F X=2,3,7,8,10,13,14 I $P(BHLBPS("MED"),BHLFS,X)="" S BHLERR=BHLERR_","_$P(Y,U,X)
 I $P(BHLBPS("MED"),BHLFS,11)="",$P(BHLBPS("MED"),BHLFS,12)="" S BHLERR=BHLERR_","_$P(Y,U,11)_","_$P(Y,U,12)
 I BHLERR'="" S BHLERR="MISSING DATA: "_$E(BHLERR,2,$L(BHLERR))
 Q
 ;
EDIT ;edit all passed data, check against input tx
 ;edit record info against input transform
 D GETPAT
 Q:BHLERR'=""
 D EVISIT      ;edit visit information and set array
 D EMED        ;edit v med and set up APCDALVR array
 Q
 ;
EMED ;
 N X,Y
 S X=$P(BHLBPS("MED"),BHLFS,8),DIC(0)="",DIC="^PSDRUG(" D ^DIC K DIC,DA,DR
 I Y=-1 S BHLBMSG="DRUG ENTRY COULD NOT BE FOUND BY NAME" D BULLETIN S X="OUTSIDE DRUG",DIC="^PSDRUG(",DIC(0)="M" D ^DIC I Y=-1 S BHLERR="OUTSIDE DRUG ENTRY NOT IN DRUG TABLE" Q
 S APCDALVR("APCDTRX")="`"_+Y
 I $P(Y,U,2)="OUTSIDE DRUG" S APCDALVR("APCDTNTD")=$P(BHLBPS("MED"),BHLFS,8)
 ; check provider, quit if error
 ;
 D PROV Q:BHLERR'=""
 ;
 ;check sig
 ;
 K DIC
 S X=$E($P(BHLBPS("MED"),BHLFS,10),1,145)
 K BHLBPSR D CHK^DIE(9000010.14,.05,"E",X,.BHLBPSR)
 I BHLBPSR="^" S BHLERR="SIG FAILED INPUT TRANSFORM",BHLEDATA="SIG = "_X Q
 S APCDALVR("APCDTSIG")=BHLBPSR
 S BHLFILE=9000010.14 F BHLJ=2:1:5 Q:BHLERR'=""  S BHLF=$P("^.06^.07^1201^1209",U,BHLJ),X=$P(BHLBPS("MED"),BHLFS,BHLJ) I X'="" K BHLBPSR D CHK^DIE(9000010.14,BHLF,"E",X,.BHLBPSR) D
 .I BHLBPSR="^" S BHLERR="FIELD "_BHLF_" FAILED INPUT TRANSFORM IN V MED",BHLEDATA=X Q
 .Q
 Q:BHLERR'=""
 S APCDALVR("APCDTQTY")=$P(BHLBPS("MED"),BHLFS,2)
 S APCDALVR("APCDTDAY")=$P(BHLBPS("MED"),BHLFS,3)
 S APCDALVR("APCDTCDT")=$P(BHLBPS("MED"),BHLFS,4)
 S APCDALVR("APCDTEXK")=$P(BHLBPS("MED"),BHLFS,5)
 Q
 ;
PROV ; Verify provider name/number
 ;
 N BHL200,VKPRVDEA,PCPRVDEA,VKPRVNAM,PRVIEN,DIC,X,Y
 S VKPRVDEA=$P(BHLBPS("MED"),BHLFS,11)  ; pharmacy provider DEA #
 S VKPRVNAM=$P(BHLBPS("MED"),BHLFS,12)  ; pharmacy provider name
 S BHL200=$P($G(^AUTTSITE(1,0)),U,22)   ; new person file flag
 ;
 S DIC=$S(BHL200:"^VA(200,",1:"^DIC(6,"),DIC(0)="MOZ"
 S X=VKPRVNAM D ^DIC
 I Y=-1 S X=VKPRVDEA D ^DIC
 I Y=-1 S BHLERR="PROVIDER FROM RX SYSTEM FAILED EDIT" Q
 S PRVIEN=$P(Y,U,1),PCPRVNAM=Y(0,0),PCPRVDEA=$S(BHL200:$P($G(^VA(200,PRVIEN,"PS")),U,2),1:$P(Y(0),U,3))
 S APCDALVR("APCDTPRV")="`"_+PRVIEN
 I VKPRVDEA="" S BHLBMSG="PROVIDER DEA# NOT PROVIDED BY RX SYSTEM" D BULLETIN Q
 I PCPRVDEA="" S BHLBMSG="PROVIDER DEA# NOT FOUND IN PCC DATABASE" D BULLETIN Q
 I PCPRVDEA'=VKPRVDEA S BHLERR="PROVIDER DEA# MISMATCH" Q
 I VKPRVNAM="" S BHLBMSG="PROVIDER NAME NOT PROVIDED BY RX SYSTEM" D BULLETIN Q
 I '$$MATCH(VKPRVNAM,PCPRVNAM) S BHLBMSG="PROVIDER NAME MISMATCH" D BULLETIN Q
 Q
 ;
EVISIT ;
 ;edit passed date,facility and set APCDALVR array
 S Y=$P(BHLBPS("VISIT"),BHLFS,1) I $P(Y,".",2)="" S Y=Y_"@12:00"
 D CHK^DIE(9000010,.01,"E",Y,.BHLBPSR)
 I BHLBPSR="^" S BHLERR="VISIT DATE FAILED INPUT TRANSFORM",BHLEDATA="VISIT DATE = "_Y Q
 S APCDALVR("APCDDATE")=BHLBPSR
 S Y=$P(BHLBPS("VISIT"),BHLFS,3),Y=$O(^AUTTLOC("C",Y,0))
 I 'Y S BHLERR="COULD NOT LOOK UP LOCATION OF ENCOUNTER",BHLEDATA="LOCATION = "_Y Q
 S APCDALVR("APCDLOC")=Y
 S APCDALVR("APCDTYPE")=$S($P($G(^APCCCTRL(Y,0)),U,4)'="":$P(^APCCCTRL(Y,0),U,4),$P($G(^APCCCTRL(DUZ(2),0)),U,4)'="":$P(^APCCCTRL(DUZ(2),0),U,4),1:"I")
 S APCDALVR("APCDCAT")=$P(BHLBPS("VISIT"),BHLFS,2) D CHK^DIE(9000010,.07,"E",APCDALVR("APCDCAT"),.BHLBPSR) I BHLBPSR="^" S BHLERR="SERVICE CATEGORY FAILED INPUT TRANSFORM",BHLEDATA="SERVICE CATEGORY = "_APCDALVR("APCDCAT") Q
 Q
 ;
GETPAT ;
 ;get patient IEN if possible
 ;if fails send bulletin
 ;if sex,ssn,dob don't match fail
 ;if name not exact, send warning bulletin
 N C,F,X,Y,PATDOB,PATSEX,PATSSN
 S F=$P(BHLBPS("PAT DEMO"),BHLFS,6)
 S F=$O(^AUTTLOC("C",F,0))
 I 'F S BHLERR="FACILITY FOR HRN LOOKUP FAILED",BHLEDATA="FACILITY = "_F Q
 S C=$P(BHLBPS("PAT DEMO"),BHLFS,5),BHLSEX=$P(BHLBPS("PAT DEMO"),BHLFS,3),BHLDOB=$P(BHLBPS("PAT DEMO"),BHLFS,2),BHLSSN=$P(BHLBPS("PAT DEMO"),BHLFS,4)
 K DIC,DA,DR,DD,D0,DO S BHLDUZ2=DUZ(2),DUZ(2)=F,X=C,DIC="^AUPNPAT(",DIC(0)="M" D ^DIC
 S DUZ(2)=BHLDUZ2 K BHLDUZ2
 I Y=-1 S BHLERR="CHART NUMBER LOOKUP FAILED, CAN'T FIND PATIENT",BHLEDATA="CHART NUMBER = "_X Q
 S IEN=$P(Y,U,1)
 S PATDOB=$P(^DPT(IEN,0),U,3)
 I BHLDOB'=PATDOB S BHLERR="DOB OF PATIENT DOES NOT MATCH",BHLEDATA="PHARMACY DOB = "_BHLDOB_", PCC DOB = "_PATDOB Q
 S PATSEX=$P(^DPT(IEN,0),U,2)
 I BHLSEX'="",PATSEX'="",BHLSEX'=PATSEX S BHLERR="SEX OF PATIENT DOES NOT MATCH",BHLEDATA="PHARMACY SEX = "_BHLSEX_", PCC SEX = "_PATSEX Q
 S PATSSN=$P(^DPT(IEN,0),U,9)
 I BHLSSN'="",PATSSN'="",BHLSSN'=PATSSN S BHLERR="SSN DOES NOT MATCH",BHLEDATA="PHARMACY SSN = "_BHLSSN_", PCC SSN = "_PATSSN Q
 I '$$MATCH($P(BHLBPS("PAT DEMO"),BHLFS,1),$P(^DPT(IEN,0),U,1)) S BHLBMSG="PAT NAME FROM PHARMACY SYSTEM DOES NOT MATCH PAT REG" D BULLETIN
 S APCDALVR("APCDPAT")=IEN
 Q
 ;
MATCH(STR1,STR2) ; match up strings
 ;
 N MIN
 S MIN=$S($L(STR1)<$L(STR2):$L(STR1),1:$L(STR2))
 I MIN<6 Q (STR1=STR2)
 Q ($E(STR1,1,MIN)=$E(STR2,1,MIN))
 ;
BULLETIN ;
 ; add error message to bulletin - bulletin will be sent later
 S BHLBIDX=BHLBIDX+1
 S XMB(BHLBIDX)=BHLBMSG
 Q
 ;
SENDBULL ;
 ; if debug mode, list bulletin errors on screen and quit
 I $G(BHLDBUG) D  K XMB Q
 .W !,"Warning Bulletin:"
 .I BHLBIDX=BHLEIDX W !,?3,"none" Q
 .N I F I=8:1:BHLBIDX W !,?3,XMB(I)
 ;
 ; quit if nothing to send
 Q:BHLBIDX=BHLEIDX
 N %X,%Y,X,XMDT,XMDUZ,Y1
 ; bulletin name
 S XMB="BHLBPS RX-PCC LINK DATA ERROR"
 ; PCC patient name
 S XMB(1)=$S($D(IEN):$P(^DPT(IEN,0),U,1),1:"")
 ; pharmacy patient name
 S XMB(2)=$P(BHLBPS("PAT DEMO"),BHLFS,1)
 ; patient chart number
 S XMB(3)=$P(BHLBPS("PAT DEMO"),BHLFS,5)
 ; drug name
 S XMB(4)=$P(BHLBPS("MED"),BHLFS,8)
 ; dispense date
 S Y=$P(BHLBPS("MED"),BHLFS,4) X ^DD("DD") S XMB(5)=Y
 ; pharmacy provider - name and DEA #
 S XMB(6)=$P(BHLBPS("MED"),BHLFS,12)_"  "_$P(BHLBPS("MED"),BHLFS,11)
 ; PCC provider name
 S XMB(7)=$G(PCPRVNAM)
 ; null out any unused parameters
 F BHLBIDX=BHLBIDX+1:1:BHLMIDX S XMB(BHLBIDX)=""
 S XMDUZ=.5
 D ^XMB
 K XMB
 Q
 ;
LOGAPCD ; Log APCDALVR array if debugging
 ;
 Q:'$G(BHLDBUG)
 K ^TMP("BHLBPS",$J)
 N I
 S I="" F  S I=$O(APCDALVR(I)) Q:I=""  S ^TMP("BHLBPS",$J,"APCDALVR",I)=APCDALVR(I)
 Q