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

AMHPCCL.m

Go to the documentation of this file.
AMHPCCL ; IHS/CMI/LAB - PCC LINK FROM BH 29 May 2006 4:37 PM 03 Jun 2009 3:08 PM ;
 ;;4.0;IHS BEHAVIORAL HEALTH;**1,2,8**;JUN 02, 2010;Build 7
 ;
 ;AMHR=BH RECORD NUMBER
 ;AMHACTN=ACTION TO BE TAKEN
 ;
START ;EP - ENTRY POINT BY TASKMAN
 Q:$P($G(^AMHREC(AMHR,11)),U,10)
 NEW P,X
 S P=$$PPINT^AMHUTIL(AMHR) I P S X=$O(^AMHSITE(DUZ(2),11,"B",P,0)) I X,$P($G(^AMHSITE(DUZ(2),11,X,0)),U,2)=1 Q  ;no link for this provider
 I '$D(ZTQUEUED) W:'$D(AMHBL) !!,"Generating PCC Visit.",!
 LOCK +^AMHREC(AMHR,0):10 E  Q    ;lock AMH record
 I AMHACTN'=4 S AMHR0=^AMHREC(AMHR,0)
 D @AMHACTN
 D XIT
 Q
1 ;add a visit
 I '$D(^AMHREC(AMHR)) Q
ADD1 ;
 S AMHERR=""
 I $G(AMHGUIV) S AMHVSIT=AMHGUIV G VF
 I $L($T(^APCDAPI4)),$L($T(GETVISIT^BSDAPI4)) D  Q
 .D BSD I AMHERR]"" W:'$G(AMHBL) !!,"PCC Visit not created, notify supervisor",!,"PCC visit creation error: ",AMHERR D:'$G(AMHBL) PAUSE^AMHLEA Q
 .I '$G(AMHVSIT) W:'$G(AMHBL) !!,"Visit not created...notify supervisor." Q
 .D VF
 .Q
 D SETVISIT
 D ^APCDALV
 I $G(APCDALVR("APCDAFLG"))=1,'$G(AMHBL) W !!,"PCC Visit not created, try again." G ADD1
 I $D(APCDALVR("APCDAFLG")) S AMHBN="VISIT" D @("V"_APCDALVR("APCDAFLG")) Q
 S AMHVSIT=APCDALVR("APCDVSIT")
VF ;
 K DR,DA,DIE S DA=AMHR,DIE="^AMHREC(",DR=".16////"_AMHVSIT_";1111////1" D CALLDIE^AMHLEIN
 I '$P($G(^AMHSITE(DUZ(2),18)),U,8) K DR,DA,DIE S DA=AMHVSIT,DIE="^AUPNVSIT(",DR="1111///R" D CALLDIE^AMHLEIN  ;reviewed/complete set as yes for all BH visits
 I $P($G(^AMHSITE(DUZ(2),18)),U,8) K DR,DA,DIE S DA=AMHVSIT,DIE="^AUPNVSIT(",DR="1111///I" D CALLDIE^AMHLEIN
 I $P($G(^APCCCTRL(DUZ(2),0)),U,12)]"",$P($P(^AMHREC(AMHR,0),U),".")<$P($G(^APCCCTRL(DUZ(2),0)),U,12) K DR,DA,DIE S DA=AMHVSIT,DIE="^AUPNVSIT(",DR="1111///R" D CALLDIE^AMHLEIN
 D VFILES^AMHPCCL1
 ;NO ERROR CHECK ABOVE !!
 Q
2 ;EDIT A VISIT (DELETE AND ADD V FILES)
 I '$D(^AMHREC(AMHR)) Q  ;huh  - no record to use for edit
 ;set up APCDALVR vars for VISIT, call to modify 
 ;if visit date/time changed, call APCDCVDT
 ;then delete all V POVS, vproviders and vactivity times.
 ;d VFILES^AMHPCCL1
 S AMHVSIT=$P(AMHR0,U,16) ;get existing pcc visit
 I AMHVSIT="" D 1 Q  ;says to edit, but no visit created, so go do add and quit
 I '$D(^AUPNVSIT(AMHVSIT)) K DIE,DA,DR,DIU,DIV,DIW S DA=AMHR,DIE="^AMHREC(",DR=".16///@" D ^DIE K DIE,DA,DR,DIU,DIV,DIW D 1 Q
 I $P(^AUPNVSIT(AMHVSIT,0),U,11) K DIE,DA,DR,DIU,DIV,DIW S DA=AMHR,DIE="^AMHREC(",DR=".16///@" D ^DIE K DIE,DA,DR,DIU,DIV,DIW D 1 Q
 D SETVISIT
 S APCDALVR("APCDATMP")="[APCDALVR 9000010 (MOD)]"
 S APCDALVR("APCDVSIT")=AMHVSIT
 S APCDALVR("APCDLOC")="`"_APCDALVR("APCDLOC")
 S APCDALVR("APCDHL")=$$VALI^XBDIQ1(9002011,AMHR,1117)  ;IHS/CMI/LAB PATCH 8 HOSP LOC
 D ^APCDALVR ;edit existing visit entry
 I $D(APCDALVR("APCDAFLG")) S AMHBN="VISIT" D V9 Q
 I $P(^AUPNVSIT(AMHVSIT,0),U)'=$P(AMHR0,U) D
 .S APCDCVDT("VISIT DFN")=AMHVSIT
 .S APCDCVDT("VISIT DATE/TIME")=$P(AMHR0,U)_$S($P($P(AMHR0,U),".",2)]"":"",1:".12")
 .S APCDCVDT("TALK")=1
 .D ^APCDCVDT
 .I $D(APCDCVDT("ERROR FLAG")) W !!,$C(7),$C(7),"Error changing PCC Visit Date and Time...PLEASE NOTIFY SITE MANAGER",! H 5
 .K APCDCVDT
 .Q
 ;delete all providers
 S AMHX=0 F  S AMHX=$O(^AUPNVPRV("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVPRV(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVPOV("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVPOV(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVTM("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVTM(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVCPT("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVCPT(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVPED("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVPED(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVHF("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVHF(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVXAM("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVXAM(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVMSR("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVMSR(" D ^DIK K DA,DR,DIK
 D VFILES^AMHPCCL1
 Q
3 ;APPEND
 I '$D(^AMHREC(AMHR)) Q  ;huh  - no record to use for edit
 S AMHVSIT=$P(AMHR0,U,16) ;get existing pcc visit
 I AMHVSIT="" D 1 Q  ;says to append, but no visit created, so go do add and quit
 ;delete all providers
 S AMHX=0 F  S AMHX=$O(^AUPNVPRV("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVPRV(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVPOV("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVPOV(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVTM("AD",AMHVSIT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVTM(" D ^DIK K DA,DR,DIK
 D VFILES^AMHPCCL1
 Q
SETVISIT ;set up visit values
 D KILL
 S APCDALVR("AUPNTALK")=""
 S APCDALVR("APCDDATE")=$P(AMHR0,U)
 D GETTYPE
 S APCDALVR("APCDPAT")=$P(AMHR0,U,8)
 S APCDALVR("APCDLOC")=$P(AMHR0,U,4)
 ;determine service category based on type of contact
 S APCDALVR("APCDCAT")=$P(^AMHTSET($P(AMHR0,U,7),0),U,3)
 I '$P($G(^AMHSITE(DUZ(2),0)),U,33) S APCDALVR("APCDAUTO")=""
 I $D(ZTQUEUED) S APCDALVR("APCDAUTO")=""
 S APCDALVR("APCDANE")=""
 ;S APCDALVR("APCDADD")=1 ;always create new visit because 12 is used and 2 visits on same day attach to each other, should never be here except on new visits
 I '$P($G(^AMHSITE(DUZ(2),0)),U,33) S APCDALVR("APCDADD")=1
 I $D(ZTQUEUED) S APCDALVR("APCDADD")=1
 D GETCLN
 I APCDALVR("APCDCAT")="I" S APCDALVR("APCDCLN")=""  ;PER LESLIE RACINE
 I APCDALVR("APCDCLN")]"" S APCDALVR("APCDCLN")="`"_APCDALVR("APCDCLN")
 S APCDALVR("APCDAPPT")=$P(AMHR0,U,11)
 S APCDALVR("APCDOLOC")=$P(AMHR0,U,26)
 S APCDALVR("APCDEVM")=$P(AMHR0,U,29)
 S APCDALVR("APCDHL")=$$VALI^XBDIQ1(9002011,AMHR,1117)  ;IHS/CMI/LAB PATCH 8 HOSP LOC
 Q
GETCLN ;determine clinic to pass
 S APCDALVR("APCDCLN")=""
 NEW X
 S X=$P(AMHR0,U,7)
 I X="" G GETCLN1
 I $P($G(^AMHTSET(X,0)),U,2)=9 S APCDALVR("APCDCLN")=$O(^DIC(40.7,"C",30,"")) Q:APCDALVR("APCDCLN")]""
 I $P($G(^AMHTSET(X,0)),U,2)=5 S APCDALVR("APCDCLN")=$O(^DIC(40.7,"C",11,"")) Q:APCDALVR("APCDCLN")]""
GETCLN1 ;
 S APCDALVR("APCDCLN")=$P(AMHR0,U,25)
 Q:APCDALVR("APCDCLN")]""
 S APCDALVR("APCDCLN")=$S($P(AMHR0,U,2)="M":$O(^DIC(40.7,"C",14,"")),$P(AMHR0,U,2)="S":$O(^DIC(40.7,"C",48,"")),$P(AMHR0,U,2)="C":$O(^DIC(40.7,"C",43,0)),1:$O(^DIC(40.7,"C",C4,"")))
 I APCDALVR("APCDCLN")="" S APCDALVR("APCDCLN")=$O(^DIC(40.7,"C",25,""))
 Q
4 ;delete visit in PCC
 W !,"Deleting associated PCC Visit.",!
 S APCDVDLT=$G(AMHVDLT) I APCDVDLT="" Q
 S AMHX=0 F  S AMHX=$O(^AUPNVPRV("AD",AMHVDLT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVPRV(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVPOV("AD",AMHVDLT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVPOV(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVTM("AD",AMHVDLT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVTM(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVCPT("AD",AMHVDLT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVCPT(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVPED("AD",AMHVDLT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVPED(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVHF("AD",AMHVDLT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVHF(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVXAM("AD",AMHVDLT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVXAM(" D ^DIK K DA,DR,DIK
 S AMHX=0 F  S AMHX=$O(^AUPNVMSR("AD",AMHVDLT,AMHX)) Q:AMHX'=+AMHX  S DA=AMHX,DIK="^AUPNVMSR(" D ^DIK K DA,DR,DIK
 ;D ^APCDVDLT
 S AUPNVSIT=AMHVDLT D MOD^AUPNVSIT K AUPNVSIT
 I '$P(^AUPNVSIT(AMHVDLT,0),U,9) S APCDVDLT=$G(AMHVDLT) D ^APCDVDLT
 Q
KILL ;
 K APCDALVR,APCDPAT,APCDLOC,APCDTYPE,APCDCAT,APCDCLN,APCDTPRO,APCDTPS,APCDTPOV,APCDTNQ,APCDTTOP,APCDTLOU,APCDTPRV,APCDTAT,APCDATMP,APCDAFLG,APCDAUTO,APCDANE,AUPNTALK,APCDAPPT,APCDOLOC
 Q
GETTYPE ;get type of visit - use loc current type or affiliation of provider
 S APCDALVR("APCDTYPE")=$S($P($G(^AMHSITE(DUZ(2),0)),U,2)]"":$P(^(0),U,2),1:"") Q:APCDALVR("APCDTYPE")]""
 ;S X=$P(^AUTTLOC($P(AMHR0,U,4),0),U,25) I X]"" S APCDALVR("APCDTYPE")=$S(X=1:"I",X=2:"6",X=3:"C",X=4:"U",X=5:"S",X=6:"T",1:"O") Q
 S X=$P($G(^APCCCTRL($P(AMHR0,U,4),0)),U,4) I X]"" S APCDALVR("APCDTYPE")=X Q  ;use pcc master control for site of loc of enc ihs/tucson/lab 11/30/95 patch 1
 S X=$$PPAFFL^AMHUTIL(AMHR,"I") I X S APCDALVR("APCDTYPE")=$S(X=1:"I",X=2:"C",X=3:"T",X=8:"6",1:"") I APCDALVR("APCDTYPE")]"" Q
 S X=$P($G(^APCCCTRL(DUZ(2),0)),U,4) I X]"" S APCDALVR("APCDTYPE")=X Q  ;use pcc master control
 S APCDALVR("APCDTYPE")="I" ;default to I if can't determine
 Q
XIT ;CLEAN UP AND EXIT
 D KILL
 LOCK -^AMHREC(AMHR,0)
 K AMHA,AMHACTN,APCDVDLT,AMHERROR,AMHBN,AMHHOLDC,AMHVFILE,AMHX,X,Y,DIE,DA,DIU,DIV,DIW,DR,APCDALVR,AMHDUZ,AMHVSIT,AMHR0,AMHLOOK,AMHGOT,AMHVISIT,AMHCOM,AMHP,AMHRES
 D ^XBFMK
 Q
V2 S AMHERROR="inability to create visit" G LBULL
V3 S AMHERROR="invalid visit parameters (date, location etc.)" G LBULL
V9 S AMHERROR="unable to modify visit entry "_AMHVSIT G LBULL
 ;
E1 S AMHERROR="incorrect template specification" G LBULL
E2 S AMHERROR="invalid values being passed to "_AMHVFILE G LBULL
 ;
LBULL ; SEND BULLETIN - LINK FAILURE
 K XMB
 S XMB(1)=AMHR,XMB(2)=$P(^DPT($P(AMHR0,U,8),0),U)_" (DFN "_$P(AMHR0,U,8)_")",Y=$P(AMHR0,U) D DD^%DT S XMB(3)=Y,XMB(4)=AMHERROR,XMB(5)=$G(AMHVFILE),XMB="AMH PCC LINK FAIL "_AMHBN
 D ^XMB K XMB,AMHERROR,AMHBN,AMHVFILE
 Q
BSD ;
 ;if non-interactive use APCDAPI4 and always force an add
 ;in interative mode display to user for selection
 K AMHIN,AMHHOLDC ;clean out array
 D KILL
 I '$P($G(^AMHSITE(DUZ(2),0)),U,33) S AMHIN("FORCE ADD")=1
 I $D(ZTQUEUED) S AMHIN("FORCE ADD")=1
 S AMHIN("VISIT DATE")=$P(AMHR0,U)
 D GETTYPE
 S AMHIN("VISIT TYPE")=APCDALVR("APCDTYPE")
 S AMHIN("PAT")=$P(AMHR0,U,8)
 S AMHIN("SITE")=$P(AMHR0,U,4)
 ;determine service category based on type of contact
 S AMHIN("SRV CAT")=$P(^AMHTSET($P(AMHR0,U,7),0),U,3)
 D GETCLN
 S AMHHOLDC=$G(APCDALVR("APCDCLN"))
 ;I APCDALVR("APCDCLN")]"" S AMHIN("CLINIC CODE")=APCDALVR("APCDCLN")
 S AMHIN("APCDAPPT")=$P(AMHR0,U,11)
 S AMHIN("APCDOLOC")=$P(AMHR0,U,26)
 S AMHIN("APCDEVM")=$P(AMHR0,U,29)
 S AMHIN("APCDOPT")=$P($G(XQY0),U) I AMHIN("APCDOPT")]"" S AMHIN("APCDOPT")=$O(^DIC(19,"B",AMHIN("APCDOPT"),0))
 ;S AMHIN("PROVIDER")=$$PPINT^AMHUTIL(AMHR)
 S AMHIN("APCDCAF")=$S($P($G(^AMHSITE(DUZ(2),18)),U,8):"I",1:"R")
 S AMHIN("TIME RANGE")=-1
 S AMHIN("USR")=DUZ
 S AMHIN("HOS LOC")=$$VALI^XBDIQ1(9002011,AMHR,1117)
BSDADD1 ;
 K APCDALVR
 K AMHV
 D GETVISIT^APCDAPI4(.AMHIN,.AMHV)
 S AMHERR=$P(AMHV(0),U,2)
 I AMHERR]"" Q  ;errored
 I $P(AMHV(0),U)=1 S V=$O(AMHV(0)) I AMHV(V)="ADD" S AMHVSIT=V D SETCLN Q
 ;since more than one passed back display them to the user and quit
SELECT ; SELECT EXISTING VISIT
 W !!,"PATIENT: ",$P(^DPT($P(AMHR0,U,8),0),U)," has one or more VISITs on ",$$FMTE^XLFDT($P(AMHR0,U)),".",!,"If one of these is your visit, please select it",!
 K AMHV1 S (AMHC,AMHA,AMHX)="",AMHV1=0 F  S AMHV1=$O(AMHV(AMHV1)) Q:AMHV1'=+AMHV1  S AMHX=$G(^AUPNVSIT(AMHV1,0)),AMHX11=$G(^AUPNVSIT(AMHV1,11)) D WRITE
 S AMHC=AMHC+1 W !,AMHC,"  Create New Visit",!
 K DIR
 S DIR(0)="N^1:"_AMHC,DIR("A")="Select" KILL DA D ^DIR KILL DIR
 I $D(DIRUT) S AMHIN("FORCE ADD")=1 S AMHIN("CLINIC CODE")=AMHHOLDC G BSDADD1
 I AMHC=Y S AMHIN("FORCE ADD")=1 S AMHIN("CLINIC CODE")=AMHHOLDC G BSDADD1
 S AMHVSIT=AMHX1(Y)
 K AMHIN,APCDALVR
 Q
 ;
WRITE ; WRITE VISITS FOR SELECT
 S AMHC=AMHC+1,AMHX1(AMHC)=AMHV1
 S AMHVLT=$P(+AMHX,".",2),AMHVLT=$S(AMHVLT="":"<NONE>",$L(AMHVLT)=1:AMHVLT_"0:00 ",1:$E(AMHVLT,1,2)_":"_$E(AMHVLT,3,4)_$E("00",1,2-$L($E(AMHVLT,3,4)))_" ")
 S AMHVLOC=""
 I $P(AMHX,U,6),$D(^AUTTLOC($P(AMHX,U,6),0)) S AMHVLOC=$P(^(0),U,7),AMHVLOC=AMHVLOC_$E("    ",1,4-$L(AMHVLOC))
 S:AMHVLOC="" AMHVLOC="...."
 W !,AMHC,"  TIME: ",AMHVLT,"LOC: ",AMHVLOC," TYPE: ",$P(AMHX,U,3)," CAT: ",$P(AMHX,U,7)," CLINIC: ",$S($P(AMHX,U,8)]"":$E($P(^DIC(40.7,$P(AMHX,U,8),0),U),1,8),1:"<NONE>") D
 .W ?57,"DEC: ",$S($P(AMHX,U,9):$P(AMHX,U,9),1:0),$S($P(AMHX11,U,3)]"":" VCN:"_$P(AMHX11,U,3),1:"")
 .I $P(AMHX,U,22) W !?3,"Hospital Location: ",$P($G(^SC($P(AMHX,U,22),0)),U)
 .S AMHTIU=$$PRIMPROV^APCLV(AMHV1,"N") I AMHTIU]"" W !?3,"Provider on Visit: ",AMHTIU
 .S AMHTIU=$O(^AUPNVNOT("AD",AMHV1,0)) I AMHTIU W !?3,"TIU Note: ",$$VAL^XBDIQ1(9000010.28,AMHTIU,.01),"  AUTHOR: ",$$VAL^XBDIQ1(9000010.28,AMHTIU,1202)
 .S AMHTIU=$$PRIMPOV^APCLV(AMHV1,"C") W !?3,"Primary POV: ",AMHTIU,"  Narrative: ",$E($$PRIMPOV^APCLV(AMHV1,"N"),1,40)
 K AMHVLT,AMHVLOC,AMHTIU
 Q
MRG ;EP
 S DA=$O(^AMHREC("AVISIT",APCDVMF,0))
 I DA S DIE="^AMHREC(",DR=".16////"_APCDVMT D ^DIE K DIE,DA,DR
 Q
DEL ;EP
 S DA=$O(^AMHREC("AVISIT",APCDVDLT,0))
 I DA,$P($G(^AMHREC(DA,11)),U,10) S AMHRDEL=DA D EN^AMHLEDEL Q
 I DA S DIE="^AMHREC(",DR=".16///@" D ^DIE K DIE,DA
 Q
SETCLN ;
 NEW DA,DIE,DR
 S DA=AMHVSIT,DIE="^AUPNVSIT(",DR=".08////"_AMHHOLDC
 D ^DIE
 Q