source: cprs/branches/tmg-cprs/CPRS-Chart/TMG_Extra/fPtDemoEdit.pas@ 1699

Last change on this file since 1699 was 819, checked in by Kevin Toppenberg, 14 years ago

Fixed crash on non-login

File size: 67.0 KB
Line 
1unit fPtDemoEdit;
2//kt Added this entire unit for demographics editing at runtime.
3
4interface
5
6uses
7 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
8 Dialogs, ComCtrls, StdCtrls, ExtCtrls, DKLang, Grids, SortStringGrid;
9
10type
11 BoolUC = (bucFalse, bucTrue, bucUnchanged);
12
13 tFileEntry = record
14 Field : string;
15 FileNum : string;
16 FieldName : String;
17 IENS : string;
18 oldValue,newValue : string;
19 end;
20
21 TGridInfo = class; //forward declaration
22 TGridDataLoader = procedure (GridInfo: TGridInfo) of object;
23 TGridInfo = class (TObject)
24 public
25 Grid : TSortStringGrid; //doesn't own object
26 FileNum : string;
27 IENS : string;
28 BasicMode : Boolean;
29 Data : TStringList; //doesn't own object
30 Message : string; //optional text.
31 DataLoadProc : TGridDataLoader;
32 ApplyBtn : TButton;
33 RevertBtn : TButton;
34 end;
35
36 TPatientInfo = class(TObject)
37 public
38 LName: String;
39 FName: String;
40 MName: String;
41 CombinedName: String;
42 Prefix: String;
43 Suffix: String;
44 Degree: String;
45 DOB: String;
46 Sex: String;
47 SSNum: String;
48 EMail: String;
49 AliasInfo : TStringList; //format: s=IEN#, Object is ^tAlias
50 AddressLine1: String;
51 AddressLine2: String;
52 AddressLine3: String;
53 City: String;
54 State: String;
55 Zip4: String;
56 BadAddress: BoolUC;
57 PhoneNumResidence: String;
58 PhoneNumWork: String;
59 PhoneNumCell: String;
60 PhoneNumTemp: String;
61
62 TempAddressLine1: String;
63 TempAddressLine2: String;
64 TempAddressLine3: String;
65 TempCity: String;
66 TempState: String;
67 TempZip4: String;
68 TempStartingDate : String;
69 TempEndingDate : String;
70 TempAddressActive: BoolUC;
71
72 ConfidentalAddressLine1: String;
73 ConfidentalAddressLine2: String;
74 ConfidentalAddressLine3: String;
75 ConfidentalCity: String;
76 ConfidentalState: String;
77 ConfidentalZip: String;
78 ConfidentalStartingDate : String;
79 ConfidentalEndingDate : String;
80 ConfAddressActive : BoolUC;
81
82 Modified : boolean;
83
84 constructor Create;
85 destructor Destroy; override;
86 procedure ClearAliasInfo;
87 procedure Clear;
88 procedure Assign(Source : TPatientInfo);
89 procedure RemoveUnchanged(OldInfo : TPatientInfo);
90 end;
91
92 TfrmPtDemoEdit = class(TForm)
93 OKBtn: TButton;
94 CancelBtn: TButton;
95 ApplyBtn: TButton;
96 PageControl: TPageControl;
97 DemoTabSheet: TTabSheet;
98 LNameLabel: TLabel;
99 FNameLabel: TLabel;
100 MNameLabel: TLabel;
101 CombinedNameLabel: TLabel;
102 PrefixLabel: TLabel;
103 SuffixLabel: TLabel;
104 DOBLabel: TLabel;
105 SSNumLabel: TLabel;
106 CombinedNameEdit: TEdit;
107 LNameEdit: TEdit;
108 FNameEdit: TEdit;
109 MNameEdit: TEdit;
110 PrefixEdit: TEdit;
111 SuffixEdit: TEdit;
112 DOBEdit: TEdit;
113 SSNumEdit: TEdit;
114 AliasGroupBox: TGroupBox;
115 AliasComboBox: TComboBox;
116 AliasNameLabel: TLabel;
117 AliasSSNumLabel: TLabel;
118 AliasNameEdit: TEdit;
119 AliasSSNEdit: TEdit;
120 AddressGroupBox: TGroupBox;
121 AddressRGrp: TRadioGroup;
122 AddressLine1Edit: TEdit;
123 AddressLine2Edit: TEdit;
124 AddressLine3Edit: TEdit;
125 CityLabel: TLabel;
126 CityEdit: TEdit;
127 StateComboBox: TComboBox;
128 Zip4Edit: TEdit;
129 Zip4Label: TLabel;
130 BadAddressCB: TCheckBox;
131 TempActiveCB: TCheckBox;
132 SexLabel: TLabel;
133 SexComboBox: TComboBox;
134 DelAliasBtn: TButton;
135 StartingDateEdit: TEdit;
136 StartingDateLabel: TLabel;
137 EndingDateLabel: TLabel;
138 EndingDateEdit: TEdit;
139 ConfActiveCB: TCheckBox;
140 DegreeEdit: TEdit;
141 DegreeLabel: TLabel;
142 AddAliasBtn: TButton;
143 GroupBox1: TGroupBox;
144 PhoneNumGrp: TRadioGroup;
145 PhoneNumEdit: TEdit;
146 Label1: TLabel;
147 Label2: TLabel;
148 Label3: TLabel;
149 DKLanguageController1: TDKLanguageController;
150 EMailEdit: TEdit;
151 Advanced: TTabSheet;
152 gridPatientDemo: TSortStringGrid;
153 procedure AliasComboBoxChange(Sender: TObject);
154 procedure FormCreate(Sender: TObject);
155 procedure AddressRGrpClick(Sender: TObject);
156 procedure PhoneNumGrpClick(Sender: TObject);
157 procedure DelAliasBtnClick(Sender: TObject);
158 procedure FormDestroy(Sender: TObject);
159 procedure FormShow(Sender: TObject);
160 procedure CombinedNameEditChange(Sender: TObject);
161 procedure LNameEditChange(Sender: TObject);
162 procedure FNameEditChange(Sender: TObject);
163 procedure MNameEditChange(Sender: TObject);
164 procedure PrefixEditChange(Sender: TObject);
165 procedure SuffixEditChange(Sender: TObject);
166 procedure SexComboBoxChange(Sender: TObject);
167 procedure EMailEditChange(Sender: TObject);
168 procedure AddressLine1EditChange(Sender: TObject);
169 procedure AddressLine2EditChange(Sender: TObject);
170 procedure AddressLine3EditChange(Sender: TObject);
171 procedure CityEditChange(Sender: TObject);
172 procedure Zip4EditChange(Sender: TObject);
173 procedure StateComboBoxChange(Sender: TObject);
174 procedure TempActiveCBClick(Sender: TObject);
175 procedure ConfActiveCBClick(Sender: TObject);
176 procedure BadAddressCBClick(Sender: TObject);
177 procedure DegreeEditChange(Sender: TObject);
178 procedure PhoneNumEditChange(Sender: TObject);
179 procedure StartingDateEditChange(Sender: TObject);
180 procedure EndingDateEditChange(Sender: TObject);
181 procedure AliasNameEditChange(Sender: TObject);
182 procedure AliasSSNEditChange(Sender: TObject);
183 procedure ApplyBtnClick(Sender: TObject);
184 procedure AddAliasBtnClick(Sender: TObject);
185 procedure OKBtnClick(Sender: TObject);
186 procedure CancelBtnClick(Sender: TObject);
187 procedure DOBEditChange(Sender: TObject);
188 procedure SSNumEditChange(Sender: TObject);
189 procedure PageControlChange(Sender: TObject);
190 procedure gridPatientDemoSelectCell(Sender: TObject; ACol,
191 ARow: Integer; var CanSelect: Boolean);
192 procedure gridPatientDemoSetEditText(Sender: TObject; ACol,
193 ARow: Integer; const Value: String);
194 procedure PageControlChanging(Sender: TObject;
195 var AllowChange: Boolean);
196 private
197 { Private declarations }
198 FCurPatientInfo : TPatientInfo;
199 FServerPatientInfo : TPatientInfo;
200 FCurAliasEdit : integer;
201 CurrentAnyFileData : TStringList;
202 ProgAliasChangeOccuring : boolean;
203 CurrentPatientData : TStringList;
204 ProgNameChangeOccuring : boolean;
205 ProgPhoneChangeOccuring : boolean;
206 FLastSelectedRow,FLastSelectedCol : integer;
207 ProgAddressChangeOccuring : boolean;
208 DataForGrid : TStringList;
209 MaxAliasIEN : integer;
210 Data : TStringList;
211 ChangesMade : boolean;
212 BasicTemplate : TStringList;
213 FLoadingGrid: boolean;
214 CachedWPField : TStringList;
215 procedure GetPtInfo(PatientInfo : TPatientInfo);
216 procedure PostChangedInfo(PatientInfo : TPatientInfo);
217 procedure ShowAliasInfo(Patient : TPatientInfo);
218 procedure GetPatientInfo(GridInfo: TGridInfo);
219 procedure ShowPtInfo(Patient : TPatientInfo);
220 function CombinedName : string;
221 procedure AddGridInfo(Grid: TSortStringGrid;
222 Data : TStringList;
223 BasicMode : boolean;
224 DataLoader : TGridDataLoader;
225 FileNum : string);
226 procedure NameParts(CombinedName: string; var LName, FName, MName : string);
227 function ExtractNum (S : String; StartPos : integer) : string;
228 procedure SetModified(value : boolean);
229 procedure SetAliasEnabled(value : boolean);
230 function PostChanges(Grid : TSortStringGrid) : TModalResult;
231 procedure CompileChanges(Grid : TSortStringGrid; CurrentUserData,Changes : TStringList);
232 procedure RegisterGridInfo(GridInfo : TGridInfo);
233 public
234 { Public declarations }
235 function GetInfoForGrid(Grid : TSortStringGrid) : TGridInfo;
236 procedure LoadAnyGrid(Grid : TSortStringGrid; BasicMode: boolean; FileNum : string;
237 IENS : string;
238 CurrentData : TStringList);
239 procedure LoadAnyGridFromInfo(GridInfo : TGridInfo);
240 function IsWPField(FileNum,FieldNum : string) : boolean;
241 function IsSubFile(FieldDef: string ; var SubFileNum : string) : boolean;
242 function GetInfoIndexForGrid(Grid : TSortStringGrid) : integer;
243 function PostVisibleGrid: TModalResult;
244 function GetLineInfo(Grid : TSortStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
245 procedure GetOneRecord(FileNum, IENS : string; Data, BlankFileInfo: TStringList);
246 //procedure GridSelectCell(Sender: TObject; ACol, ARow: Integer; var CanSelect: Boolean);
247 function GetUserLine(CurrentUserData : TStringList; Grid : TSortStringGrid; ARow: integer) : integer;
248 function FindInStrings(fieldNum : string; Strings : TStringList; var fileNum : string) : integer;
249 end;
250
251var
252 frmPtDemoEdit: TfrmPtDemoEdit;
253
254Const
255 DEF_GRID_ROW_HEIGHT = 17;
256 CLICK_FOR_SUBS = '<CLICK for Sub-Entries>';
257 COMPUTED_FIELD = '<Computed Field --> CAN''T EDIT>';
258 CLICK_TO_EDIT = '<CLICK to Edit Text>';
259 HIDDEN_FIELD = '<Hidden>';
260
261implementation
262
263{$R *.dfm}
264
265uses
266 IniFiles,Trpcb,ORNet,uCore, mfunstr, subfilesU, strutils, LookupU, SetSelU,
267 SelDateTimeU, PostU, EditTextU, FMErrorU;
268
269const
270 ADD_NEW_ALIAS = '<Add New Alias>';
271
272type
273 tAlias= class
274 Name : string;
275 SSN : string;
276 procedure Assign(Source: tAlias);
277 end;
278
279procedure tAlias.Assign(Source : tAlias);
280begin
281 Name := Source.Name;
282 SSN := Source.SSN;
283end;
284
285//=========================================================
286//=========================================================
287//=========================================================
288
289constructor TPatientInfo.Create;
290begin
291 AliasInfo := TStringList.Create;
292
293 Clear;
294end;
295
296destructor TPatientInfo.Destroy;
297begin
298 ClearAliasInfo;
299 AliasInfo.Free;
300 inherited Destroy;
301End;
302
303procedure TPatientInfo.ClearAliasInfo;
304var i : integer;
305 pAlias : tAlias;
306begin
307 for i := 0 to AliasInfo.Count-1 do begin
308 pAlias := tAlias(AliasInfo.Objects[i]);
309 pAlias.Free;
310 end;
311 AliasInfo.Clear
312End;
313
314procedure TPatientInfo.Clear;
315begin
316 LName:= '';
317 FName:= '';
318 MName:= '';
319 CombinedName:= '';
320 Prefix:= '';
321 Suffix:= '';
322 Degree:= '';
323 DOB:= '';
324 SSNum:= '';
325 EMail:= '';
326 ClearAliasInfo;
327 AddressLine1:= '';
328 AddressLine2:= '';
329 AddressLine3:= '';
330 City:= '';
331 State:= '';
332 Zip4:= '';
333 TempAddressLine1:= '';
334 TempAddressLine2:= '';
335 TempAddressLine3:= '';
336 TempCity:= '';
337 TempState:= '';
338 TempZip4:= '';
339 TempStartingDate := '';
340 TempEndingDate := '';
341 ConfidentalAddressLine1:= '';
342 ConfidentalAddressLine2:= '';
343 ConfidentalAddressLine3:= '';
344 ConfidentalCity:= '';
345 ConfidentalState:= '';
346 ConfidentalZip:= '';
347 ConfidentalStartingDate := '';
348 ConfidentalEndingDate := '';
349 BadAddress:= bucFalse;
350 TempAddressActive:= bucFalse;
351 ConfAddressActive := bucFalse;
352 Modified := false;
353
354 PhoneNumResidence:= '';
355 PhoneNumWork:= '';
356 PhoneNumCell:= '';
357 PhoneNumTemp:= '';
358 Sex:= '';
359end;
360
361
362procedure TPatientInfo.Assign(Source : TPatientInfo);
363var i : integer;
364 pAlias : tAlias;
365 OtherpAlias : tAlias;
366begin
367 LName:=Source.LName;
368 FName:=Source.FName;
369 MName:=Source.MName;
370 CombinedName:=Source.CombinedName;
371 Prefix:=Source.Prefix;
372 Suffix:=Source.Suffix;
373 Degree:=Source.Degree;
374 DOB:=Source.DOB;
375 SSNum:=Source.SSNum;
376 EMail:=Source.EMail;
377
378 ClearAliasInfo;
379 //Copy pointed to tAlias entries, don't simply copy references
380 for i := 0 to Source.AliasInfo.Count-1 do begin
381 AliasInfo.Add(Source.AliasInfo.Strings[i]);
382 OtherpAlias := tAlias(Source.AliasInfo.Objects[i]);
383 if OtherpAlias<>nil then begin
384 pAlias := tAlias.Create;
385 pAlias.Name := OtherpAlias.Name;
386 pAlias.SSN := OtherpAlias.SSN;
387 AliasInfo.Objects[i]:=pAlias;
388 end;
389 end;
390 AddressLine1:=Source.AddressLine1;
391 AddressLine2:=Source.AddressLine2;
392 AddressLine3:=Source.AddressLine3;
393 City:=Source.City;
394 State:=Source.State;
395 Zip4:=Source.Zip4;
396 TempAddressLine1:=Source.TempAddressLine1;
397 TempAddressLine2:=Source.TempAddressLine2;
398 TempAddressLine3:=Source.TempAddressLine3;
399 TempCity:=Source.TempCity;
400 TempState:=Source.TempState;
401 TempZip4:=Source.TempZip4;
402 TempStartingDate :=Source.TempStartingDate ;
403 TempEndingDate :=Source.TempEndingDate ;
404 ConfidentalAddressLine1:=Source.ConfidentalAddressLine1;
405 ConfidentalAddressLine2:=Source.ConfidentalAddressLine2;
406 ConfidentalAddressLine3:=Source.ConfidentalAddressLine3;
407 ConfidentalCity:=Source.ConfidentalCity;
408 ConfidentalState:=Source.ConfidentalState;
409 ConfidentalZip:=Source.ConfidentalZip;
410 ConfidentalStartingDate :=Source.ConfidentalStartingDate ;
411 ConfidentalEndingDate :=Source.ConfidentalEndingDate ;
412 BadAddress:= Source.BadAddress;
413 TempAddressActive:= Source.TempAddressActive;
414 ConfAddressActive := Source.ConfAddressActive;
415 PhoneNumResidence:=Source.PhoneNumResidence;
416 PhoneNumWork:=Source.PhoneNumWork;
417 PhoneNumCell:=Source.PhoneNumCell;
418 PhoneNumTemp:=Source.PhoneNumTemp;
419 Sex:=Source.Sex;
420 EMail := Source.EMail;
421end;
422
423
424procedure TPatientInfo.RemoveUnchanged(OldInfo : TPatientInfo);
425//Will remove entries that are unchanged from OldInfo
426//ALSO, will change AliasInfo entries:
427// Other code adds "IEN" numbers that don't have any corresponding
428// true IEN on the server. This will convert these to +1,+2 etc.
429// And, if there is an alias entry in the OldInfo that is not
430// in this info, then a matching @ entry for that IEN will be generated.
431
432 procedure CompStrs(var newS, oldS : string);
433 begin
434 if newS = oldS then begin
435 newS := ''; //no change,
436 end else begin
437 if (newS = '') and (oldS <> '') then newS := '@' //delete symbol
438 end;
439 end;
440
441 procedure CompBoolUC(var newBN, oldBN : BoolUC);
442 begin
443 if newBN=oldBN then begin
444 newBN := bucUnchanged; //Mark unchanged
445 end;
446 end;
447
448 const
449 BOOL_STR : array[false..true] of string =('TRUE','FALSE');
450 NO_CHANGE = 1;
451 NEW_RECORD = 2;
452 DELETED_RECORD = 3;
453 CHANGED_RECORD = 4;
454
455 function CompAliasRec(curAlias,oldAlias : tAlias) : integer;
456 //Returns: NO_CHANGE = 1; NEW_RECORD = 2; DELETED_RECORD = 3; CHANGED_RECORD = 4;
457 begin
458 Result := NO_CHANGE;
459 if (curAlias <> nil) and (oldAlias <> nil) then begin
460 if curAlias.Name = '' then begin
461 if oldAlias.Name <> '' then Result := DELETED_RECORD;
462 end else if curAlias.Name <> oldAlias.Name then begin
463 Result := CHANGED_RECORD;
464 end;
465 if Result = NO_CHANGE then begin
466 if curAlias.SSN <> oldAlias.SSN then Result := CHANGED_RECORD;
467 end;
468 end;
469 end;
470
471 function CompAlias(IEN : string; pAlias : tAlias; OldInfo : TPatientInfo) : integer;
472 //format: s=IEN#, Object is ^tAlias
473 //Returns: NO_CHANGE = 1; NEW_RECORD = 2; DELETED_RECORD = 3; CHANGED_RECORD = 4;
474 var i : integer;
475 oldPAlias : tAlias;
476 begin
477 Result := NEW_RECORD;
478 for i := 0 to OldInfo.AliasInfo.Count-1 do begin
479 if OldInfo.AliasInfo.Strings[i] = IEN then begin
480 oldPAlias := tAlias(OldInfo.AliasInfo.Objects[i]);
481 Result := CompAliasRec(pAlias,oldPAlias);
482 break;
483 end;
484 end;
485 end;
486
487 var i,j,AddCt : integer;
488 pAlias, tempPAlias : tAlias;
489
490begin
491 {if OldInfo = This Info, then remove entries}
492 CompStrs(LName, OldInfo.LName);
493 CompStrs(FName, OldInfo.FName);
494 CompStrs(MName, OldInfo.MName);
495 CompStrs(CombinedName, OldInfo.CombinedName);
496 CompStrs(Prefix, OldInfo.Prefix);
497 CompStrs(Suffix, OldInfo.Suffix);
498 CompStrs(Degree, OldInfo.Degree);
499 CompStrs(DOB, OldInfo.DOB);
500 CompStrs(SSNum, OldInfo.SSNum);
501 CompStrs(EMail, OldInfo.EMail);
502
503 CompStrs(AddressLine1, OldInfo.AddressLine1);
504 CompStrs(AddressLine2, OldInfo.AddressLine2);
505 CompStrs(AddressLine3, OldInfo.AddressLine3);
506 CompStrs(City, OldInfo.City);
507 CompStrs(State, OldInfo.State);
508 CompStrs(Zip4, OldInfo.Zip4);
509 CompStrs(TempAddressLine1, OldInfo.TempAddressLine1);
510 CompStrs(TempAddressLine2, OldInfo.TempAddressLine2);
511 CompStrs(TempAddressLine3, OldInfo.TempAddressLine3);
512 CompStrs(TempCity, OldInfo.TempCity);
513 CompStrs(TempState, OldInfo.TempState);
514 CompStrs(TempZip4, OldInfo.TempZip4);
515 CompStrs(TempStartingDate , OldInfo.TempStartingDate );
516 CompStrs(TempEndingDate , OldInfo.TempEndingDate );
517 CompStrs(ConfidentalAddressLine1, OldInfo.ConfidentalAddressLine1);
518 CompStrs(ConfidentalAddressLine2, OldInfo.ConfidentalAddressLine2);
519 CompStrs(ConfidentalAddressLine3, OldInfo.ConfidentalAddressLine3);
520 CompStrs(ConfidentalCity, OldInfo.ConfidentalCity);
521 CompStrs(ConfidentalState, OldInfo.ConfidentalState);
522 CompStrs(ConfidentalZip, OldInfo.ConfidentalZip);
523 CompStrs(ConfidentalStartingDate , OldInfo.ConfidentalStartingDate );
524 CompStrs(ConfidentalEndingDate , OldInfo.ConfidentalEndingDate );
525
526 CompBoolUC(BadAddress, OldInfo.BadAddress);
527 CompBoolUC(TempAddressActive, OldInfo.TempAddressActive);
528 CompBoolUC(ConfAddressActive, OldInfo.ConfAddressActive);
529
530 CompStrs(PhoneNumResidence, OldInfo.PhoneNumResidence);
531 CompStrs(PhoneNumWork, OldInfo.PhoneNumWork);
532 CompStrs(PhoneNumCell, OldInfo.PhoneNumCell);
533 CompStrs(PhoneNumTemp, OldInfo.PhoneNumTemp);
534 CompStrs(Sex, OldInfo.Sex);
535
536 //Compare Aliases
537 //format: s=IEN#, Object is ^tAlias
538
539 //first, see which entries in OldInfo are deleted in CurInfo.
540 for i := 0 to OldInfo.AliasInfo.Count-1 do begin
541 pAlias := tAlias(OldInfo.AliasInfo.Objects[i]);
542 if CompAlias(OldInfo.AliasInfo.Strings[i], pAlias, self) = NEW_RECORD then begin
543 //here we have an entry in OldInfo, not in CurInfo, so must represent a Delete
544 //This needs to be posted to server with old IEN and @ symbol
545 tempPAlias := tAlias.Create;
546 tempPAlias.Name := '@';
547 AliasInfo.AddObject(OldInfo.AliasInfo.Strings[i],tempPAlias);
548 end;
549 end;
550
551 AddCt := 0;
552 //First, see which entries in New PatientInfo are new, or unchanged.
553 for i := 0 to AliasInfo.Count-1 do begin
554 pAlias := tAlias(AliasInfo.Objects[i]);
555 if (pAlias=nil) then continue;
556 if pAlias.Name= '@' then continue; //skip those marked as deleted from OldInfo
557 case CompAlias(AliasInfo.Strings[i], pAlias, OldInfo) of
558 NO_CHANGE : begin //delete unchanged data (no need to repost to server)
559 pAlias.Destroy;
560 AliasInfo.Strings[i] :='<@>'; //mark for deletion below
561 end;
562 NEW_RECORD : begin //mark as +1, +2 etc IEN
563 AddCt := AddCt + 1;
564 AliasInfo.Strings[i] := '+' + IntToStr(AddCt);
565 end;
566 CHANGED_RECORD : begin end; // do nothing, leave changes in place
567 end; {case}
568 end;
569
570 for i := AliasInfo.Count-1 downto 0 do begin
571 if AliasInfo.Strings[i] = '<@>' then AliasInfo.Delete(i);
572 end;
573
574
575end;
576
577
578//=========================================================
579//=========================================================
580//=========================================================
581
582procedure TfrmPtDemoEdit.GetPtInfo;
583var tempINI : TMemINIFile; //I do this to make dealing with hash table read easier
584 i,index : integer;
585 IEN, Key,Value,s : string;
586 pAlias : tAlias;
587
588begin
589 FServerPatientInfo.Clear;
590 tempINI := TMemINIFile.Create('xxx.ini');
591
592 RPCBrokerV.remoteprocedure := 'TMG GET PATIENT DEMOGRAPHICS';
593 RPCBrokerV.param[0].value := Patient.DFN; RPCBrokerV.param[0].ptype := literal;
594 //RPCBrokerV.Call;
595 CallBroker;
596
597 with FServerPatientInfo do begin
598 //Store results in a hash table for easier random access
599 //Don't store Alias info in hash table, put directly into AliasInfo stringlist
600 for i := 0 to RPCBrokerV.Results.Count-1 do begin
601 s := RPCBrokerV.Results.Strings[i];
602 if Pos('ALIAS',s)=0 then begin
603 Key := piece(s,'=',1);
604 Value := piece(s,'=',2);
605 tempINI.WriteString('DATA',Key,Value);
606 end else begin
607 IEN := piece(s,' ',2);
608 if StrToInt(IEN)>MaxAliasIEN then MaxAliasIEN := StrToInt(IEN);
609 index := AliasInfo.IndexOf(IEN);
610 if index <0 then begin
611 pAlias := tAlias.Create; //AliasInfo will own these.
612 AliasInfo.AddObject(IEN,pAlias);
613 end else begin
614 pAlias := tAlias(AliasInfo.Objects[index]);
615 end;
616 if Pos('NAME=',s)>0 then begin
617 pAlias.Name := piece(s,'=',2);
618 end else if Pos('SSN=',s)>0 then begin
619 pAlias.SSN := piece(s,'=',2);
620 end;
621 end;
622 end;
623 LName:=tempINI.ReadString('DATA','LNAME','');
624 FName:=tempINI.ReadString('DATA','FNAME','');
625 MName:=tempINI.ReadString('DATA','MNAME','');
626 CombinedName:=tempINI.ReadString('DATA','COMBINED_NAME','');
627 Prefix:=tempINI.ReadString('DATA','PREFIX','');
628 Suffix:=tempINI.ReadString('DATA','SUFFIX','');
629 Degree:=tempINI.ReadString('DATA','DEGREE','');
630 DOB:= tempINI.ReadString('DATA','DOB','');
631 Sex:= tempINI.ReadString('DATA','SEX','');
632 SSNum:= tempINI.ReadString('DATA','SS_NUM','');
633 EMail:= tempINI.ReadString('DATA','EMAIL','');
634 AddressLine1:= tempINI.ReadString('DATA','ADDRESS_LINE_1','');
635 AddressLine2:= tempINI.ReadString('DATA','ADDRESS_LINE_2','');
636 AddressLine3:= tempINI.ReadString('DATA','ADDRESS_LINE_3','');
637 City:= tempINI.ReadString('DATA','CITY','');
638 State:= tempINI.ReadString('DATA','STATE','');
639 Zip4:= tempINI.ReadString('DATA','ZIP4','');
640 BadAddress:= BoolUC(tempINI.ReadString('DATA','BAD_ADDRESS','')<>'');
641 TempAddressLine1:= tempINI.ReadString('DATA','TEMP_ADDRESS_LINE_1','');
642 TempAddressLine2:= tempINI.ReadString('DATA','TEMP_ADDRESS_LINE_2','');
643 TempAddressLine3:= tempINI.ReadString('DATA','TEMP_ADDRESS_LINE_3','');
644 TempCity:= tempINI.ReadString('DATA','TEMP_CITY','');
645 TempState:=tempINI.ReadString('DATA','TEMP_STATE','');
646 TempZip4:= tempINI.ReadString('DATA','TEMP_ZIP4','');
647 TempStartingDate :=tempINI.ReadString('DATA','TEMP_STARTING_DATE','');
648 TempEndingDate := tempINI.ReadString('DATA','TEMP_ENDING_DATE','');
649 TempAddressActive:= BoolUC(tempINI.ReadString('DATA','TEMP_ADDRESS_ACTIVE','')='YES');
650 ConfidentalAddressLine1:= tempINI.ReadString('DATA','CONF_ADDRESS_LINE_1','');
651 ConfidentalAddressLine2:= tempINI.ReadString('DATA','CONF_ADDRESS_LINE_2','');
652 ConfidentalAddressLine3:= tempINI.ReadString('DATA','CONF_ADDRESS_LINE_3','');
653 ConfidentalCity:= tempINI.ReadString('DATA','CONF_CITY','');
654 ConfidentalState:= tempINI.ReadString('DATA','CONF_STATE','');
655 ConfidentalZip:= tempINI.ReadString('DATA','CONF_ZIP','');
656 ConfidentalStartingDate := tempINI.ReadString('DATA','CONG_STARTING_DATE','');
657 ConfidentalEndingDate := tempINI.ReadString('DATA','CONF_ENDING_DATE','');
658 ConfAddressActive:= BoolUC(tempINI.ReadString('DATA','CONF_ADDRESS_ACTIVE','')='YES');
659 PhoneNumResidence:= tempINI.ReadString('DATA','PHONE_RESIDENCE','');
660 PhoneNumWork:= tempINI.ReadString('DATA','PHONE_WORK','');
661 PhoneNumCell:= tempINI.ReadString('DATA','PHONE_CELL','');
662 PhoneNumTemp:= tempINI.ReadString('DATA','PHONE_TEMP','');
663 end;
664 FCurPatientInfo.Assign(FServerPatientInfo);
665 tempINI.Free; //I don't write out, so should never end up on disk.
666end;
667
668procedure TfrmPtDemoEdit.PostChangedInfo(PatientInfo : TPatientInfo);
669
670 procedure CheckBUCPost(Title : string; Value : BoolUC);
671 begin
672 if Value <> bucUnchanged then begin
673 if Value = bucTrue then RPCBrokerV.Param[1].Mult['"'+Title+'"'] := 'YES';
674 if Value = bucFalse then RPCBrokerV.Param[1].Mult['"'+Title+'"'] := 'NO';
675 end;
676 end;
677
678 procedure CheckPost(Title, Value : string);
679 begin
680 if Value <> '' then RPCBrokerV.Param[1].Mult['"'+Title+'"'] := Value;
681 end;
682
683 var i : integer;
684 pAlias : tAlias;
685begin
686 RPCBrokerV.remoteprocedure := 'TMG SET PATIENT DEMOGRAPHICS';
687 RPCBrokerV.param[0].value := Patient.DFN; RPCBrokerV.param[0].ptype := literal;
688
689 RPCBrokerV.Param[1].PType := list;
690 with PatientInfo do begin
691 CheckPost('COMBINED_NAME',CombinedName);
692 //CheckPost('LNAME', LName); //Don't send because data is in COMBINED NAME
693 //CheckPost('FNAME',FName);
694 //CheckPost('MNAME',MName);
695 //CheckPost('PREFIX',Prefix);
696 //CheckPost('SUFFIX',Suffix);
697 //CheckPost('DEGREE',Degree);
698 CheckPost('DOB',DOB);
699 CheckPost('SEX',Sex);
700 CheckPost('SS_NUM',SSNum);
701 CheckPost('EMAIL',EMail);
702 CheckPost('ADDRESS_LINE_1',AddressLine1);
703 CheckPost('ADDRESS_LINE_2',AddressLine2);
704 CheckPost('ADDRESS_LINE_3',AddressLine3);
705 CheckPost('CITY',City);
706 CheckPost('STATE',State);
707 CheckPost('ZIP4',Zip4);
708
709 CheckPost('TEMP_ADDRESS_LINE_1',TempAddressLine1);
710 CheckPost('TEMP_ADDRESS_LINE_2',TempAddressLine2);
711 CheckPost('TEMP_ADDRESS_LINE_3',TempAddressLine3);
712 CheckPost('TEMP_CITY',TempCity);
713 CheckPost('TEMP_STATE',TempState);
714 CheckPost('TEMP_ZIP4',TempZip4);
715 CheckPost('TEMP_STARTING_DATE',TempStartingDate );
716 CheckPost('TEMP_ENDING_DATE',TempEndingDate );
717 CheckPost('CONF_ADDRESS_LINE_1',ConfidentalAddressLine1);
718 CheckPost('CONF_ADDRESS_LINE_2',ConfidentalAddressLine2);
719 CheckPost('CONF_ADDRESS_LINE_3',ConfidentalAddressLine3);
720 CheckPost('CONF_CITY',ConfidentalCity);
721 CheckPost('CONF_STATE',ConfidentalState);
722 CheckPost('CONF_ZIP',ConfidentalZip);
723 CheckPost('CONG_STARTING_DATE',ConfidentalStartingDate );
724 CheckPost('CONF_ENDING_DATE',ConfidentalEndingDate );
725 CheckPost('PHONE_RESIDENCE',PhoneNumResidence);
726 CheckPost('PHONE_WORK',PhoneNumWork);
727 CheckPost('PHONE_CELL',PhoneNumCell);
728 CheckPost('PHONE_TEMP',PhoneNumTemp);
729
730 case BadAddress of
731 bucTrue: RPCBrokerV.Param[1].Mult['"BAD_ADDRESS"'] := 'UNDELIVERABLE';
732 bucFalse: RPCBrokerV.Param[1].Mult['"BAD_ADDRESS"'] := '@';
733 end; {case}
734 CheckBUCPost('TEMP_ADDRESS_ACTIVE', TempAddressActive);
735 CheckBUCPost('CONF_ADDRESS_ACTIVE', ConfAddressActive);
736
737 for i := 0 to AliasInfo.Count-1 do begin
738 pAlias := tAlias(AliasInfo.Objects[i]);
739 if (pAlias=nil) then continue;
740 RPCBrokerV.Param[1].Mult['"ALIAS ' + AliasInfo.Strings[i] + ' NAME"'] := pAlias.Name;
741 if pAlias.Name <> '@' then begin
742 RPCBrokerV.Param[1].Mult['"ALIAS ' + AliasInfo.Strings[i] + ' SSN"'] := pAlias.SSN;
743 end;
744 end;
745
746 //RPCBrokerV.Call;
747 CallBroker;
748 if RPCBrokerV.Results.Strings[0]<>'1' then begin
749 MessageDlg(RPCBrokerV.Results.Strings[0],mtError,[mbOK],0);
750 end else begin
751 ChangesMade := true;
752 end;
753 end;
754end;
755
756
757procedure TfrmPtDemoEdit.ShowPtInfo(Patient : TPatientInfo);
758var i : integer;
759 pAlias : tAlias;
760begin
761 ProgNameChangeOccuring := true;
762 With Patient do begin
763 LNameEdit.Text := LName;
764 FNameEdit.Text := FName;
765 MNameEdit.Text := MName;
766 CombinedNameEdit.Text := CombinedName;
767 PrefixEdit.Text := Prefix;
768 SuffixEdit.Text := Suffix;
769 DegreeEdit.Text := Degree;
770 DOBEdit.Text := DOB;
771 SSNumEdit.Text := SSNum;
772 EMailEdit.Text := EMail;
773 if Sex='MALE' then SexComboBox.ItemIndex := 0 else SexComboBox.ItemIndex := 1;
774 AliasComboBox.Items.Clear;
775 for i := 0 to AliasInfo.Count-1 do begin
776 pAlias := tAlias(AliasInfo.Objects[i]);
777 if pAlias<>nil then begin
778 AliasComboBox.Items.AddObject(pAlias.Name,pAlias);
779 end;
780 end;
781 if AliasComboBox.Items.count>0 then begin
782 AliasComboBox.ItemIndex := 0;
783 SetAliasEnabled(true);
784 end;
785 ShowAliasInfo(Patient);
786
787 PhoneNumGrp.ItemIndex := 0;
788 PhoneNumGrpClick(self);
789 end;
790
791 BadAddressCB.Visible := false;
792 TempActiveCB.Visible := false;
793 ProgNameChangeOccuring := false;
794end;
795
796procedure TfrmPtDemoEdit.ShowAliasInfo(Patient : TPatientInfo);
797var i : integer;
798 pAlias : tAlias;
799begin
800 i := AliasComboBox.ItemIndex;
801 if i > -1 then begin
802 if i < Patient.AliasInfo.Count then begin
803 pAlias := tAlias(Patient.AliasInfo.Objects[i]);
804 end else pAlias := nil;
805 ProgAliasChangeOccuring := true;
806 if pAlias<>nil then begin
807 AliasNameEdit.Text := pAlias.Name;
808 AliasSSNEdit.Text := pAlias.SSN;
809 end else begin
810 AliasNameEdit.Text := '';
811 AliasSSNEdit.Text := '';
812 end;
813 ProgAliasChangeOccuring := false;
814 end;
815end;
816
817
818procedure TfrmPtDemoEdit.AliasComboBoxChange(Sender: TObject);
819var s : string;
820 i : integer;
821begin
822 if ProgAliasChangeOccuring=false then begin
823 i := AliasCombobox.ItemIndex;
824 if i>-1 then begin
825 s := AliasCombobox.Items.Strings[i];
826 SetAliasEnabled(true);
827 end else begin
828 SetAliasEnabled(false);
829 end;
830 ShowAliasInfo(FCurPatientInfo);
831 end;
832end;
833
834procedure TfrmPtDemoEdit.FormCreate(Sender: TObject);
835begin
836 FCurAliasEdit := -1;
837 FCurPatientInfo := TPatientInfo.Create;
838 FServerPatientInfo := TPatientInfo.Create;
839 DataForGrid := TStringList.Create; //will own GridInfo objects.
840 ProgAliasChangeOccuring := false;
841 ProgNameChangeOccuring := false;
842 ProgPhoneChangeOccuring := false;
843 ProgAddressChangeOccuring := false;
844 MaxAliasIEN := 0;
845 ChangesMade := false;
846 CurrentPatientData := TStringList.Create;
847 AddGridInfo(GridPatientDemo,CurrentPatientData,false,GetPatientInfo,'2');
848
849end;
850
851procedure TfrmPtDemoEdit.FormDestroy(Sender: TObject);
852begin
853 DataForGrid.Free;
854 FCurPatientInfo.Destroy;
855 FServerPatientInfo.Destroy;
856 CurrentPatientData.Free;
857end;
858
859
860procedure TfrmPtDemoEdit.AddressRGrpClick(Sender: TObject);
861begin
862 {fill in data for newly selected fields}
863 ProgAddressChangeOccuring := true;
864 TempActiveCB.Visible := false;
865 BadAddressCB.Visible := false;
866 ConfActiveCB.Visible := false;
867 StartingDateLabel.Visible := false;
868 StartingDateEdit.Visible := false;
869 EndingDateLabel.Visible := false;
870 EndingDateEdit.Visible := false;
871 case AddressRGrp.ItemIndex of
872 0 : begin //Permanant
873 AddressLine1Edit.Text := FCurPatientInfo.AddressLine1;
874 AddressLine2Edit.Text := FCurPatientInfo.AddressLine2;
875 AddressLine3Edit.text := FCurPatientInfo.AddressLine3;
876 CityEdit.text := FCurPatientInfo.City;
877 StateComboBox.text := FCurPatientInfo.State;
878 Zip4Edit.text := FCurPatientInfo.Zip4;
879 BadAddressCB.Visible := true;
880 BadAddressCB.Checked := (FCurPatientInfo.BadAddress=bucTrue);
881 end;
882 1 : begin //temp
883 AddressLine1Edit.Text := FCurPatientInfo.TempAddressLine1;
884 AddressLine2Edit.Text := FCurPatientInfo.TempAddressLine2;
885 AddressLine3Edit.Text := FCurPatientInfo.TempAddressLine3;
886 CityEdit.Text := FCurPatientInfo.TempCity;
887 StateComboBox.Text := FCurPatientInfo.TempState;
888 Zip4Edit.Text := FCurPatientInfo.TempZip4;
889 StartingDateEdit.Text := FCurPatientInfo.TempStartingDate ;
890 EndingDateEdit.Text := FCurPatientInfo.TempEndingDate ;
891 StartingDateLabel.Visible := true;
892 StartingDateEdit.Visible := true;
893 EndingDateLabel.Visible := true;
894 EndingDateEdit.Visible := true;
895 TempActiveCB.Visible := true;
896 TempActiveCB.Checked := (FCurPatientInfo.TempAddressActive=bucTrue);
897 end;
898 2 : begin //confidental
899 AddressLine1Edit.Text := FCurPatientInfo.ConfidentalAddressLine1;
900 AddressLine2Edit.Text := FCurPatientInfo.ConfidentalAddressLine2;
901 AddressLine3Edit.Text := FCurPatientInfo.ConfidentalAddressLine3;
902 CityEdit.Text := FCurPatientInfo.ConfidentalCity;
903 StateComboBox.Text := FCurPatientInfo.ConfidentalState;
904 Zip4Edit.Text := FCurPatientInfo.ConfidentalZip;
905 StartingDateEdit.Text := FCurPatientInfo.ConfidentalStartingDate ;
906 EndingDateEdit.Text := FCurPatientInfo.ConfidentalEndingDate ;
907 StartingDateLabel.Visible := true;
908 StartingDateEdit.Visible := true;
909 EndingDateLabel.Visible := true;
910 EndingDateEdit.Visible := true;
911 ConfActiveCB.Visible := true;
912 ConfActiveCB.Checked := (FCurPatientInfo.ConfAddressActive=bucTrue);
913 end;
914 end; {case}
915 ProgAddressChangeOccuring := false;
916end;
917
918procedure TfrmPtDemoEdit.PhoneNumGrpClick(Sender: TObject);
919begin
920 ProgPhoneChangeOccuring := true;
921 case PhoneNumGrp.ItemIndex of
922 0 : begin //Residence
923 PhoneNumEdit.Text := FCurPatientInfo.PhoneNumResidence;
924 end;
925 1 : begin //work
926 PhoneNumEdit.Text := FCurPatientInfo.PhoneNumWork;
927 end;
928 2 : begin //cell
929 PhoneNumEdit.Text := FCurPatientInfo.PhoneNumCell;
930 end;
931 3 : begin //temp
932 PhoneNumEdit.Text := FCurPatientInfo.PhoneNumTemp;
933 end;
934 else begin
935 PhoneNumEdit.Text := '';
936 end;
937 end; {case}
938 ProgPhoneChangeOccuring := false;
939end;
940
941procedure TfrmPtDemoEdit.DelAliasBtnClick(Sender: TObject);
942var i, j : integer;
943 pAlias : tAlias;
944begin
945 i := AliasComboBox.ItemIndex;
946 if i > -1 then begin
947 pAlias := tAlias(AliasComboBox.Items.Objects[i]);
948 if pAlias<>nil then begin
949 for j := 0 to FCurPatientInfo.AliasInfo.Count-1 do begin
950 if FCurPatientInfo.AliasInfo.Objects[j] = pAlias then begin
951 FCurPatientInfo.AliasInfo.Delete(j);
952 SetModified(true);
953 pAlias.Free;
954 AliasComboBox.Items.Delete(i);
955 //AliasComboBox.ItemIndex := 0;
956 //ShowAliasInfo(FCurPatientInfo);
957 ProgAliasChangeOccuring:= true;
958 AliasNameEdit.Text:='';
959 AliasSSNEdit.Text:='';
960 ProgAliasChangeOccuring:= false;
961 break;
962 end;
963 end;
964 end;
965 end;
966 if AliasCombobox.Items.Count=0 then begin
967 AliasNameEdit.Text:='';
968 AliasSSNEdit.Text:='';
969 SetAliasEnabled(false);
970 AliasCombobox.Text := '';
971 end;
972end;
973
974procedure TfrmPtDemoEdit.FormShow(Sender: TObject);
975begin
976 PageControl.ActivePageIndex := 0;
977 GetPtInfo(FServerPatientInfo);
978 FCurPatientInfo.Assign(FServerPatientInfo);
979 ShowPtInfo(FCurPatientInfo);
980end;
981
982procedure TfrmPtDemoEdit.CombinedNameEditChange(Sender: TObject);
983var LName,FName,MName : string;
984begin
985 if ProgNameChangeOccuring = false then begin
986 FCurPatientInfo.CombinedName := CombinedNameEdit.Text;
987 SetModified(true);
988 if CombinedNameEdit.Text <> CombinedName then begin
989 ProgNameChangeOccuring := true;
990 NameParts(CombinedNameEdit.Text, LName, FName, MName);
991 LNameEdit.Text := LName;
992 FNameEdit.Text := FName;
993 MNameEdit.Text := MName;
994 ProgNameChangeOccuring := false;
995 end;
996 end;
997end;
998
999procedure TfrmPtDemoEdit.LNameEditChange(Sender: TObject);
1000begin
1001 if ProgNameChangeOccuring = false then begin
1002 FCurPatientInfo.LName := LNameEdit.Text;
1003 SetModified(true);
1004 CombinedNameEdit.Text := CombinedName;
1005 end;
1006end;
1007
1008procedure TfrmPtDemoEdit.FNameEditChange(Sender: TObject);
1009begin
1010 if ProgNameChangeOccuring = false then begin
1011 FCurPatientInfo.FName := FNameEdit.Text;
1012 SetModified(true);
1013 CombinedNameEdit.Text := CombinedName;
1014 end
1015end;
1016
1017procedure TfrmPtDemoEdit.MNameEditChange(Sender: TObject);
1018begin
1019 if ProgNameChangeOccuring = false then begin
1020 FCurPatientInfo.MName := MNameEdit.Text;
1021 SetModified(true);
1022 CombinedNameEdit.Text := CombinedName;
1023 end;
1024end;
1025
1026procedure TfrmPtDemoEdit.PrefixEditChange(Sender: TObject);
1027begin
1028 if ProgNameChangeOccuring = false then begin
1029 FCurPatientInfo.Prefix := PrefixEdit.Text;
1030 SetModified(true);
1031 end;
1032end;
1033
1034procedure TfrmPtDemoEdit.SuffixEditChange(Sender: TObject);
1035begin
1036 if ProgNameChangeOccuring = false then begin
1037 FCurPatientInfo.Suffix := SuffixEdit.Text;
1038 SetModified(true);
1039 CombinedNameEdit.Text := CombinedName;
1040 end;
1041end;
1042
1043procedure TfrmPtDemoEdit.DOBEditChange(Sender: TObject);
1044begin
1045 if ProgNameChangeOccuring = false then begin
1046 FCurPatientInfo.DOB := DOBEdit.Text;
1047 SetModified(true);
1048 end;
1049end;
1050
1051procedure TfrmPtDemoEdit.SSNumEditChange(Sender: TObject);
1052begin
1053 if ProgNameChangeOccuring = false then begin
1054 FCurPatientInfo.SSNum := SSNumEdit.Text;
1055 SetModified(true);
1056 end;
1057end;
1058
1059procedure TfrmPtDemoEdit.EMailEditChange(Sender: TObject);
1060begin
1061 if ProgNameChangeOccuring = false then begin
1062 FCurPatientInfo.EMail := EMailEdit.Text;
1063 SetModified(true);
1064 end;
1065end;
1066
1067procedure TfrmPtDemoEdit.SexComboBoxChange(Sender: TObject);
1068begin
1069 if ProgNameChangeOccuring = false then begin
1070 FCurPatientInfo.Sex := SexComboBox.Text;
1071 SetModified(true);
1072 end;
1073end;
1074
1075procedure TfrmPtDemoEdit.DegreeEditChange(Sender: TObject);
1076begin
1077 if ProgNameChangeOccuring = false then begin
1078 FCurPatientInfo.Degree := DegreeEdit.Text;
1079 SetModified(true);
1080 end;
1081end;
1082
1083procedure TfrmPtDemoEdit.AddressLine1EditChange(Sender: TObject);
1084begin
1085 if ProgAddressChangeOccuring = false then SetModified(true);
1086 Case AddressRGrp.ItemIndex of
1087 0 : FCurPatientInfo.AddressLine1 := AddressLine1Edit.Text;
1088 1 : FCurPatientInfo.TempAddressLine1 := AddressLine1Edit.Text;
1089 2 : FCurPatientInfo.ConfidentalAddressLine1 := AddressLine1Edit.Text;
1090 end; {case}
1091end;
1092
1093procedure TfrmPtDemoEdit.AddressLine2EditChange(Sender: TObject);
1094begin
1095 if ProgAddressChangeOccuring = false then SetModified(true);
1096 Case AddressRGrp.ItemIndex of
1097 0 : FCurPatientInfo.AddressLine2 := AddressLine2Edit.Text;
1098 1 : FCurPatientInfo.TempAddressLine2 := AddressLine2Edit.Text;
1099 2 : FCurPatientInfo.ConfidentalAddressLine2 := AddressLine2Edit.Text;
1100 end; {case}
1101end;
1102
1103procedure TfrmPtDemoEdit.AddressLine3EditChange(Sender: TObject);
1104begin
1105 if ProgAddressChangeOccuring = false then SetModified(true);
1106 Case AddressRGrp.ItemIndex of
1107 0 : FCurPatientInfo.AddressLine3 := AddressLine3Edit.Text;
1108 1 : FCurPatientInfo.TempAddressLine3 := AddressLine3Edit.Text;
1109 2 : FCurPatientInfo.ConfidentalAddressLine3 := AddressLine3Edit.Text;
1110 end; {case}
1111end;
1112
1113procedure TfrmPtDemoEdit.CityEditChange(Sender: TObject);
1114begin
1115 if ProgAddressChangeOccuring = false then SetModified(true);
1116 Case AddressRGrp.ItemIndex of
1117 0 : FCurPatientInfo.City := CityEdit.Text;
1118 1 : FCurPatientInfo.TempCity := CityEdit.Text;
1119 2 : FCurPatientInfo.ConfidentalCity := CityEdit.Text;
1120 end; {case}
1121end;
1122
1123procedure TfrmPtDemoEdit.Zip4EditChange(Sender: TObject);
1124begin
1125 if ProgAddressChangeOccuring = false then SetModified(true);
1126 Case AddressRGrp.ItemIndex of
1127 0 : FCurPatientInfo.Zip4 := Zip4Edit.Text;
1128 1 : FCurPatientInfo.TempZip4 := Zip4Edit.Text;
1129 2 : FCurPatientInfo.ConfidentalZip := leftstr(Zip4Edit.Text,5);
1130 end; {case}
1131end;
1132
1133procedure TfrmPtDemoEdit.StateComboBoxChange(Sender: TObject);
1134begin
1135 if ProgAddressChangeOccuring = false then SetModified(true);
1136 Case AddressRGrp.ItemIndex of
1137 0 : FCurPatientInfo.State := StateComboBox.Text;
1138 1 : FCurPatientInfo.TempState := StateComboBox.Text;
1139 2 : FCurPatientInfo.ConfidentalState := StateComboBox.Text;
1140 end; {case}
1141end;
1142
1143procedure TfrmPtDemoEdit.TempActiveCBClick(Sender: TObject);
1144begin
1145 FCurPatientInfo.TempAddressActive := BoolUC(TempActiveCB.Checked);
1146 if ProgAddressChangeOccuring = false then SetModified(true);
1147end;
1148
1149procedure TfrmPtDemoEdit.ConfActiveCBClick(Sender: TObject);
1150begin
1151 FCurPatientInfo.ConfAddressActive := BoolUC(ConfActiveCB.Checked);
1152 if ProgAddressChangeOccuring = false then SetModified(true);
1153end;
1154
1155procedure TfrmPtDemoEdit.BadAddressCBClick(Sender: TObject);
1156begin
1157 FCurPatientInfo.BadAddress := BoolUC(BadAddressCB.Checked);
1158 if ProgAddressChangeOccuring = false then SetModified(true);
1159end;
1160
1161procedure TfrmPtDemoEdit.PhoneNumEditChange(Sender: TObject);
1162begin
1163 if ProgPhoneChangeOccuring = false then SetModified(true);
1164 Case PhoneNumGrp.ItemIndex of
1165 0 : FCurPatientInfo.PhoneNumResidence := PhoneNumEdit.Text;
1166 1 : FCurPatientInfo.PhoneNumWork := PhoneNumEdit.Text;
1167 2 : FCurPatientInfo.PhoneNumCell := PhoneNumEdit.Text;
1168 3 : FCurPatientInfo.PhoneNumTemp := PhoneNumEdit.Text;
1169 end; {case}
1170
1171end;
1172
1173procedure TfrmPtDemoEdit.StartingDateEditChange(Sender: TObject);
1174begin
1175 if ProgAddressChangeOccuring = false then SetModified(true);
1176 Case AddressRGrp.ItemIndex of
1177 1 : FCurPatientInfo.TempStartingDate := StartingDateEdit.Text;
1178 2 : FCurPatientInfo.ConfidentalStartingDate := StartingDateEdit.Text;
1179 end; {case}
1180end;
1181
1182procedure TfrmPtDemoEdit.EndingDateEditChange(Sender: TObject);
1183begin
1184 if ProgAddressChangeOccuring = false then SetModified(true);
1185 Case AddressRGrp.ItemIndex of
1186 1 : FCurPatientInfo.TempEndingDate := EndingDateEdit.Text;
1187 2 : FCurPatientInfo.ConfidentalEndingDate := EndingDateEdit.Text;
1188 end; {case}
1189end;
1190
1191procedure TfrmPtDemoEdit.AliasNameEditChange(Sender: TObject);
1192var i : integer;
1193 pAlias : tAlias;
1194 tempB : boolean;
1195begin
1196 if ProgAliasChangeOccuring=false then begin
1197 i := AliasComboBox.ItemIndex;
1198 if i > -1 then begin
1199 pAlias := tAlias(AliasComboBox.Items.Objects[i]);
1200 if pAlias<>nil then begin
1201 pAlias.Name := AliasNameEdit.Text;
1202 AliasComboBox.Items.Strings[i]:= AliasNameEdit.Text;
1203 AliasComboBox.Text := AliasNameEdit.Text;
1204 tempB := ProgAliasChangeOccuring;
1205 ProgAliasChangeOccuring:=true;
1206 AliasComboBox.ItemIndex := i;
1207 ProgAliasChangeOccuring:=tempB;
1208 SetModified(true);
1209 end;
1210 end;
1211 end;
1212end;
1213
1214
1215procedure TfrmPtDemoEdit.AliasSSNEditChange(Sender: TObject);
1216var i : integer;
1217 pAlias : tAlias;
1218begin
1219 if ProgAliasChangeOccuring=false then begin
1220 i := AliasComboBox.ItemIndex;
1221 if i > -1 then begin
1222 pAlias := tAlias(AliasComboBox.Items.Objects[i]);
1223 if pAlias<>nil then begin
1224 pAlias.SSN := AliasSSNEdit.Text;
1225 SetModified(true);
1226 end;
1227 end;
1228 end;
1229end;
1230
1231procedure TfrmPtDemoEdit.SetAliasEnabled(value : boolean);
1232begin
1233 AliasNameEdit.Enabled := value;
1234 AliasSSNEdit.Enabled := value;
1235 if value=true then begin
1236 AliasNameEdit.Color := clWindow;
1237 AliasSSNEdit.Color := clWindow;
1238 end else begin
1239 AliasNameEdit.Color := clInactiveBorder;
1240 AliasSSNEdit.Color := clInactiveBorder;
1241 end;
1242end;
1243
1244
1245function TfrmPtDemoEdit.CombinedName : string;
1246begin
1247 Result := '';
1248 Result := FNameEdit.Text;
1249 if MNameEdit.Text <> '' then Result := Result + ' ' + MNameEdit.Text;
1250 if SuffixEdit.Text <> '' then Result := Result + ' ' + SuffixEdit.Text;
1251 if Result <> '' then Result := ',' + Result;
1252 Result := LNameEdit.Text + Result;
1253end;
1254
1255procedure TfrmPtDemoEdit.NameParts(CombinedName: string; var LName, FName, MName : string);
1256var tempS : string;
1257begin
1258 LName := piece(CombinedName,',',1);
1259 tempS := piece(CombinedName,',',2);
1260 FName := piece(tempS,' ',1);
1261 MName := piece(tempS,' ',2,16);
1262end;
1263
1264
1265procedure TfrmPtDemoEdit.ApplyBtnClick(Sender: TObject);
1266var TempPatientInfo : tPatientInfo;
1267begin
1268if pagecontrol.ActivePageIndex = 0 then begin
1269 TempPatientInfo := tPatientInfo.Create;
1270 TempPatientInfo.Assign(FCurPatientInfo);
1271 TempPatientInfo.RemoveUnchanged(FServerPatientInfo);
1272 PostChangedInfo(TempPatientInfo);
1273 TempPatientInfo.Destroy;
1274 SetModified(false);
1275end else begin
1276 PostVisibleGrid;
1277 SetModified(false);
1278end;
1279end;
1280function TfrmPtDemoEdit.PostVisibleGrid: TModalResult;
1281 begin
1282 result := PostChanges(gridPatientDemo);
1283 end;
1284
1285function TfrmPtDemoEdit.PostChanges(Grid : TSortStringGrid) : TModalResult;
1286 //Results: mrNone -- no post done (not needed)
1287 // mrCancel -- user pressed cancel on confirmation screen.
1288 // mrNo -- signals posting error.
1289 var Changes : TStringList;
1290 PostResult : TModalResult;
1291 CurrentData : TStringList;
1292 GridInfo : TGridInfo;
1293 IENS : string;
1294 begin
1295 Result := mrNone; //default to No changes
1296 GridInfo := GetInfoForGrid(Grid);
1297 if GridInfo=nil then exit;
1298 CurrentData := GridInfo.Data;
1299 if CurrentData=nil then exit;
1300 if CurrentData.Count = 0 then exit;
1301 IENS := Patient.DFN;
1302 if IENS='' then exit;
1303 Changes := TStringList.Create;
1304 CompileChanges(Grid,CurrentData,Changes);
1305 if Changes.Count>0 then begin
1306 PostForm.PrepForm(Changes);
1307 PostResult := PostForm.ShowModal;
1308 if PostResult = mrOK then begin
1309 //if DisuserChanged(Changes) then begin //looks for change in file 200, field 4
1310 // InitializeUsersTreeView;
1311 //end else begin
1312 if Pos('+',IENS)>0 then begin
1313 GridInfo.IENS := PostForm.GetNewIENS(IENS);
1314 end;
1315 if assigned(GridInfo.DataLoadProc) then begin
1316 GridInfo.DataLoadProc(GridInfo);
1317 end;
1318 {
1319 if CurrentData = CurrentUserData then begin
1320 LoadUserData(IENS,CurrentData); //reload record from server.
1321 end else if CurrentData = CurrentSettingsData then begin
1322 GetSettingsInfo(GridInfo.FileNum, GridInfo.IENS, CurrentData);
1323 end else if CurrentData = CurrentPatientData then begin
1324 GetPatientInfo(GridInfo.IENS, CurrentData);
1325 end else if CurrentData = CurrentAnyFileData then begin
1326 GetAnyFileInfo(GridInfo.FileNum, GridInfo.IENS, CurrentData);
1327 end;
1328 }
1329 //end;
1330 end else if PostResult = mrNo then begin //mrNo is signal of post Error
1331 // show error...
1332 end;
1333 Result := PostResult;
1334 end else begin
1335 Result := mrNone;
1336 end;
1337 Changes.Free;
1338 end;
1339
1340 procedure TfrmPtDemoEdit.CompileChanges(Grid : TSortStringGrid; CurrentUserData,Changes : TStringList);
1341 //Output format:
1342 // FileNum^IENS^FieldNum^FieldName^newValue^oldValue
1343
1344 var row : integer;
1345 Entry : tFileEntry;
1346 oneEntry : string;
1347 begin
1348 for row := 1 to Grid.RowCount-1 do begin
1349 Entry := GetLineInfo(Grid,CurrentUserData, row);
1350 if Entry.oldValue <> Entry.newValue then begin
1351 if (Entry.newValue <> CLICK_FOR_SUBS) and
1352 (Entry.newValue <> COMPUTED_FIELD) and
1353 (Entry.newValue <> CLICK_TO_EDIT) then begin
1354 oneEntry := Entry.FileNum + '^' + Entry.IENS + '^' + Entry.Field + '^' + Entry.FieldName;
1355 oneEntry := oneEntry + '^' + Entry.newValue + '^' + Entry.oldValue;
1356 Changes.Add(oneEntry);
1357 end;
1358 end;
1359 end;
1360 end;
1361
1362procedure TfrmPtDemoEdit.SetModified(value : boolean);
1363begin
1364 FCurPatientInfo.Modified := value;
1365 ApplyBtn.Enabled := FCurPatientInfo.Modified;
1366end;
1367
1368procedure TfrmPtDemoEdit.AddAliasBtnClick(Sender: TObject);
1369var pAlias : tAlias;
1370 IEN : string;
1371begin
1372 pAlias := tAlias.Create;
1373 if FCurPatientInfo.AliasInfo.count>0 then begin
1374 IEN := FCurPatientInfo.AliasInfo.Strings[FCurPatientInfo.AliasInfo.count-1];
1375 end else begin
1376 IEN := IntToStr(MaxAliasIEN);
1377 end;
1378 MaxAliasIEN := StrToInt(IEN)+1;
1379 IEN := IntToStr(MaxAliasIEN);
1380 FCurPatientInfo.AliasInfo.AddObject(IEN,pAlias);
1381 SetModified(true);
1382 AliasCombobox.Items.AddObject('<Edit New Alias>',pAlias);
1383 //pAlias.Name := '<Edit New Alias>';
1384 //AliasCombobox.Items.Add(ADD_NEW_ALIAS);
1385 AliasCombobox.ItemIndex := AliasCombobox.Items.Count-1;
1386 SetAliasEnabled(true);
1387 ShowAliasInfo(FCurPatientInfo);
1388end;
1389
1390procedure TfrmPtDemoEdit.OKBtnClick(Sender: TObject);
1391begin
1392 if FCurPatientInfo.Modified = true then begin
1393 case MessageDlg('Apply Changes?',mtConfirmation,mbYesNoCancel,0) of
1394 mrYes : begin
1395 ApplyBtnClick(Sender);
1396 frmPtDemoEdit.ModalResult := mrOK; //closes form
1397 end;
1398 mrNo : begin
1399 if ChangesMade = false then frmPtDemoEdit.ModalResult := mrCancel // closes form, signal no need for refresh
1400 else frmPtDemoEdit.ModalResult := mrOK; // closes form.
1401 end;
1402 mrCancel : frmPtDemoEdit.ModalResult := mrNone; //do nothing
1403 end; {case}
1404 end else begin
1405 if ChangesMade = false then frmPtDemoEdit.ModalResult := mrCancel // closes form, signal no need for refresh
1406 else frmPtDemoEdit.ModalResult := mrOK; // closes form.
1407 end;
1408end;
1409
1410procedure TfrmPtDemoEdit.CancelBtnClick(Sender: TObject);
1411begin
1412 if FCurPatientInfo.Modified = true then begin
1413 case MessageDlg('Cancel Changes?',mtConfirmation,mbYesNoCancel,0) of
1414 mrYes : frmPtDemoEdit.ModalResult := mrCancel; //closes form
1415 mrNo : frmPtDemoEdit.ModalResult := mrNone; //do nothing
1416 mrCancel : frmPtDemoEdit.ModalResult := mrNone; //do nothing
1417 end; {case}
1418 end else begin
1419 frmPtDemoEdit.ModalResult := mrCancel; // closes form.
1420 end;
1421
1422end;
1423
1424
1425procedure TfrmPtDemoEdit.PageControlChange(Sender: TObject);
1426var
1427 GridInfo : TGridInfo;
1428 IEN : longInt;
1429 ModalResult : TModalResult;
1430
1431begin
1432 if pagecontrol.ActivePageIndex = 0 then begin
1433 GetPtInfo(FServerPatientInfo);
1434 FCurPatientInfo.Assign(FServerPatientInfo);
1435 ShowPtInfo(FCurPatientInfo);
1436 end else begin
1437 IEN := strtoint(patient.dfn); //get info from selected patient
1438 if IEN = 0 then exit;
1439 GridInfo := GetInfoForGrid(gridPatientDemo);
1440 if GridInfo = nil then exit;
1441 GridInfo.IENS := IntToStr(IEN)+',';
1442 GetPatientInfo(GridInfo);
1443 end;
1444
1445end;
1446
1447procedure TfrmPtDemoEdit.GetPatientInfo(GridInfo: TGridInfo);
1448
1449var cmd,RPCResult : string;
1450 IENS : String;
1451 grid : TSortStringGrid;
1452begin
1453// IENS := Patient.DFN;
1454 IENS := GridInfo.IENS;
1455// Data := GridInfo.Data;
1456 grid := GridInfo.Grid;
1457 grid.Cells[0,1] := '';
1458 grid.Cells[1,1] := '';
1459 grid.Cells[2,1] := '';
1460 grid.RowCount :=2;
1461 grid.Cursor := crHourGlass;
1462 if IENS <> '0,' then begin
1463 RPCBrokerV.remoteprocedure := 'TMG CHANNEL';
1464 RPCBrokerV.param[0].ptype := list;
1465 cmd := 'GET ONE RECORD^2^' + IENS;
1466 RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
1467 //RPCBrokerV.Call;
1468 CallBroker;
1469 RPCResult := RPCBrokerV.Results[0]; //returns: error: -1; success=1
1470 //Results[1]='FileNum^IENS^FieldNum^ExtValue^FieldName^DDInfo...
1471 //Results[2]='FileNum^IENS^FieldNum^ExtValue^FieldName^DDInfo...
1472 if piece(RPCResult,'^',1)='-1' then begin
1473 messagedlg(RPCBrokerV.Results[1],mtError,mbOKCancel,0);
1474 //FMErrorForm.Memo.Lines.Assign(RPCBrokerV.Results);
1475 end else begin
1476 GridInfo.Data.Assign(RPCBrokerV.results);
1477 //LoadAnyGrid(grid,false,'2',IENS,Data);
1478 LoadAnyGridFromInfo(GridInfo);
1479 end;
1480 end;
1481 gridPatientDemo.Cursor := crDefault;
1482end;
1483
1484procedure TfrmPtDemoEdit.LoadAnyGrid(Grid : TSortStringGrid; //the TSortStringGrid to load
1485 BasicMode: boolean;
1486 FileNum : string;
1487 IENS : string;
1488 CurrentData : TStringList);
1489 var
1490 GridInfo : TGridInfo;
1491 begin
1492 GridInfo := TGridInfo.Create;
1493 //This stores load information into a GridInfo
1494 GridInfo.Grid := Grid;
1495 GridInfo.BasicMode := BasicMode;
1496 GridInfo.FileNum := FileNum;
1497 GridInfo.IENS := IENS;
1498 GridInfo.Data := CurrentData;
1499 LoadAnyGridFromInfo(GridInfo);
1500 GridInfo.Free;
1501 end;
1502
1503procedure TfrmPtDemoEdit.LoadAnyGridFromInfo(GridInfo : TGridInfo);
1504 //This assumes that GridInfo already has loaded info.
1505 var
1506 Grid : TSortStringGrid; //the TSortStringGrid to load
1507 BasicMode: boolean;
1508 FileNum : string;
1509 IENS : string;
1510 CurrentData : TStringList;
1511
1512 procedure LoadOneLine (Grid : TSortStringGrid; oneEntry : string; GridRow : integer);
1513 var
1514 tempFile,IENS : string;
1515 fieldNum,fieldName,fieldDef : string;
1516 subFileNum : string;
1517 value : string;
1518 begin
1519 tempFile := Piece(oneEntry,'^',1);
1520 if tempFile = FileNum then begin //handle subfiles later...
1521 IENS := Piece(oneEntry,'^',2);
1522 fieldNum := Piece(oneEntry,'^',3);
1523 value := Piece(oneEntry,'^',4);
1524 fieldName := Piece(oneEntry,'^',5);
1525 fieldDef := Piece(oneEntry,'^',6);
1526 Grid.RowCount := GridRow + 1;
1527 Grid.Cells[0,GridRow] := fieldNum;
1528 Grid.Cells[1,GridRow] := fieldName;
1529 if Pos('W',fieldDef)>0 then begin
1530 Grid.Cells[2,GridRow] := CLICK_TO_EDIT;
1531 end else if IsSubFile(fieldDef, subFileNum) then begin
1532 if IsWPField(FileNum,fieldNum) then begin
1533 Grid.Cells[2,GridRow] := CLICK_TO_EDIT;
1534 end else begin
1535 Grid.Cells[2,GridRow] := CLICK_FOR_SUBS;
1536 end;
1537 end else if Pos('C',fieldDef)>0 then begin
1538 Grid.Cells[2,GridRow] := COMPUTED_FIELD;
1539 end else begin
1540 Grid.Cells[2,GridRow] := value;
1541 end;
1542 Grid.RowHeights[GridRow] := DEF_GRID_ROW_HEIGHT;
1543 end;
1544 end;
1545
1546 function getOneLine(CurrentData : TStringList; oneFileNum,oneFieldNum : string) : string;
1547 var i : integer;
1548 FileNum,FieldNum : string;
1549 begin
1550 result := '';
1551 // FileNum^IENS^FieldNum^FieldName^newValue^oldValue
1552 for i := 1 to CurrentData.Count - 1 do begin
1553 FileNum := piece(CurrentData.Strings[i],'^',1);
1554 if FileNum <> oneFileNum then continue;
1555 FieldNum := piece(CurrentData.Strings[i],'^',3);
1556 if FieldNum <> oneFieldNum then continue;
1557 result := CurrentData.Strings[i];
1558 break;
1559 end;
1560 end;
1561
1562 var i : integer;
1563 oneEntry : string;
1564 oneFileNum,oneFieldNum : string;
1565 gridRow : integer;
1566
1567 begin
1568 FLoadingGrid := true;
1569 if GridInfo=nil then exit;
1570 Grid := GridInfo.Grid;
1571 BasicMode := GridInfo.BasicMode;
1572 FileNum := GridInfo.FileNum;
1573 IENS := GridInfo.IENS;
1574 CurrentData := GridInfo.Data;
1575
1576 Grid.Cells[0,1] := '';
1577 Grid.Cells[1,1] := '';
1578 Grid.Cells[2,1] := '';
1579 Grid.RowCount :=2;
1580 Grid.ColWidths[0] := 50;
1581 Grid.ColWidths[1] := 200;
1582 Grid.ColWidths[2] := 300;
1583 Grid.Cells[0,0] := '#';
1584 Grid.Cells[1,0] := 'Name';
1585 Grid.Cells[2,0] := 'Value';
1586
1587 if BasicMode=false then begin
1588 for i := 1 to CurrentData.Count-1 do begin //start at 1 because [0] = 1^Success
1589 oneEntry := CurrentData.Strings[i];
1590 LoadOneLine (Grid,oneEntry,i);
1591 end;
1592 end else if BasicMode=true then begin
1593 gridRow := 1;
1594 for i := 0 to BasicTemplate.Count-1 do begin
1595 oneFileNum := Piece(BasicTemplate.Strings[i],'^',1);
1596 if oneFileNum <> fileNum then continue;
1597 oneFieldNum := Piece(BasicTemplate.Strings[i],'^',2);
1598 oneEntry := getOneLine(CurrentData,oneFileNum,oneFieldNum);
1599 LoadOneLine (Grid,oneEntry,gridRow);
1600 Inc(GridRow);
1601 end;
1602 end;
1603 FLoadingGrid := false;
1604 end;
1605
1606 function TfrmPtDemoEdit.GetInfoForGrid(Grid : TSortStringGrid) : TGridInfo;
1607 var i : integer;
1608 begin
1609 i := GetInfoIndexForGrid(Grid);
1610 if i > -1 then begin
1611 result := TGridInfo(DataForGrid.Objects[i]);
1612 end else begin
1613 result := nil;
1614 end;
1615 end;
1616
1617
1618 function TfrmPtDemoEdit.GetInfoIndexForGrid(Grid : TSortStringGrid) : integer;
1619 var s : string;
1620 begin
1621 s := IntToStr(integer(Grid));
1622 result := Dataforgrid.indexof(s);
1623 end;
1624
1625function TfrmPtDemoEdit.IsSubFile(FieldDef: string ; var SubFileNum : string) : boolean;
1626 //SubFileNum is OUT parameter
1627 begin
1628 SubFileNum := ExtractNum(FieldDef,1);
1629 result := (SubFileNum <> '');
1630 end;
1631
1632 function TfrmPtDemoEdit.IsWPField(FileNum,FieldNum : string) : boolean;
1633 var RPCResult : string;
1634 SrchStr : string;
1635 Idx: integer;
1636 begin
1637 SrchStr := FileNum + '^' + FieldNum + '^';
1638 //Idx := CachedWPField.IndexOf(SrchStr + 'YES');
1639 //if Idx > -1 then begin Result := true; exit; end;
1640 //Idx := CachedWPField.IndexOf(SrchStr + 'NO');
1641 //if Idx > -1 then begin Result := false; exit; end;
1642
1643 result := false;
1644 RPCBrokerV.remoteprocedure := 'TMG CHANNEL';
1645 RPCBrokerV.param[0].ptype := list;
1646 RPCBrokerV.Param[0].Mult['"REQUEST"'] := 'IS WP FIELD^' + FileNum + '^' + FieldNum;
1647 //RPCBrokerV.Call;
1648 CallBroker;
1649 RPCResult := RPCBrokerV.Results[0]; //returns: error: -1; success=1
1650 if piece(RPCResult,'^',1)='-1' then begin
1651 //FMErrorForm.Memo.Lines.Assign(RPCBrokerV.Results);
1652 //FMErrorForm.PrepMessage;
1653 //FMErrorForm.ShowModal;
1654 end else begin
1655 RPCResult := piece(RPCResult,'^',3);
1656 result := (RPCResult = 'YES');
1657 //CachedWPField.Add(SrchStr + RPCResult);
1658 end;
1659 end;
1660
1661 function TfrmPtDemoEdit.ExtractNum (S : String; StartPos : integer) : string;
1662 var i : integer;
1663 ch : char;
1664 begin
1665 result := '';
1666 if (S = '') or (StartPos < 0) then exit;
1667 i := StartPos;
1668 repeat
1669 ch := S[i];
1670 i := i + 1;
1671 if ch in ['0'..'9','.'] then begin
1672 Result := Result + ch;
1673 end;
1674 until (i > length(S)) or not (ch in ['0'..'9','.'])
1675 end;
1676
1677 procedure TfrmPtDemoEdit.gridPatientDemoSelectCell(Sender: TObject; ACol,
1678 ARow: Integer; var CanSelect: Boolean);
1679 (*
1680 For Field def, here is the legend
1681 character meaning
1682
1683 BC The data is Boolean Computed (true or false).
1684 C The data is Computed.
1685 Cm The data is multiline Computed.
1686 DC The data is Date-valued, Computed.
1687 D The data is Date-valued.
1688 F The data is Free text.
1689 I The data is uneditable.
1690 Pn The data is a Pointer reference to file "n".
1691 S The data is from a discrete Set of codes.
1692
1693 N The data is Numeric-valued.
1694
1695 Jn To specify a print length of n characters.
1696 Jn,d To specify printing n characters with decimals.
1697
1698 V The data is a Variable pointer.
1699 W The data is Word processing.
1700 WL The Word processing data is normally printed in Line mode (i.e., without word wrap).
1701 *)
1702 var oneEntry,FieldDef : string;
1703 date,time: string;
1704 FileNum,FieldNum,SubFileNum : string;
1705 GridFileNum : string;
1706 UserLine : integer;
1707 Grid : TSortStringGrid;
1708 IEN : int64;
1709 IENS : string;
1710 CurrentData : TStringList;
1711 GridInfo : TGridInfo;
1712 SubFileForm : TSubFileForm;
1713 begin
1714 if FLoadingGrid then exit; //prevent pseudo-clicks during loading...
1715 Grid := (Sender as TSortStringGrid);
1716 GridInfo := GetInfoForGrid(Grid);
1717 if GridInfo=nil then exit;
1718 GridFileNum := GridInfo.FileNum;
1719 CanSelect := false; //default to NOT selectable.
1720 CurrentData := GridInfo.Data;
1721 if CurrentData=nil then exit;
1722 if CurrentData.Count = 0 then exit;
1723 UserLine := GetUserLine(CurrentData,Grid,ARow);
1724 if UserLine = -1 then exit;
1725 oneEntry := CurrentData.Strings[UserLine];
1726 FieldDef := Piece(oneEntry,'^',6);
1727 if Pos('F',FieldDef)>0 then begin //Free text
1728 CanSelect := true;
1729 end else if IsSubFile(FieldDef,SubFileNum) then begin //Subfiles.
1730 FileNum := Piece(oneEntry,'^',1);
1731 FieldNum := Piece(oneEntry,'^',3);
1732 if IsWPField(FileNum,FieldNum) then begin
1733 IENS := Piece(oneEntry,'^',2);
1734 EditTextForm.PrepForm(FileNum,FieldNum,IENS);
1735 EditTextForm.ShowModal;
1736 end else begin
1737 //handle subfiles here
1738 IENS := '';
1739 if GridInfo.Message = MSG_SUB_FILE then begin //used message from subfile Grid
1740 IENS := GridInfo.IENS;
1741 end; // else if LastSelTreeNode <> nil then begin //this is one of the selction trees.
1742 IEN := strtoint(Patient.DFN); //longInt(LastSelTreeNode.Data);
1743 if IEN > 0 then IENS := InttoStr(IEN) + ',';
1744 if GridInfo.Data = CurrentAnyFileData then begin
1745 IEN := strtoint(patient.dfn); //get info from selected record
1746 if IEN > 0 then IENS := InttoStr(IEN) + ',';
1747 end;
1748 if IENS <> '' then begin
1749 SubFileForm := TSubFileForm.Create(self);
1750 SubFileForm.PrepForm(SubFileNum,IENS);
1751 SubfileForm.ShowModal; // note: may call this function again recursively for sub-sub-files etc.
1752 SubFileForm.Free;
1753 end else begin
1754 MessageDlg('IENS for File="". Can''t process.',mtInformation,[MBOK],0);
1755 end;
1756 end;
1757 end else if Pos('C',FieldDef)>0 then begin //computed fields.
1758 CanSelect := false;
1759 end else if Pos('D',FieldDef)>0 then begin //date field
1760 date := piece(Grid.Cells[ACol,ARow],'@',1);
1761 time := piece(Grid.Cells[ACol,ARow],'@',2);
1762 if date <> '' then begin
1763 SelDateTimeForm.DateTimePicker.Date := StrToDate(date);
1764 end else begin
1765 SelDateTimeForm.DateTimePicker.Date := SysUtils.Date;
1766 end;
1767 if SelDateTimeForm.ShowModal = mrOK then begin
1768 date := DateToStr(SelDateTimeForm.DateTimePicker.Date);
1769 time := TimeToStr(SelDateTimeForm.DateTimePicker.Time);
1770 if time <> '' then date := date; // + '@' + time; elh 8/15/08
1771 Grid.Cells[ACol,ARow] := date;
1772 end;
1773 CanSelect := true;
1774 end else if Pos('S',FieldDef)>0 then begin //Set of Codes
1775 SetSelForm.PrepForm(Piece(oneEntry,'^',7));
1776 if SetSelForm.ShowModal = mrOK then begin
1777 Grid.Cells[ACol,ARow] := SetSelForm.ComboBox.Text;
1778 CanSelect := true;
1779 end;
1780 end else if Pos('I',FieldDef)>0 then begin //uneditable
1781 ShowMessage('Sorry. Flagged as UNEDITABLE.');
1782 end else if Pos('P',FieldDef)>0 then begin //Pointer to file.
1783 FileNum := ExtractNum (FieldDef,Pos('P',FieldDef)+1);
1784 //check for validity here...
1785 FieldLookupForm.PrepForm(FileNum,Grid.Cells[ACol,ARow]);
1786 if FieldLookupForm.ShowModal = mrOK then begin
1787 Grid.Cells[ACol,ARow] := FieldLookupForm.ORComboBox.Text;
1788 CanSelect := true;
1789 end;
1790 end;
1791 if CanSelect then begin
1792 FLastSelectedRow := ARow;
1793 FLastSelectedCol := ACol;
1794 SetModified(True);
1795 end;
1796 //GridInfo.ApplyBtn.Enabled := true;
1797 //GridInfo.RevertBtn.Enabled := true;
1798 end;
1799
1800 function TfrmPtDemoEdit.GetLineInfo(Grid : TSortStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
1801 var fieldNum : string;
1802 oneEntry : string;
1803 fileNum : string;
1804 gridRow : integer;
1805 begin
1806 fieldNum := Grid.Cells[0,ARow];
1807 gridRow := FindInStrings(fieldNum, CurrentUserData, fileNum);
1808 if gridRow > -1 then begin
1809 oneEntry := CurrentUserData.Strings[gridRow];
1810 Result.Field := fieldNum;
1811 Result.FieldName := Grid.Cells[1,ARow];
1812 Result.FileNum := fileNum;
1813 Result.IENS := Piece(oneEntry,'^',2);
1814 Result.oldValue := Piece(oneEntry,'^',4);
1815 Result.newValue := Grid.Cells[2,ARow];
1816 end else begin
1817 Result.Field := '';
1818 Result.FieldName := '';
1819 Result.FileNum := '';
1820 Result.IENS := '';
1821 Result.oldValue := '';
1822 Result.newValue := '';
1823 end;
1824 end;
1825
1826procedure TfrmPtDemoEdit.GetOneRecord(FileNum, IENS : string; Data, BlankFileInfo: TStringList);
1827 var cmd,RPCResult : string;
1828 i : integer;
1829 oneEntry : string;
1830 begin
1831 Data.Clear;
1832 if (IENS='') then exit;
1833 if Pos('+',IENS)=0 then begin //don't ask server to load +1 records.
1834 RPCBrokerV.remoteprocedure := 'TMG CHANNEL';
1835 RPCBrokerV.Param[0].Value := '.X'; // not used
1836 RPCBrokerV.param[0].ptype := list;
1837 cmd := 'GET ONE RECORD^' + FileNum + '^' + IENS;
1838 RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
1839 //RPCBrokerV.Call;
1840 CallBroker;
1841 RPCResult := RPCBrokerV.Results[0]; //returns: error: -1; success=1
1842 if piece(RPCResult,'^',1)='-1' then begin
1843 FMErrorForm.Memo.Lines.Assign(RPCBrokerV.Results);
1844 FMErrorForm.PrepMessage;
1845 FMErrorForm.ShowModal;
1846 end else begin
1847 Data.Assign(RPCBrokerV.Results);
1848 end;
1849 end else begin
1850 Data.Add('1^Success'); //to keep same as call to server
1851 if BlankFileInfo.Count = 0 then begin
1852 //Format is: FileNum^^FieldNum^^DDInfo...
1853 // elh GetBlankFileInfo(FileNum,BlankFileInfo);
1854 end;
1855 for i := 1 to BlankFileInfo.Count-1 do begin //0 is 1^success
1856 oneEntry := BlankFileInfo.Strings[i];
1857 // elh SetPiece(oneEntry,'^',2,IENS);
1858 Data.Add(oneEntry);
1859 end;
1860 end;
1861 end;
1862
1863function TfrmPtDemoEdit.GetUserLine(CurrentUserData : TStringList; Grid : TSortStringGrid; ARow: integer) : integer;
1864 var fieldNum: string;
1865 tempFileNum : string;
1866 begin
1867 fieldNum := Grid.Cells[0,ARow];
1868 Result := FindInStrings(fieldNum,CurrentUserData,tempFileNum);
1869 end;
1870
1871 function TfrmPtDemoEdit.FindInStrings(fieldNum : string; Strings : TStringList; var fileNum : string) : integer;
1872 //Note: if fileNum is passed blank, then first matching file will be placed in it (i.e. OUT parameter)
1873 var tempFieldNum : string;
1874 oneEntry,tempFile : string;
1875 i : integer;
1876 begin
1877 result := -1;
1878 fileNum := '';
1879 for i := 1 to Strings.Count-1 do begin //0 --> 1^success
1880 oneEntry := Strings.Strings[i];
1881 tempFile := Piece(oneEntry,'^',1);
1882 if fileNum='' then fileNum := tempFile;
1883 if tempFile <> fileNum then continue; //ignore subfiles
1884 tempFieldNum := Piece(oneEntry,'^',3);
1885 if tempFieldNum <> fieldNum then continue;
1886 Result := i;
1887 break;
1888 end;
1889 end;
1890
1891 procedure TfrmPtDemoEdit.AddGridInfo(Grid: TSortStringGrid;
1892 Data : TStringList;
1893 BasicMode : boolean;
1894 DataLoader : TGridDataLoader;
1895 FileNum : string);
1896 var tempGridInfo : TGridInfo;
1897 begin
1898 tempGridInfo := TGridInfo.Create;
1899 tempGridInfo.Grid := Grid;
1900 tempGridInfo.Data := Data;
1901 tempGridInfo.BasicMode := BasicMode;
1902 tempGridInfo.FileNum := FileNum;
1903 tempGridInfo.DataLoadProc := DataLoader;
1904 //tempGridInfo.ApplyBtn := ApplyBtn;
1905 //tempGridInfo.RevertBtn := RevertBtn;
1906 RegisterGridInfo(tempGridInfo);
1907 end;
1908
1909procedure TfrmPtDemoEdit.RegisterGridInfo(GridInfo : TGridInfo);
1910 var s : string;
1911 begin
1912 if GridInfo = nil then exit;
1913 s := IntToStr(integer(GridInfo.Grid));
1914 DataForGrid.AddObject(s,GridInfo);
1915 end;
1916
1917procedure TfrmPtDemoEdit.gridPatientDemoSetEditText(Sender: TObject; ACol,
1918 ARow: Integer; const Value: String);
1919begin
1920 SetModified(True);
1921end;
1922
1923procedure TfrmPtDemoEdit.PageControlChanging(Sender: TObject;
1924 var AllowChange: Boolean);
1925var
1926 intAnswer : Integer;
1927begin
1928//Before changing the form, find out if changes need to be applied and
1929//prompt user. elh
1930 if ApplyBtn.enabled = True then begin
1931 intAnswer := messagedlg('Do you want to apply your changes?', mtWarning,mbYesNoCancel,0);
1932 if intAnswer = mrYes then begin //Yes
1933 ApplyBtnClick(Sender);
1934 //messagedlg('Changes Saved.', mtWarning,[mbOK],0);
1935 SetModified(False);
1936 end else if intAnswer = mrNo then begin //No
1937 SetModified(False);
1938 end else if intAnswer = mrCancel then begin //Cancel
1939 AllowChange := False;
1940 end;
1941 end;
1942end;
1943end.
Note: See TracBrowser for help on using the repository browser.