source: fmts/trunk/p/C0XPT0.m@ 1616

Last change on this file since 1616 was 1616, checked in by Sam Habiel, 11 years ago

Now code add drugs to drug file. Still needs lot more work.

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