source: cprs/branches/foia-cprs/CPRS-Chart/Orders/rODAllergy.pas@ 459

Last change on this file since 459 was 459, checked in by Kevin Toppenberg, 16 years ago

Adding foia-cprs branch

File size: 10.9 KB
Line 
1unit rODAllergy;
2
3{$O-}
4
5interface
6
7uses SysUtils, Classes, ORNet, ORFn, rCore, uCore, TRPCB, dialogs, rMisc ;
8
9type
10 TAllergyRec = record
11 Changed: boolean;
12 IEN: Integer;
13 CausativeAgent: string;
14 AllergyType: string;
15 NatureOfReaction: string;
16 SignsSymptoms: TStringList;
17 Originator: int64;
18 OriginatorName: string;
19 Originated: TFMDateTime;
20 Comments: TStringList;
21 IDBandMarked: TStringList;
22 ChartMarked: TStringList;
23 Verifier: int64;
24 VerifierName: string;
25 Verified: boolean;
26 VerifiedDateTime: TFMDateTime;
27 EnteredInError: boolean;
28 DateEnteredInError: TFMDateTime;
29 UserEnteringInError: int64;
30 ErrorComments: TStringList;
31 Observed_Historical: string;
32 Observations: TStringList;
33 ReactionDate: TFMDateTime;
34 Severity: string;
35 NoKnownAllergies: Boolean;
36 NewComments: TStringList;
37 end;
38
39 TARTPatchInstalled = record
40 PatchInstalled: boolean;
41 PatchChecked: boolean;
42 end;
43
44 TGMRASiteParams = record
45 MarkIDBandFlag: Boolean;
46 OriginatorCommentsRequired: Boolean;
47 ErrorCommentsEnabled: Boolean;
48 ParamsSet: Boolean;
49 end;
50
51function SearchForAllergies(StringToMatch: string): TStrings;
52function SubsetofSymptoms(const StartFrom: string; Direction: Integer): TStrings;
53function ODForAllergies: TStrings;
54function GetCWADInfo(const DFN: string): string;
55function SaveAllergy(EditRec: TAllergyRec): string;
56function LoadAllergyForEdit(AllergyIEN: integer): TAllergyRec;
57function SendARTBulletin(AFreeTextEntry: string; AComment: TStringList): string;
58function RPCEnterNKAForPatient: string;
59
60// site parameter functions
61function ARTPatchInstalled: boolean;
62function GetSiteParams: TGMRASiteParams;
63function MarkIDBand: boolean;
64function RequireOriginatorComments: boolean;
65function EnableErrorComments: boolean;
66
67implementation
68
69const
70 NO_YES: array[Boolean] of string = ('NO', 'YES');
71
72var
73 uARTPatchInstalled: TARTPatchInstalled;
74 uGMRASiteParams: TGMRASiteParams;
75
76function ODForAllergies: TStrings;
77begin
78 CallV('ORWDAL32 DEF',[nil]);
79 Result := RPCBrokerV.Results;
80end;
81
82function SearchForAllergies(StringToMatch: string): TStrings;
83begin
84 CallV('ORWDAL32 ALLERGY MATCH',[StringToMatch]);
85 Result := RPCBrokerV.Results;
86end;
87
88function SubsetofSymptoms(const StartFrom: string; Direction: Integer): TStrings;
89begin
90 Callv('ORWDAL32 SYMPTOMS',[StartFrom, Direction]);
91 Result := RPCBrokerV.Results;
92end;
93
94function GetCWADInfo(const DFN: string): string;
95begin
96 Result := sCallV('ORWPT CWAD',[DFN]);
97end;
98
99function LoadAllergyForEdit(AllergyIEN: integer): TAllergyRec;
100var
101 Dest: TStringList;
102 EditRec: TAllergyRec;
103 x: string;
104begin
105 Dest := TStringList.Create;
106 try
107 tCallV(Dest, 'ORWDAL32 LOAD FOR EDIT', [AllergyIEN]) ;
108 if Piece(RPCBrokerV.Results[0], U, 1) <> '-1' then
109 begin
110 with EditRec do
111 begin
112 Changed := False;
113 IEN := AllergyIEN;
114 CausativeAgent := ExtractDefault(Dest, 'CAUSATIVE AGENT');
115 AllergyType := ExtractDefault(Dest, 'ALLERGY TYPE');
116 NatureOfReaction := ExtractDefault(Dest, 'NATURE OF REACTION');
117 SignsSymptoms := TStringList.Create;
118 ExtractItems(SignsSymptoms, Dest, 'SIGN/SYMPTOMS');
119 MixedCaseByPiece(SignsSymptoms, U, 4);
120 x := ExtractDefault(Dest, 'ORIGINATOR');
121 Originator := StrToInt64Def(Piece(x, U, 1), 0);
122 OriginatorName := Piece(x, U, 2);
123 Originated := StrToFMDateTime(ExtractDefault(Dest, 'ORIGINATED'));
124 Comments := TStringList.Create;
125 ExtractText(Comments, Dest, 'COMMENTS');
126 IDBandMarked := TStringList.Create;
127 ExtractItems(IDBandMarked, Dest, 'ID BAND MARKED');
128 ChartMarked := TStringList.Create;
129 ExtractItems(ChartMarked, Dest, 'CHART MARKED');
130 //x := ExtractDefault(Dest, 'VERIFIER');
131 //Verifier := StrToInt64Def(Piece(x, U, 1), 0);
132 //VerifierName := Piece(x, U, 2);
133 //x := ExtractDefault(Dest, 'VERIFIED');
134 //Verified := Piece(x, U, 1) = 'YES';
135 //if Verified then
136 // VerifiedDateTime := StrToFMDateTime(Piece(x, U, 2));
137 x := ExtractDefault(Dest, 'ENTERED IN ERROR');
138 EnteredInError := Piece(x, U, 1) = 'YES';
139 DateEnteredInError := StrToFloatDef(Piece(x, U, 2), 0);
140 UserEnteringInError := StrToInt64Def(Piece(x, U, 3), 0);
141 ErrorComments := TStringList.Create;
142 Observed_Historical := ExtractDefault(Dest, 'OBS/HIST');
143 Observations := TStringList.Create;
144 ExtractText(Observations, Dest, 'OBSERVATIONS');
145 //ReactionDate := StrToFMDateTime(Piece(ExtractDefault(Dest, 'REACTDT'), U, 3));
146 //Severity := Piece(ExtractDefault(Dest, 'SEVERITY'), U, 3);
147 NoKnownAllergies := (StrToIntDef(Piece(ExtractDefault(Dest, 'NKA'), U, 3), 0) > 0);
148 NewComments := TStringList.Create;
149 end;
150 end
151 else
152 EditRec.IEN := -1;
153 Result := EditRec;
154 finally
155 Dest.Free;
156 end;
157end;
158
159function SaveAllergy(EditRec: TAllergyRec): string;
160var
161 i: integer;
162begin
163 with RPCBrokerV, EditRec do
164 begin
165 ClearParameters := True;
166 RemoteProcedure := 'ORWDAL32 SAVE ALLERGY';
167 Param[0].PType := literal;
168 Param[0].Value := IntToStr(IEN);
169 Param[1].PType := literal;
170 Param[1].Value := Patient.DFN;
171 Param[2].PType := list;
172 with Param[2] do
173 begin
174 if NoKnownAllergies then
175 Mult['"GMRANKA"'] := NO_YES[NoKnownAllergies];
176 if CausativeAgent <> '' then
177 Mult['"GMRAGNT"'] := CausativeAgent;
178 if AllergyType <> '' then
179 Mult['"GMRATYPE"'] := AllergyType ;
180 if NatureOfReaction <> '' then
181 Mult['"GMRANATR"'] := NatureOfReaction ;
182 if Originator > 0 then
183 Mult['"GMRAORIG"'] := IntToStr(Originator);
184 if Originated > 0 then
185 Mult['"GMRAORDT"'] := FloatToStr(Originated);
186 with SignsSymptoms do if Count > 0 then
187 begin
188 Mult['"GMRASYMP",0'] := IntToStr(Count);
189 for i := 0 to Count - 1 do
190 Mult['"GMRASYMP",' + IntToStr(i+1)] := Pieces(Strings[i], U, 1, 5);
191 end;
192 //if Verified then
193 // Mult['"GMRAVER"'] := NO_YES[Verified];
194 //if Verifier > 0 then
195 // Mult['"GMRAVERF"'] := IntToStr(Verifier);
196 //if VerifiedDateTime > 0 then
197 // Mult['"GMRAVERD"'] := FloatToStr(VerifiedDateTime);
198 if EnteredInError then
199 begin
200 Mult['"GMRAERR"'] := NO_YES[EnteredInError];
201 Mult['"GMRAERRBY"'] := IntToStr(UserEnteringInError);
202 Mult['"GMRAERRDT"'] := FloatToStr(DateEnteredInError);
203 with ErrorComments do if Count > 0 then
204 begin
205 Mult['"GMRAERRCMTS",0'] := IntToStr(Count);
206 for i := 0 to Count - 1 do
207 Mult['"GMRAERRCMTS",' + IntToStr(i+1)] := Strings[i];
208 end;
209 end ;
210 with ChartMarked do if Count > 0 then
211 begin
212 Mult['"GMRACHT",0'] := IntToStr(Count);
213 for i := 0 to Count - 1 do
214 Mult['"GMRACHT",' + IntToStr(i+1)] := Strings[i];
215 end;
216 with IDBandMarked do if Count > 0 then
217 begin
218 Mult['"GMRAIDBN",0'] := IntToStr(Count);
219 for i := 0 to Count - 1 do
220 Mult['"GMRAIDBN",' + IntToStr(i+1)] := Strings[i];
221 end;
222 if Length(Observed_Historical) > 0 then
223 Mult['"GMRAOBHX"'] := Observed_Historical;
224 if ReactionDate > 0 then
225 Mult['"GMRARDT"'] := FloatToStr(ReactionDate);
226 if Length(Severity) > 0 then
227 Mult['"GMRASEVR"'] := Severity;
228 with NewComments do if Count > 0 then
229 begin
230 Mult['"GMRACMTS",0'] := IntToStr(Count);
231 for i := 0 to Count - 1 do
232 Mult['"GMRACMTS",' + IntToStr(i+1)] := Strings[i];
233 end;
234 end;
235 CallBroker;
236 Result := Results[0];
237 end;
238end;
239
240function RPCEnterNKAForPatient: string;
241begin
242 with RPCBrokerV do
243 begin
244 ClearParameters := True;
245 RemoteProcedure := 'ORWDAL32 SAVE ALLERGY';
246 Param[0].PType := literal;
247 Param[0].Value := '0';
248 Param[1].PType := literal;
249 Param[1].Value := Patient.DFN;
250 Param[2].PType := list;
251 with Param[2] do
252 Mult['"GMRANKA"'] := 'YES';
253 CallBroker;
254 Result := Results[0];
255 end;
256end;
257
258function SendARTBulletin(AFreeTextEntry: string; AComment: TStringList): string;
259var
260 i: integer;
261begin
262 with RPCBrokerV do
263 begin
264 ClearParameters := True;
265 RemoteProcedure := 'ORWDAL32 SEND BULLETIN';
266 Param[0].PType := literal;
267 Param[0].Value := User.DUZ;
268 Param[1].PType := literal;
269 Param[1].Value := Patient.DFN;
270 Param[2].PType := literal;
271 Param[2].Value := AFreeTextEntry;
272 if AComment.Count > 0 then with Param[3] do
273 begin
274 PType := list;
275 for i := 0 to AComment.Count - 1 do
276 Mult[IntToStr(Succ(i)) + ',0'] := AComment[i];
277 Mult['0'] := '^^' + IntToStr(AComment.Count);
278 end;
279 CallBroker;
280 Result := Results[0];
281 end;
282end;
283
284// Site parameter functions
285
286function ARTPatchInstalled: boolean;
287begin
288 with uARTPatchInstalled do
289 if not PatchChecked then
290 begin
291 PatchInstalled := ServerHasPatch('GMRA*4.0*21');
292 PatchChecked := True;
293 end;
294 Result := uARTPatchInstalled.PatchInstalled;
295end;
296
297function GetSiteParams: TGMRASiteParams;
298var
299 x: string;
300begin
301 with uGMRASiteParams do
302 if not ParamsSet then
303 begin
304 x := sCallV('ORWDAL32 SITE PARAMS', [nil]);
305 MarkIDBandFlag := (Piece(x, U, 5) <> '0');
306 OriginatorCommentsRequired := (Piece(x, U, 4) = '1');
307 ErrorCommentsEnabled := (Piece(x, U, 11) = '1');
308 ParamsSet := True;
309 end;
310 Result := uGMRASiteParams;
311end;
312
313function MarkIDBand: boolean;
314begin
315 Result := GetSiteParams.MarkIDBandFlag;
316end;
317
318function RequireOriginatorComments: boolean;
319begin
320 Result := GetSiteParams.OriginatorCommentsRequired;
321end;
322
323function EnableErrorComments: boolean;
324begin
325 Result := GetSiteParams.ErrorCommentsEnabled;
326end;
327
328end.
Note: See TracBrowser for help on using the repository browser.