source: ccr/trunk/p/C0CALERT.m@ 1664

Last change on this file since 1664 was 1586, checked in by Sam Habiel, 12 years ago

Changed license to AGPL. Some clean-up for XINDEX

  • Property svn:mergeinfo set to (toggle deleted branches)
    /ccr/branches/ohum/o-old/p/C0CALERT.m1290
    /ccr/branches/ohum/p/C0CALERT.m1291-1543
    /ccr/branches/ohum/p/p/C0CALERT.m1287-1289
File size: 5.9 KB
Line 
1C0CALERT ; CCDCCR/CKU/GPL - CCR/CCD PROCESSING FOR ALERTS ; 09/11/08 ; 10/29/12 4:04pm
2 ;;1.2;CCD/CCR GENERATION UTILITIES;;Oct 30, 2012;Build 50
3 ;Copyright 2008,2009 George Lilly, University of Minnesota and others.
4 ;
5 ; This program is free software: you can redistribute it and/or modify
6 ; it under the terms of the GNU Affero General Public License as
7 ; published by the Free Software Foundation, either version 3 of the
8 ; License, or (at your option) any later version.
9 ;
10 ; This program is distributed in the hope that it will be useful,
11 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ; GNU Affero General Public License for more details.
14 ;
15 ; You should have received a copy of the GNU Affero General Public License
16 ; along with this program. If not, see <http://www.gnu.org/licenses/>.
17 ;
18 ;
19 W "NO ENTRY FROM TOP",!
20 Q
21 ;
22EXTRACT(ALTXML,DFN,ALTOUTXML,CALLBK) ; EXTRACT ALERTS INTO XML TEMPLATE
23 ; CALLBACK IF PROVIDED IS CALLED FOR EACH ALLERGY BEFORE MAPPING
24 ; ALTXML AND ALTOUTXML ARE PASSED BY NAME SO GLOBALS CAN BE USED
25 ;
26 ; GET ADVERSE REACTIONS AND ALLERGIES
27 ; N GMRA,GMRAL ; FOR DEBUGGING, DON'T NEW THESE VARIABLES
28 S GMRA="0^0^111"
29 D EN1^GMRADPT
30 I $G(GMRAL)'=1 D Q ; NO ALLERGIES FOUND THUS *QUIT*
31 . S @ALTOUTXML@(0)=0
32 ; DEFINE MAPPING
33 N ALTTVMAP,ALTVMAP,ALTTARYTMP,ALTARYTMP
34 S ALTTVMAP=$NA(^TMP("C0CCCR",$J,"ALERTS"))
35 S ALTTARYTMP=$NA(^TMP("C0CCCR",$J,"ALERTSARYTMP"))
36 K @ALTTVMAP,@ALTTARYTMP
37 N ALTTMP,ALTCNT S ALTG=$NA(GMRAL),ALTCNT=1
38 S ALTTMP="" ;
39 F S ALTTMP=$O(@ALTG@(ALTTMP)) Q:ALTTMP="" D ; CHANGED TO $O BY GPL
40 . W "ALTTMP="_ALTTMP,!
41 . ; I $QS(ALTTMP,2)="S" W !,"S FOUND",! Q
42 . S ALTVMAP=$NA(@ALTTVMAP@(ALTCNT))
43 . K @ALTVMAP
44 . S @ALTVMAP@("ALERTOBJECTID")="ALERT"_ALTCNT
45 . N A1 S A1=@ALTG@(ALTTMP) ; ALL THE PIECES
46 . I $D(CALLBK) D @CALLBK ;CALLBACK FOR EPRESCRIBING
47 . N A2 S A2=$$GET1^DIQ(120.8,ALTTMP,"MECHANISM","I") ; MECHANISM
48 . N A3 S A3=$P(A1,U,5) ; ADVERSE FLAG
49 . N ADT S ADT="Patient has an " ; X $ZINT H 5
50 . S ADT=ADT_$S(A2="P":"ADVERSE",A2="A":"ALLERGIC",1:"UNKNOWN")
51 . S ADT=ADT_" reaction to "_$P(@ALTG@(ALTTMP),U,2)_"."
52 . S @ALTVMAP@("ALERTDESCRIPTIONTEXT")=ADT
53 . N ADTY S ADTY=$S(A2="P":"Adverse Reaction",A2="A":"Allergy",1:"") ;
54 . S @ALTVMAP@("ALERTTYPE")=ADTY ; type of allergy
55 . N ALTCDE ; SNOMED CODE THE THE ALERT
56 . S ALTCDE=$S(A2="P":"282100009",A2="A":"416098002",1:"") ; IF NOT ADVERSE, IT IS ALLERGIC
57 . S @ALTVMAP@("ALERTCODEVALUE")=ALTCDE ;
58 . ; WILL USE 418634005 FOR ALLERGIC REACTION TO A SUBSTANCE
59 . ; AND 282100009 FOR ADVERSE REACTION TO A SUBSTANCE
60 . I ALTCDE'="" D ; IF THERE IS A CODE
61 . . S @ALTVMAP@("ALERTCODESYSTEM")="SNOMED CT"
62 . . S @ALTVMAP@("ALERTCODESYSTEMVERSION")="2008"
63 . E D ; SET TO NULL
64 . . S @ALTVMAP@("ALERTCODESYSTEM")=""
65 . . S @ALTVMAP@("ALERTCODESYSTEMVERSION")=""
66 . S @ALTVMAP@("ALERTSTATUSTEXT")="" ; WHERE DO WE GET THIS?
67 . N ALTPROV S ALTPROV=$P(^GMR(120.8,ALTTMP,0),U,5) ; SOURCE PROVIDER IEN
68 . I ALTPROV'="" D ; PROVIDER PROVIDEED
69 . . S @ALTVMAP@("ALERTSOURCEID")="ACTORPROVIDER_"_ALTPROV
70 . E S @ALTVMAP@("ALERTSOURCEID")="" ; SOURCE NULL - SHOULD NOT HAPPEN
71 . W "RUNNING ALERTS, PROVIDER: ",@ALTVMAP@("ALERTSOURCEID"),!
72 . N ACGL1,ACGFI,ACIEN,ACVUID,ACNM,ACTMP
73 . S ACGL1=$P(@ALTG@(ALTTMP),U,9) ; ADDRESS OF THE REACTANT XX;GLB(YY.Z,
74 . S ACGFI=$$PRSGLB($P(ACGL1,";",2)) ; FILE NUMBER
75 . S ACIEN=$P(ACGL1,";",1) ; IEN OF REACTANT
76 . S ACVUID=$$GET1^DIQ(ACGFI,ACIEN,"VUID") ; VUID OF THE REACTANT
77 . S @ALTVMAP@("ALERTAGENTPRODUCTOBJECTID")="PRODUCT_"_ACIEN ; IE OF REACTANT
78 . S @ALTVMAP@("ALERTAGENTPRODUCTSOURCEID")="" ; WHERE DO WE GET THIS?
79 . S ACNM=$P(@ALTG@(ALTTMP),U,2) ; REACTANT
80 . S @ALTVMAP@("ALERTAGENTPRODUCTNAMETEXT")=ACNM
81 . N ZC,ZCD,ZCDS,ZCDSV ; CODE,CODE SYSTEM,CODE VERSION
82 . S (ZC,ZCD,ZCDS,ZCDSV)="" ; INITIALIZE
83 . I ACVUID'="" D ; IF VUID IS NOT NULL
84 . . S ZC=$$CODE^C0CUTIL(ACVUID)
85 . . S ZCD=$P(ZC,"^",1) ; CODE TO USE
86 . . S ZCDS=$P(ZC,"^",2) ; CODING SYSTEM - RXNORM OR VUID
87 . . S ZCDSV=$P(ZC,"^",3) ; CODING SYSTEM VERSION
88 . E D ; IF REACTANT CODE VALUE IS NULL
89 . . I $G(DUZ("AG"))="I" D ; IF WE ARE RUNNING ON RPMS
90 . . . S ACTMP=$O(^C0CCODES(176.112,"C",ACNM,0)) ;
91 . . . W "RPMS NAME FOUND",ACNM," ",ACTMP,!
92 . . S @ALTVMAP@("ALERTAGENTPRODUCTCODESYSTEM")=""
93 . . S @ALTVMAP@("ALERTAGENTPRODUCTCODEVALUE")=""
94 . S @ALTVMAP@("ALERTAGENTPRODUCTCODEVALUE")=ZCD
95 . S @ALTVMAP@("ALERTAGENTPRODUCTCODESYSTEM")=ZCDS
96 . S @ALTVMAP@("ALERTAGENTPRODUCTNAMETEXT")=ACNM_" "_ZCDS_": "_ZCD
97 . S @ALTVMAP@("ALERTDESCRIPTIONTEXT")=ADT_" "_ZCDS_": "_ZCD
98 . ; REACTIONS - THIS SHOULD BE MULTIPLE, IS SINGLE NOW
99 . N ARTMP,ARIEN,ARDES,ARVUID
100 . S (ARTMP,ARDES,ARVUID)=""
101 . I $D(@ALTG@(ALTTMP,"S",1)) D ; IF REACTION EXISTS
102 . . S ARTMP=@ALTG@(ALTTMP,"S",1)
103 . . W "REACTION:",ARTMP,!
104 . . S ARIEN=$P(ARTMP,";",2)
105 . . S ARDES=$P(ARTMP,";",1)
106 . . S ARVUID=$$GET1^DIQ(120.83,ARIEN,"VUID")
107 . S @ALTVMAP@("ALERTREACTIOINDESCRIPTIONTEXT")=ARDES
108 . I ARVUID'="" D ; IF REACTION VUID IS NOT NULL
109 . . S @ALTVMAP@("ALERTREACTIONCODEVALUE")=ARVUID
110 . . S @ALTVMAP@("ALERTREACTIONCODESYSTEM")="VUID"
111 . E D ; IF IT IS NULL DON'T SET CODE SYSTEM
112 . . S @ALTVMAP@("ALERTREACTIONCODEVALUE")=""
113 . . S @ALTVMAP@("ALERTREACTIONCODESYSTEM")=""
114 . S ALTARYTMP=$NA(@ALTTARYTMP@(ALTCNT))
115 . ; NOW GO TO THE GLOBAL TO GET THE DATE/TIME AND BETTER DESCRIPTION
116 . N C0CG1,C0CT ; ARRAY FOR VALUES FROM GLOBAL
117 . D GETN1^C0CRNF("C0CG1",120.8,ALTTMP,"") ;GET VALUES BY NAME
118 . S C0CT=$$ZVALUEI^C0CRNF("ORIGINATION DATE/TIME","C0CG1")
119 . S @ALTVMAP@("ALERTDATETIME")=$$FMDTOUTC^C0CUTIL(C0CT,"DT")
120 . K @ALTARYTMP
121 . D MAP^C0CXPATH(ALTXML,ALTVMAP,ALTARYTMP)
122 . I ALTCNT=1 D CP^C0CXPATH(ALTARYTMP,ALTOUTXML)
123 . I ALTCNT>1 D INSINNER^C0CXPATH(ALTOUTXML,ALTARYTMP)
124 . S ALTCNT=ALTCNT+1
125 S @ALTTVMAP@(0)=ALTCNT-1 ; RECORD THE NUMBER OF ALERTS
126 Q
127PRSGLB(INGLB) ; EXTRINSIC TO PARSE GLOBALS AND RETURN THE FILE NUMBER
128 ; INGLB IS OF THE FORM: PSNDF(50.6,
129 ; RETURN 50.6
130 Q $P($P(INGLB,"(",2),",",1) ;
Note: See TracBrowser for help on using the repository browser.