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

AMHLEDEL.m

Go to the documentation of this file.
AMHLEDEL ; IHS/CMI/LAB - DELETE BH RECORD ;
 ;;4.0;IHS BEHAVIORAL HEALTH;;MAY 14, 2010
 ;
EN ;EP
 ;
 NEW X,Y,AMHX,AMHY,AMHGO
DELETE ;
 S AMHGRP=$P(^AMHREC(AMHRDEL,0),U,34)
 S AMHPAT=$P(^AMHREC(AMHRDEL,0),U,8)
 Q:$$IINTAKE(AMHRDEL)  ;quit if the visit has an initial intake with update documents
 S AMHVFLE=9002011 F AMHVL=0:0 S AMHVFLE=$O(^DIC(AMHVFLE)) Q:AMHVFLE>9002011.49!(AMHVFLE'=+AMHVFLE)  D DELETE2
 S DA=$O(^AMHRCDST("B",AMHRDEL,0)) I DA S DIK="^AMHRCDST(" D ^DIK ;delete staging tool
 S DIK="^AMHREC(",DA=AMHRDEL,X=2 D ^DIK K DA,DIK
 I $G(AMHGRP) D GRPDEL(AMHRDEL,AMHPAT)  ;cmi/maw added for group delete
 D EOJ
 Q
 ;
DELETE2 ;
 I AMHVFLE=9002011.13 D INTAKE Q
 S AMHVNM=$P(^DIC(AMHVFLE,0),U)
 S AMHVDG=^DIC(AMHVFLE,0,"GL"),AMHVIGR=AMHVDG_"""AD"",AMHRDEL,AMHVDFN)"
 S AMHVDFN="" F AMHVI=1:1 S AMHVDFN=$O(@AMHVIGR) Q:AMHVDFN=""  W:'$D(ZTQUEUED) "." S DIK=AMHVDG,DA=AMHVDFN D ^DIK
 Q
 ;
GRPDEL(REC,PAT) ;-- delete the group record and patient entry from group
 N GDA
 S GDA=0 F  S GDA=$O(^AMHGROUP("AREC",REC,GDA)) Q:'GDA  D
 . S GIEN=0 F  S GIEN=$O(^AMHGROUP("AREC",REC,GDA,GIEN)) Q:'GIEN  D
 .. D GRECDIK(GDA,GIEN)
 .. D GPATDIK(PAT,GDA)
 Q
 ;
GRECDIK(D,I) ;-- delete the record from the group 6101 multiple
 S DA(1)=GDA
 S DA=I
 S DIK="^AMHGROUP("_DA(1)_",61,"
 D ^DIK
 Q
 ;
GPATDIK(PT,D) ;-- remove the patient from the group 5101 multiple
 K DA
 S DA=$O(^AMHGROUP(D,51,"B",PT,0))
 Q:'DA
 S DA(1)=D
 S DIK="^AMHGROUP("_DA(1)_",51,"
 D ^DIK
 Q
 ;
EOJ ; EOJ CLEANUP
 K AMHVDFN,AMHVDG,AMHRDEL,AMHVFLE,AMHVI,AMHVIGR,AMHVL,AMHVNM,AMHGRP,AMHPAT
 K %,X
 K D,D0,DA,DIC,DICR,DIE,DIG,DIH,DIU,DIV,DIW,DQ,DR,DIK,DITC
 Q
IINTAKE(R) ;EP - does this visit have an initial intake with updates?
 NEW X,Y,G
 S G=""
 S X=0 F  S X=$O(^AMHRINTK("AD",R,X)) Q:X'=+X!(G)  D
 .I $O(^AMHRINTK("AI",X,0)) S G=1
 .Q
 Q G
INTAKE ;
 Q  ;;NO VISIT LINK ANYMORE
 S (C,AMHX)=0 F  S AMHX=$O(^AMHRINTK("AD",AMHRDEL,AMHX)) Q:AMHX'=+AMHX  D
 .I $P(^AMHRINTK(AMHX,0),U,3)=AMHRDEL D
 ..S DITC=1,DIE="^AMHRINTK(",DA=AMHX,DR=".03///@" D ^DIE K DIE,DA,DR,DITC
 ..S Z=$O(^AMHRINTK(AMHX,11,"B",AMHRDEL,0)) I 'Z Q
 ..S DIE="^AMHRINTK("_AMHX_",11,",DA(1)=AMHX,DA=Z,DR=".01///@" D ^DIE K DIE,DA,DR,DITC
 .S AMHY=0 F  S AMHY=$O(^AMHRINTK("AD",AMHRDEL,AMHX,AMHY)) Q:AMHY'=+AMHY  D
 ..I $P(^AMHRINTK(AMHX,11,AMHY,0),U)=AMHRDEL S DIE="^AMHRINTK("_AMHX_",11,",DA(1)=AMHX,DA=AMHY,DR=".01///@" D ^DIE K DIE,DA,DR
 .I $P(^AMHRINTK(AMHX,0),U,3)="",'$O(^AMHRINTK(AMHX,11,0)) S DIK="^AMHRINTK(",DA=AMHX D ^DIK Q
 .Q:$P(^AMHRINTK(AMHX,0),U,3)
 .S X=$O(^AMHRINTK(AMHX,11,0)),X=$P(^AMHRINTK(AMHX,11,X,0),U,1)
 .S DA=AMHX,DIE="^AMHRINTK(",DITC=1,DR=".03////"_X D ^DIE K DIE,DA,DR,DITC
 .Q
 Q