source: FOIAVistA/trunk/r/ADVERSE_REACTION_TRACKING-GMRA-GMA/GMRAUTL2.m@ 1607

Last change on this file since 1607 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 9.5 KB
Line 
1GMRAUTL2 ;SLC/DAN New style index utilities, update utility for 120.8 ;1/3/07 08:02
2 ;;4.0;Adverse Reaction Tracking;**23,36**;Mar 29, 1996;Build 9
3 ;
4 N GMRAI,GMRAC,ENTRY,UPDATED
5 Q:$G(X1(1))=$G(X2(1)) ;Entry unchanged
6 S ENTRY=DA(1)_";GMRD(120.82,"_"^"_$P(^GMRD(120.82,DA(1),0),"^")
7 I $G(X1(1))>0,$G(X2(1))>0 S:$G(GMRAT)="ING" GMRAI("D",X1(1))="",GMRAI("A",X2(1))="" S:$G(GMRAT)="CLASS" GMRAC("D",X1(1))="",GMRAC("A",X2(1))="" ;Edited existing entry
8 I $G(X1(1))>0,$G(X2(1))="" S:$G(GMRAT)="ING" GMRAI("D",X1(1))="" S:$G(GMRAT)="CLASS" GMRAC("D",X1(1))="" ;Entry deleted
9 I $G(X1(1))="",$G(X2(1))>0 S:$G(GMRAT)="ING" GMRAI("A",X2(1))="" S:$G(GMRAT)="CLASS" GMRAC("A",X2(1))="" ;New entry
10 D QUP ;Queue updating of existing entries and order checking
11 Q
12 ;
13QUP ;Queue the update
14 S ZTRTN="UPDATE^GMRAUTL2(ENTRY,.GMRAI,.GMRAC)",ZTIO="GMRA UPDATE RESOURCE",ZTDTH=$H,ZTDESC="Update existing allergies",ZTSAVE("*")="" D ^%ZTLOAD Q
15 ;
16UPDATE(ENTRY,ING,CLASS) ;Update existing entries in 120.8 with new information.
17 ;Entry is IEN;File reference^Text of file entry - 6;GMRD(120.82,^STRAWBERRIES
18 ;ING - Array of ingredients - "A",IEN for those to be added and "D",IEN for those to be deleted
19 ;CLASS - Array of drug classes - "A",IEN for those to be added and "D",IEN for those to be deleted
20 ;
21 N ALLERGY,POINTER,ACTION,SUB,SUBI,SUBC,DFN,GMRAS,GMRACOM
22 S ALLERGY=$P(ENTRY,"^",2) Q:ALLERGY=""
23 S POINTER=$P(ENTRY,"^") Q:POINTER=""
24 S SUB=0 F S SUB=$O(^GMR(120.8,"C",ALLERGY,SUB)) Q:'+SUB D
25 .S DFN=$P(^GMR(120.8,SUB,0),U)
26 .Q:$$DECEASED^GMRAFX(DFN) ;Don't update if patient is deceased
27 .Q:$P(^GMR(120.8,SUB,0),"^",3)'=POINTER ;Same text name but not the same entry
28 .Q:$G(^GMR(120.8,SUB,"ER"))>0 ;Entered in error
29 .S GMRACOM=0
30 .F ACTION="A","D" D
31 ..S SUBI=0 F S SUBI=$O(ING(ACTION,SUBI)) Q:'+SUBI D
32 ...I ACTION="A" D ADD("I",SUB,SUBI,.GMRAS) I $G(GMRAS) S ING(ACTION,SUBI)=1,GMRACOM=1,UPDATED(DFN)=""
33 ...I ACTION="D" D DEL("I",SUB,SUBI,.GMRAS) I $G(GMRAS) S ING(ACTION,SUBI)=1,GMRACOM=1
34 ..S SUBC=0 F S SUBC=$O(CLASS(ACTION,SUBC)) Q:'+SUBC D
35 ...I ACTION="A" D ADD("C",SUB,SUBC,.GMRAS) I $G(GMRAS) S CLASS(ACTION,SUBC)=1,UPDATED(DFN)="",GMRACOM=1
36 ...I ACTION="D" D DEL("C",SUB,SUBC,.GMRAS) I $G(GMRAS) S GMRACOM=1,CLASS(ACTION,SUBC)=1
37 .I $G(GMRACOM) D ADDCOM
38 I $D(UPDATED) D CHKORD ;New order checks now?
39 Q
40 ;
41ADD(TYPE,ALENT,SUBENT,GMRAS) ;Adds entry to appropriate multiple
42 N FILE,FDA,EM
43 S GMRAS=1
44 I $D(^GMR(120.8,ALENT,$S(TYPE="I":2,1:3),"B",SUBENT)) S GMRAS=0 Q ;Entry already exists
45 L +^GMR(120.8,ALENT)
46 S FILE=$S(TYPE="I":120.802,1:120.803)
47 S FDA(FILE,"+1,"_ALENT_",",.01)=SUBENT
48 D UPDATE^DIE("","FDA",,"EM")
49 L -^GMR(120.8,ALENT)
50 Q
51 ;
52DEL(TYPE,ALENT,SUBENT,GMRAS) ;Delete entry from multiple
53 N FILE,FDA,EM,ENTRY
54 S GMRAS=1
55 I '$D(^GMR(120.8,ALENT,$S(TYPE="I":2,1:3),"B",SUBENT)) S GMRAS=0 Q ;No entry to delete
56 L +^GMR(120.8,ALENT)
57 S ENTRY=$O(^GMR(120.8,ALENT,$S(TYPE="I":2,1:3),"B",SUBENT,0)) Q:'+ENTRY
58 S FILE=$S(TYPE="I":120.802,1:120.803)
59 S FDA(FILE,ENTRY_","_ALENT_",",.01)="@"
60 D FILE^DIE("","FDA","EM")
61 L -^GMR(120.8,ALENT)
62 Q
63 ;
64CHKORD ;Check for orders that are now in conflict with existing allergy data
65 N TIME,GMRAOC,ORX,SUB,GMRAORX,GI,CNT,DFN
66 Q:'+$G(DUZ) ;Don't check if no valid user to send data to
67 K ^TMP("ORR",$J),^TMP($J,"ERR")
68 S DFN=0 F S DFN=$O(UPDATED(DFN)) Q:'+DFN D
69 .D EN^ORQ1(DFN_";DPT(") ;Retrieve active orders
70 .S TIME=$O(^TMP("ORR",$J,0))
71 .Q:'^TMP("ORR",$J,TIME,"TOT") ;No orders found
72 .S SUB=0 F S SUB=$O(^TMP("ORR",$J,TIME,SUB)) Q:'+SUB D
73 ..D BLD^ORCHECK(+^TMP("ORR",$J,TIME,SUB)) ;Get "order" information in order checking format
74 .M GMRAORX=ORX K ORX,GMRAOC
75 .D EN^ORKCHK(.GMRAOC,DFN,.GMRAORX,"ACCEPT")
76 .S GI=0,CNT=0 F S GI=$O(GMRAOC(GI)) Q:'+GI D
77 ..Q:$P(GMRAOC(GI),U,2)'=3 ;Quit if not allergy related
78 ..Q:$D(^OR(100,$P(GMRAOC(GI),U),9,"B",3)) ;Quit if existing allergy order check, can't be for this new information
79 ..S CNT=CNT+1,^TMP($J,"ERR",DFN,CNT)=$P($$STATUS^ORQOR2($P(GMRAOC(GI),U)),U,2)_" order for "_$P($$OI^ORX8($P(GMRAOC(GI),U)),U,2)_",order #"_$P(GMRAOC(GI),U)
80 .K GMRAORX ;Remove previous list of orders
81 D MAIL K ^TMP("ORR",$J),^TMP($J,"ERR")
82 Q
83 ;
84ADDCOM ;Add comment to updated allergy indicating changes
85 Q
86 N TYPE,ROOT,SUB2,DICR,DIEL,DL,DP,DM,DK,DIK,DC,DE,GLOB,DH,D,DQ,DR,DIC,DIE,DIA,DI,DG,DDH,DDER,DA,D0,D1
87 F GLOB="ING(""A"")","ING(""D"")","CLASS(""A"")","CLASS(""D"")" I $D(@GLOB) D
88 .S TYPE=$S(GLOB="ING(""A"")":1,GLOB="ING(""D"")":2,GLOB="CLASS(""A"")":3,1:4) ;Determines if we're adding or deleting ingredients or classes
89 .S COM="The following "_$S(TYPE=1!(TYPE=2):"ingredients",1:"drug classes")_" were "_$S(TYPE=2!(TYPE=4):"deleted",1:"added")_": "
90 .S ROOT=$S(TYPE=1:"ING(""A"")",TYPE=2:"ING(""D"")",TYPE=3:"CLASS(""A"")",1:"CLASS(""D"")")
91 .S SUB2=0 F S SUB2=$O(@ROOT@(SUB2)) Q:'+SUB2 I @ROOT@(SUB2) S COM=COM_$S($P(COM,": ",2)'="":", ",1:"")_$S(TYPE=1!(TYPE=2):$$GET1^DIQ(50.416,SUB2_",",.01),1:$$GET1^DIQ(50.605,SUB2_",",.01))
92 .I $P(COM,": ",2)'="" L +^GMR(120.8,SUB) D ADCOM^GMRAFX(SUB,"O",COM) L -^GMR(120.8,SUB)
93 Q
94 ;
95MAIL ;Send message containing potential order checks to user.
96 N XMSUB,XMTEXT,XMDUZ,XMY,XMZ,CNT,SUB,ERR,TYPE,NUM
97 Q:'$D(^TMP($J,"ERR")) ;Nothing to report
98 K ^TMP($J,"TEXT")
99 S XMDUZ="Allergy auto-update program"
100 S XMY($G(DUZ,.5))="" ;Send to user who initiated change or postmaster
101 S XMY("G.GMRA REQUEST NEW REACTANT")="" ;Include mail group to be sure someone gets this message
102 S CNT=1
103 S ^TMP($J,"TEXT",CNT)="The "_$P(ENTRY,U,2)_" reactant was updated.",CNT=CNT+1
104 S ^TMP($J,"TEXT",CNT)="The following drug classes and/or drug ingredients were added:",CNT=CNT+1,^TMP($J,"TEXT",CNT)="",CNT=CNT+1
105 F TYPE="GMRAI","GMRAC" D
106 .I $D(@(TYPE)) D
107 ..S ^TMP($J,"TEXT",CNT)=$S(TYPE="GMRAI":"Ingredients",1:"Classes")_": ",CNT=CNT+1
108 ..S NUM=0 F S NUM=$O(@TYPE@("A",NUM)) Q:'+NUM S ^TMP($J,"TEXT",CNT)=$G(^TMP($J,"TEXT",CNT))_$S($L($G(^TMP($J,"TEXT",CNT))):",",1:"")_$$GET1^DIQ($S(TYPE="GMRAI":50.416,1:50.605),NUM_",",.01)
109 ..S CNT=CNT+1,^TMP($J,"TEXT",CNT)="",CNT=CNT+1
110 S ^TMP($J,"TEXT",CNT)="As a result of the update the following patients have drug-allergy",CNT=CNT+1
111 S ^TMP($J,"TEXT",CNT)="interactions that need to be reviewed to ensure the patient's safety.",CNT=CNT+1
112 S SUB=0 F S SUB=$O(^TMP($J,"ERR",SUB)) Q:'+SUB D
113 .S ^TMP($J,"TEXT",CNT)="",CNT=CNT+1
114 .S ^TMP($J,"TEXT",CNT)=$$GET1^DIQ(2,SUB_",",.01),CNT=CNT+1
115 .S ERR=0 F S ERR=$O(^TMP($J,"ERR",SUB,ERR)) Q:'+ERR S ^TMP($J,"TEXT",CNT)=" "_^TMP($J,"ERR",SUB,ERR),CNT=CNT+1
116 S XMTEXT="^TMP($J,""TEXT"",",XMSUB="Potential order checks from allergy update"
117 D ^XMD
118 K ^TMP($J,"TEXT")
119 Q
120 ;
121TOP10 ;Check top 10 reactions after push of file 120.83
122 N SUB,REAC,REACNO,ARRAY,SUBNM,REACNM,GMRATXT,XMSUB,XMTEXT,XMDUZ,XMY,DIFROM,CNT
123 I '$L($T(SCREEN^XTID)) Q ;No screening code so quit
124 S SUB=0 F S SUB=$O(^GMRD(120.84,SUB)) Q:'+SUB I $D(^GMRD(120.84,SUB,1)) D
125 .S REAC=0 F S REAC=$O(^GMRD(120.84,SUB,1,REAC)) Q:'+REAC D
126 ..S REACNO=$P(^GMRD(120.84,SUB,1,REAC,0),U) Q:'+REACNO
127 ..I $$SCREEN^XTID(120.83,.01,REACNO_",") D
128 ...S SUBNM=$P(^GMRD(120.84,SUB,0),U),REACNM=$P(^GMRD(120.83,REACNO,0),U)
129 ...S ARRAY(SUBNM,REACNM)=""
130 I $D(ARRAY) D
131 .S XMDUZ="Data Standardization update of file 120.83",XMY("G.GMRA REQUEST NEW REACTANT")=""
132 .S GMRATXT(1)="The signs/symptoms file has been automatically updated. You're receiving"
133 .S GMRATXT(2)="this message because one or more signs/symptoms was inactivated during this"
134 .S GMRATXT(3)="update and the term(s) appear in your top ten list and must be replaced."
135 .S GMRATXT(4)="Below you will find the name of the site parameter and the terms that are now"
136 .S GMRATXT(5)="inactive for that entry. Use the Enter/Edit Site Parameters [GMRA SITE FILE]"
137 .S GMRATXT(6)="option to find and replace these terms."
138 .S GMRATXT(7)=""
139 .S CNT=7
140 .S SUB="" F S SUB=$O(ARRAY(SUB)) Q:SUB="" S CNT=CNT+1,GMRATXT(CNT)="Site parameter: "_SUB D S CNT=CNT+1,GMRATXT(CNT)=""
141 ..S REAC="" F S REAC=$O(ARRAY(SUB,REAC)) Q:REAC="" S CNT=CNT+1,GMRATXT(CNT)="Term: "_REAC
142 .S XMTEXT="GMRATXT(",XMSUB="Signs/symptoms require updating"
143 .D ^XMD
144 Q
145 ;
146QREACT ;Queue name update, called from "AC" xref in file 120.82. Entire section added in patch 23
147 N OTERM,NTERM,ZTRTN,ZTDTH,ZTIO,ZTDESC
148 Q:X1(1)=""!(X2(1)="") ;Entry is new or has been deleted, no updating required
149 Q:X1(1)=X2(1) ;Entry has been updated to same value, no updating required
150 S OTERM=X1(1),NTERM=X2(1)
151 S ZTRTN="REACT^GMRAUTL2",ZTIO="GMRA UPDATE RESOURCE",ZTDTH=$H,ZTDESC="UPDATE REACTANT FIELD IN 120.8",ZTSAVE("*")="" D ^%ZTLOAD
152 Q
153 ;
154REACT ;Update REACTANT field with name from 120.82. Section added with patch 23
155 N IEN,FDA,EM,DFN
156 S IEN=0 F S IEN=$O(^GMR(120.8,"C",OTERM,IEN)) Q:'+IEN D
157 .S DFN=$P(^GMR(120.8,IEN,0),U)
158 .Q:$$DECEASED^GMRAFX(DFN) ;Don't update if patient is deceased
159 .Q:+$G(^GMR(120.8,IEN,"ER")) ;Don't update if entered in error
160 .L +^GMR(120.8,IEN)
161 .S FDA(120.8,IEN_",",.02)=NTERM
162 .D FILE^DIE("","FDA","EM")
163 .L -^GMR(120.8,IEN)
164 Q
165 ;
166QTYPE ;Queue allergy type updates, section added in 36
167 N ENTRY
168 S ENTRY=DA_";GMRD(120.82,"_"^"_$P(^GMRD(120.82,DA,0),"^")
169 Q:X1(1)=""!(X2(1)="")
170 Q:X1(1)=X2(1)
171 S ZTRTN="TYPE^GMRAUTL2",ZTIO="",ZTDTH=$H,ZTDESC="Allergy type updates",ZTSAVE("*")="" D ^%ZTLOAD
172 Q
173 ;
174TYPE ;Find related entries in 120.8 and update, section added in 36
175 N ALLERGY,POINTER,DFN,SUB
176 S ALLERGY=$P(ENTRY,"^",2) Q:ALLERGY=""
177 S POINTER=$P(ENTRY,"^") Q:POINTER=""
178 S SUB=0 F S SUB=$O(^GMR(120.8,"C",ALLERGY,SUB)) Q:'+SUB D
179 .Q:$P(^GMR(120.8,SUB,0),"^",3)'=POINTER ;Same text name but not the same entry
180 .S DFN=$P(^GMR(120.8,SUB,0),U)
181 .Q:$$DECEASED^GMRAFX(DFN) ;Don't update if patient is deceased
182 .Q:$G(^GMR(120.8,SUB,"ER"))>0 ;Entered in error
183 .S DR="3.1///"_X2(1),DIE=120.8,DA=SUB D ^DIE ;Update allergy type
184 Q
Note: See TracBrowser for help on using the repository browser.