source: fmts/trunk/p/C0XPT2.m@ 1659

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

Added processing for encounters, pass 1

File size: 5.6 KB
Line 
1C0XPT2 ; VEN/SMH - Get and Store Allergies/ADRs ;2013-05-01 9:54 AM
2 ;;1.1;FILEMAN TRIPLE STORE;;
3 ; (C) Sam Habiel 2013
4 ; Proprietary code. Stay out!
5 ;
6ADR(G,DFN) ; Private Proc; Extract Allergies and ADRs from Graph and add to Patient's Record
7 ; Input: G, Patient Graph, DFN, you should know that that is; Both by value.
8 ;
9 ; Try No known allergies first.
10 N NKA S NKA=$$ONETYPE1^C0XGET3(G,"sp:AllergyExclusion") ; Get NKA node
11 ;
12 ; Add NKA to record.
13 ; We don't really care about the return value. If patient already has
14 ; allergies, we just keep them.
15 I $L(NKA) N % S %=$$NKA(DFN) QUIT ; If it exists, let's try to file it into VISTA
16 ;
17 ; If we are here, it means that the patient has allergies. Fun!
18 ; Process incoming allergies
19 N RETURN ; Local return variable. I don't expect a patient to have more than 50 allergies.
20 D ONETYPE^C0XGET3($NA(RETURN),G,"sp:Allergy") ; Get all allergies for patient
21 ;
22 N S F S=0:0 S S=$O(RETURN(S)) Q:'S D ; For each allergy
23 . ; Get the SNOMED code for the category
24 . N ALLERGYTYPE
25 . N SNOCAT S SNOCAT=$$GSPO1^C0XGET3(G,RETURN(S),"sp:category.sp:code"),SNOCAT=$P(SNOCAT,"/",$L(SNOCAT,"/"))
26 . I SNOCAT=414285001 S ALLERGYTYPE="F" ; Food
27 . E I SNOCAT=416098002 S ALLERGYTYPE="D" ; Drug
28 . I '$D(ALLERGYTYPE) S $EC=",U1," ; Crash if neither of these is true.
29 . ;
30 . N ALLERGEN,ALLERGENI ; Allergen, Internal Allergen
31 . I ALLERGYTYPE="F" D ; Food
32 . . S ALLERGEN=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:otherAllergen.dcterms:title")) ; uppercase the allergen
33 . . I ALLERGEN="PEANUT" S ALLERGEN="PEANUTS" ; TODO: temporary fix
34 . . S ALLERGENI=$$GMRA(ALLERGEN) ; Get internal representation for GMRA call
35 . ;
36 . ; Otherwise, it's a drug. But we need to find out if it's a class,
37 . ; ingredient, canonical drug, etc. Unfortunately, Smart examples don't
38 . ; show such variety. The only one specified is a drug class.
39 . ; Therefore
40 . ; TODO: Handle other drug items besides drug class
41 . ;
42 . E D ; Drug Class
43 . . N DC S DC=$$GSPO1^C0XGET3(G,RETURN(S),"sp:drugClassAllergen.sp:code") ; drug class
44 . . I '$L(DC) QUIT ; edit this line out when handling other items
45 . . S ALLERGEN=$P(DC,"/",$L(DC,"/")) ; Get last piece
46 . . ; TODO: Resolve drug class properly. Need all of RxNorm for that.
47 . . N STR S STR=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:drugClassAllergen.dcterms:title"))
48 . . I ALLERGEN="N0000175503" S ALLERGENI=STR_U_"23;PS(50.605," ; hard codeded for sulfonamides
49 . . ;
50 . ; DEBUG.ASSERT THAT allergen Internal isn't empty
51 . I '$L(ALLERGENI) S $EC=",U1,"
52 . ;
53 . ; Get Severity (Mild or Severe) - We get free text rather than SNOMED
54 . N SEVERITY S SEVERITY=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:severity.dcterms:title"))
55 . I '$L(SEVERITY) S $EC=",U1,"
56 . ;
57 . ; Get Reaction - We get free text rather than SNOMED
58 . N REACTION S REACTION=$$UP^XLFSTR($$GSPO1^C0XGET3(G,RETURN(S),"sp:allergicReaction.dcterms:title"))
59 . I '$L(REACTION) S $EC=",U1,"
60 . ;
61 . ; Now that we have determined the allergy, add it
62 . D FILEADR(DFN,ALLERGENI,REACTION,SEVERITY,ALLERGYTYPE) ; Internal API
63 QUIT
64 ;
65NKA(DFN) ; Public $$; Add no known allergies to patient record
66 N ORDFN S ORDFN=DFN ; CPRS API requires this one
67 N ORY ; Return value: 0 - Everything is okay; -1^msg: Patient already has allergies
68 D NKA^GMRAGUI1 ; API
69 QUIT $G(ORY) ; Not always returned
70 ;
71GMRA(NAME) ; $$ Private - Retrieve GMRAGNT for food allergy from 120.82
72 ; Input: Brand Name, By Value
73 ; Output: Entry Name^IEN;File Root for IEN
74 N C0PIEN S C0PIEN=$$FIND1^DIC(120.82,"","O",NAME,"B")
75 Q:C0PIEN $$GET1^DIQ(120.82,C0PIEN,.01)_"^"_C0PIEN_";GMRD(120.82,"
76 QUIT "" ; no match otherwise
77 ;
78TYPE(GMRAGNT) ; $$ Private - Get allergy Type (Drug, food, or other)
79 ; Input: Allergen, formatted as Allergen^IEN;File Root
80 ; Output: Type (internal)^Type (external) e.g. D^Drug
81 N C0PIEN S C0PIEN=+$P(GMRAGNT,U,2)
82 I GMRAGNT["GMRD(120.82," Q $$GET1^DIQ(120.82,C0PIEN,"ALLERGY TYPE","I")_U_$$GET1^DIQ(120.82,C0PIEN,"ALLERGY TYPE","E")
83 Q "D^Drug" ; otherwise, it's a drug
84 ;
85FILEADR(DFN,AGENT,REACTION,SEVERITY,TYPE,DATE) ; Private Proc - File Drug Reaction
86 ; This is very messy right now. The more use this gets, the better idea
87 ; I will have of how much data resolution this API should expect and how
88 ; much it should do itself.
89 ;
90 K ^TMP($J,"ADR")
91 S ^TMP($J,"ADR","GMRAGNT")=AGENT ; Agent Free Text^Agent in variable pointer format
92 S ^TMP($J,"ADR","GMRATYPE")=TYPE ; F(ood), D(rug), or O(ther) or combination.
93 S ^TMP($J,"ADR","GMRANATR")="U^Unknown" ; Mechanism: Allergic, Pharmacologic, or Unknown
94 S ^TMP($J,"ADR","GMRAORIG")=$$NP^C0XPT0 ; New Person generated for SMART
95 S ^TMP($J,"ADR","GMRAORDT")=$G(DATE,$$NOW^XLFDT) ; Origination Date; Ideally, would have a date for the allergy.
96 S ^TMP($J,"ADR","GMRACHT",0)=1 ; Mark Chart as allergy document; don't know why; CPRS does that.
97 S ^TMP($J,"ADR","GMRACHT",1)=$$NOW^XLFDT ; Chart documentation date; don't know why; CPRS does that.
98 S ^TMP($J,"ADR","GMRAOBHX")="h^HISTORICAL" ; or o^Observered
99 S ^TMP($J,"ADR","GMRACMTS",0)=1 ; Comments
100 S ^TMP($J,"ADR","GMRACMTS",1)=SEVERITY ; Store severity in the comments (Severity in VISTA only applies to observed allergies)
101 S ^TMP($J,"ADR","GMRASYMP",0)=1 ; One Symptom
102 ;
103 ; Find IEN of Reaction from S/S file. We say "Q - Don't transform; X - exact match only; Screen on VUID status"
104 N RXN S RXN=$$FIND1^DIC(120.83,,"QX",REACTION,"B^D","I '$$SCREEN^XTID(120.83,.01,Y_"","")") ; Get Reaction IEN
105 I RXN S ^TMP($J,"ADR","GMRASYMP",1)=RXN_U_REACTION ; Coded reaction
106 E S ^TMP($J,"ADR","GMRASYMP",1)="FT"_U_REACTION ; Free Text Reaction
107 ;
108 N ORY ; Return value 0: success; -1: failure; discarded.
109 D UPDATE^GMRAGUI1("",DFN,$NA(^TMP($J,"ADR")))
110 K ^TMP($J,"ADR")
111 QUIT
Note: See TracBrowser for help on using the repository browser.