1 | C0XPT0 ; VEN/SMH - Get patient data and do something about it ;2013-02-19 12:01 PM
|
---|
2 | ;;1.1;FILEMAN TRIPLE STORE;;
|
---|
3 | ;
|
---|
4 | ; Get all graphs
|
---|
5 | NEW RETURN
|
---|
6 | DO GRAPHS^C0XGET1(.RETURN) ; TODO: Return could be a global due to large data.
|
---|
7 | N I S I="" F S I=$O(RETURN(I)) Q:I="" D ; For each IEN
|
---|
8 | . N G S G="" F S G=$O(RETURN(I,G)) Q:G="" D ; For each graph tied to IEN
|
---|
9 | . . D PROGRAPH(G) ; Process Graph
|
---|
10 | QUIT
|
---|
11 | ;
|
---|
12 | PROGRAPH(G) ; Process Graph (i.e. Patient)
|
---|
13 | NEW RETURN
|
---|
14 | N DEM S DEM=$$ONETYPE1^C0XGET3(G,"sp:Demographics")
|
---|
15 | I DEM="" QUIT
|
---|
16 | ;
|
---|
17 | ; PARAM("NAME")=NAME (last name minimal; recommend full name)
|
---|
18 | ; PARAM("GENDER")=SEX
|
---|
19 | ; PARAM("DOB")=DATE OF BIRTH
|
---|
20 | ; PARAM("MRN")=MEDICAL RECORD NUMBER
|
---|
21 | ;
|
---|
22 | NEW PARAM
|
---|
23 | SET PARAM("NAME")=$$NAME(DEM)
|
---|
24 | SET PARAM("GENDER")=$$SEX(DEM)
|
---|
25 | SET PARAM("DOB")=$$DOB(DEM)
|
---|
26 | SET PARAM("MRN")=$$MRN(DEM)
|
---|
27 | NEW RETURN
|
---|
28 | D ADDPT(.RETURN,.PARAM)
|
---|
29 | N DFN S DFN=$P(RETURN(1),U,2)
|
---|
30 | I DFN<1 S $EC=",U1," ; Debug.Assert that patient is added.
|
---|
31 | ; D VITALS(G,DFN)
|
---|
32 | D PROBLEMS^C0XPT1(G,DFN) ; Extract Problems and File
|
---|
33 | D ADR^C0XPT2(G,DFN) ; Extract Allergies and File
|
---|
34 | ;
|
---|
35 | QUIT
|
---|
36 | ;
|
---|
37 | NAME(DEMID) ; Public $$; Return VISTA name given the Demographics node ID.
|
---|
38 | ;
|
---|
39 | IF '$DATA(DEMID) SET $EC=",U1," ; Must pass this in.
|
---|
40 | ;
|
---|
41 | ; Get name node
|
---|
42 | NEW NAMENODE SET NAMENODE=$$object^C0XGET1(DEMID,"v:n")
|
---|
43 | IF '$L(NAMENODE) SET $EC=",U1," ; Not supposed to happen.
|
---|
44 | ;
|
---|
45 | ; Get Last name
|
---|
46 | NEW FAMILY SET FAMILY=$$object^C0XGET1(NAMENODE,"v:family-name")
|
---|
47 | IF '$L(FAMILY) SET $EC=",U1," ; Not supposed to happen
|
---|
48 | ;
|
---|
49 | ; Get First name
|
---|
50 | NEW GIVEN SET GIVEN=$$object^C0XGET1(NAMENODE,"v:given-name")
|
---|
51 | IF '$L(GIVEN) SET $EC=",U1," ; ditto
|
---|
52 | ;
|
---|
53 | ; Get Additional name (?Middle?)
|
---|
54 | NEW MIDDLE SET MIDDLE=$$object^C0XGET1(NAMENODE,"v:additional-name")
|
---|
55 | ; This is optional of course
|
---|
56 | ;
|
---|
57 | QUIT $$UP^XLFSTR(FAMILY_","_GIVEN_" "_MIDDLE)
|
---|
58 | ;
|
---|
59 | ;
|
---|
60 | DOB(DEMID) ; Public $$; Return Timson Date for DOB given the Dem node ID.
|
---|
61 | ;
|
---|
62 | IF '$DATA(DEMID) SET $EC=",U1," ; Must pass this in.
|
---|
63 | ;
|
---|
64 | ; Get DOB.
|
---|
65 | NEW DOB S DOB=$$object^C0XGET1(DEMID,"v:bday")
|
---|
66 | IF '$L(DOB) SET $EC=",U1," ; ditto
|
---|
67 | ;
|
---|
68 | ; Convert to Timson Date using %DT
|
---|
69 | N X,Y,%DT
|
---|
70 | S X=DOB
|
---|
71 | D ^%DT
|
---|
72 | QUIT Y
|
---|
73 | ;
|
---|
74 | ;
|
---|
75 | SEX(DEMID) ; Public $$; Return Sex M or F given the demographics node ID.
|
---|
76 | ;
|
---|
77 | IF '$DATA(DEMID) SET $EC=",U1," ; Must pass this in.
|
---|
78 | ;
|
---|
79 | ; Get "gender"
|
---|
80 | NEW SEX S SEX=$$object^C0XGET1(DEMID,"foaf:gender")
|
---|
81 | IF '$L(SEX) SET $EC=",U1," ; ditto
|
---|
82 | ;
|
---|
83 | ; Convert to internal value
|
---|
84 | N SEXABBR ; Sex Abbreviation
|
---|
85 | D CHK^DIE(2,.02,,SEX,.SEXABBR) ; Check value and convert to internal
|
---|
86 | ;
|
---|
87 | IF SEXABBR="^" QUIT "F" ; Unknown sexes will be female (Sam sez so)
|
---|
88 | ELSE QUIT SEXABBR
|
---|
89 | ;
|
---|
90 | ;
|
---|
91 | MRN(DEMID) ; Public $$; Return the Medical Record Number given node ID.
|
---|
92 | ;
|
---|
93 | IF '$DATA(DEMID) SET $EC=",U1," ; Must pass this in.
|
---|
94 | ;
|
---|
95 | ; Get subject node, then the identifer under it.
|
---|
96 | NEW MRNNODE S MRNNODE=$$object^C0XGET1(DEMID,"sp:medicalRecordNumber")
|
---|
97 | NEW MRN S MRN=$$object^C0XGET1(MRNNODE,"dcterms:identifier")
|
---|
98 | ;
|
---|
99 | ; If it doesn't exist, invent one
|
---|
100 | I '$L(MRN) S MRN=$R(928749018234)
|
---|
101 | QUIT MRN
|
---|
102 | ;
|
---|
103 | ADDPT(RETURN,PARAM) ; Private Proc; Add Patient to VISTA.
|
---|
104 | ; Return RPC style return pass by reference. Pass empty.
|
---|
105 | ; PARAM passed by reference.
|
---|
106 | ; Required elements include:
|
---|
107 | ; PARAM("NAME")=NAME (last name minimal; recommend full name)
|
---|
108 | ; PARAM("GENDER")=SEX
|
---|
109 | ; PARAM("DOB")=DATE OF BIRTH
|
---|
110 | ; PARAM("MRN")=MEDICAL RECORD NUMBER
|
---|
111 | ;
|
---|
112 | ; Optional elements include:
|
---|
113 | ; PARAM("POBCTY")=PLACE OF BIRTH [CITY]
|
---|
114 | ; PARAM("POBST")=PLACE OF BIRTH [STATE]
|
---|
115 | ; PARAM("MMN")=MOTHER'S MAIDEN NAME
|
---|
116 | ; PARAM("ALIAS",#)=ALIAS NAME(last^first^middle^suffix)^ALIAS SSN
|
---|
117 | ;
|
---|
118 | ; These elements are calculated:
|
---|
119 | ; PARAM("PRFCLTY")=PREFERRED FACILITY
|
---|
120 | ; PARAM("SSN")=SOCIAL SECURITY NUMBER OR NULL IF NONE
|
---|
121 | ; PARAM("SRVCNCTD")=SERVICE CONNECTED?
|
---|
122 | ; PARAM("TYPE")=TYPE
|
---|
123 | ; PARAM("VET")=VETERAN (Y/N)?
|
---|
124 | ; PARAM("FULLICN")=INTEGRATION CONTROL NUMBER AND CHECKSUM
|
---|
125 | ;
|
---|
126 | ;CHECK THAT PATCH DG*5.3*800 is installed for routine VAFCPTAD to add pt.
|
---|
127 | I '$$PATCH^XPDUTL("DG*5.3*800") D EN^DDIOL("You need to have patch DG*5.3*800 to add patients") S $EC=",U1,"
|
---|
128 | ;
|
---|
129 | ; Crash if required params aren't present
|
---|
130 | N X F X="NAME","GENDER","DOB","MRN" S:'$D(PARAM(X)) $EC=",U1,"
|
---|
131 | ;
|
---|
132 | ; Calculate ICN and its checksum using MRN; then remove MRN.
|
---|
133 | S PARAM("FULLICN")=PARAM("MRN")_"V"_$$CHECKDG^MPIFSPC(PARAM("MRN"))
|
---|
134 | ;
|
---|
135 | ; Get Preferred Facility from this Facility's number.
|
---|
136 | S PARAM("PRFCLTY")=$P($$SITE^VASITE(),U,3) ; Must use Station number here for API.
|
---|
137 | I 'PARAM("PRFCLTY") S $EC=",U1," ; crash if Facility is not set-up properly.
|
---|
138 | ;
|
---|
139 | ; No SSN (for now)
|
---|
140 | S PARAM("SSN")=""
|
---|
141 | ;
|
---|
142 | ; Boiler plate stuff below:
|
---|
143 | ; TODO: This could be configurable in a File. WV uses "VISTA OFFICE EHR"
|
---|
144 | S PARAM("SRVCNCTD")="N"
|
---|
145 | S PARAM("TYPE")="NON-VETERAN (OTHER)"
|
---|
146 | S PARAM("VET")="N"
|
---|
147 | ;
|
---|
148 | ; Now for the finish. Add the patient to VISTA (but only adds it to 2 :-()
|
---|
149 | D ADD^VAFCPTAD(.RETURN,.PARAM)
|
---|
150 | ;
|
---|
151 | I +RETURN(1)=-1 S $EC=",U1," ; It failed.
|
---|
152 | E N PIEN S PIEN=$P(RETURN(1),U,2)
|
---|
153 | ;
|
---|
154 | ; Add to IHS Patient file using Laygo in case it's already there.
|
---|
155 | NEW C0XFDA
|
---|
156 | SET C0XFDA(9000001,"?+"_PIEN_",",.01)=PIEN
|
---|
157 | SET C0XFDA(9000001,"?+"_PIEN_",",.02)=DT
|
---|
158 | SET C0XFDA(9000001,"?+"_PIEN_",",.12)=DUZ ;logged in user IEN (e.g. "13")
|
---|
159 | SET C0XFDA(9000001,"?+"_PIEN_",",.16)=DT
|
---|
160 | DO UPDATE^DIE("",$NAME(C0XFDA))
|
---|
161 | I $D(^TMP("DIERR",$J)) S $EC=",U1,"
|
---|
162 | ;
|
---|
163 | ; Add medical record number.
|
---|
164 | NEW IENS S IENS="?+1,"_PIEN_","
|
---|
165 | NEW C0XFDA
|
---|
166 | SET C0XFDA(9000001.41,IENS,.01)=+$$SITE^VASITE() ; This time, the IEN of the primary site
|
---|
167 | SET C0XFDA(9000001.41,IENS,.02)=PARAM("MRN") ; Put Medical Record Number on Station Number
|
---|
168 | DO UPDATE^DIE("",$NAME(C0XFDA))
|
---|
169 | I $D(^TMP("DIERR",$J)) S $EC=",U1,"
|
---|
170 | QUIT
|
---|
171 | ;
|
---|
172 | VITALS(G,DFN) ; Private EP; Process Vitals for a patient graph.
|
---|
173 | ; Vital Sign Sets
|
---|
174 | K ^TMP($J) ; Global variable. A patient can have 1000 vital sets.
|
---|
175 | D GOPS^C0XGET3($NA(^TMP($J,"VS")),G,"sp:VitalSignSet","rdf:type")
|
---|
176 | ;
|
---|
177 | ; For each Vital Sign Set, grab encounter
|
---|
178 | N S F S=0:0 S S=$O(^TMP($J,"VS",S)) Q:S="" D
|
---|
179 | . N ENC S ENC=$$GSPO1^C0XGET3(G,^TMP($J,"VS",S),"sp:encounter")
|
---|
180 | ;
|
---|
181 | ; D EN1^GMVDCSAV(.RESULT,DATA)
|
---|
182 | QUIT
|
---|
183 | ;
|
---|
184 | NP() ; New Person Entry
|
---|
185 | N C0XFDA,C0XIEN,C0XERR
|
---|
186 | S C0XFDA(200,"?+1,",.01)="PROVIDER,UNKNOWN SMART" ; Name
|
---|
187 | S C0XFDA(200,"?+1,",1)="USP" ; Initials
|
---|
188 | S C0XFDA(200,"?+1,",28)="SMART" ; Mail Code
|
---|
189 | ;
|
---|
190 | N DIC S DIC(0)="" ; An XREF in File 200 requires this.
|
---|
191 | D UPDATE^DIE("E",$NA(C0XFDA),$NA(C0XIEN),$NA(C0XERR)) ; Typical UPDATE
|
---|
192 | Q C0XIEN(1) ;Provider IEN
|
---|
193 | ;
|
---|