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

Last change on this file since 654 was 541, checked in by Kevin Toppenberg, 15 years ago

TMG Ver 1.1 Added HTML Support, better demographics editing

File size: 66.8 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;
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 : TStringGrid; //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: TStringGrid;
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: TStringGrid;
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 : TStringGrid) : TModalResult;
231 procedure CompileChanges(Grid : TStringGrid; CurrentUserData,Changes : TStringList);
232 procedure RegisterGridInfo(GridInfo : TGridInfo);
233 public
234 { Public declarations }
235 function GetInfoForGrid(Grid : TStringGrid) : TGridInfo;
236 procedure LoadAnyGrid(Grid : TStringGrid; 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 : TStringGrid) : integer;
243 function PostVisibleGrid: TModalResult;
244 function GetLineInfo(Grid : TStringGrid; 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 : TStringGrid; 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
596 with FServerPatientInfo do begin
597 //Store results in a hash table for easier random access
598 //Don't store Alias info in hash table, put directly into AliasInfo stringlist
599 for i := 0 to RPCBrokerV.Results.Count-1 do begin
600 s := RPCBrokerV.Results.Strings[i];
601 if Pos('ALIAS',s)=0 then begin
602 Key := piece(s,'=',1);
603 Value := piece(s,'=',2);
604 tempINI.WriteString('DATA',Key,Value);
605 end else begin
606 IEN := piece(s,' ',2);
607 if StrToInt(IEN)>MaxAliasIEN then MaxAliasIEN := StrToInt(IEN);
608 index := AliasInfo.IndexOf(IEN);
609 if index <0 then begin
610 pAlias := tAlias.Create; //AliasInfo will own these.
611 AliasInfo.AddObject(IEN,pAlias);
612 end else begin
613 pAlias := tAlias(AliasInfo.Objects[index]);
614 end;
615 if Pos('NAME=',s)>0 then begin
616 pAlias.Name := piece(s,'=',2);
617 end else if Pos('SSN=',s)>0 then begin
618 pAlias.SSN := piece(s,'=',2);
619 end;
620 end;
621 end;
622 LName:=tempINI.ReadString('DATA','LNAME','');
623 FName:=tempINI.ReadString('DATA','FNAME','');
624 MName:=tempINI.ReadString('DATA','MNAME','');
625 CombinedName:=tempINI.ReadString('DATA','COMBINED_NAME','');
626 Prefix:=tempINI.ReadString('DATA','PREFIX','');
627 Suffix:=tempINI.ReadString('DATA','SUFFIX','');
628 Degree:=tempINI.ReadString('DATA','DEGREE','');
629 DOB:= tempINI.ReadString('DATA','DOB','');
630 Sex:= tempINI.ReadString('DATA','SEX','');
631 SSNum:= tempINI.ReadString('DATA','SS_NUM','');
632 EMail:= tempINI.ReadString('DATA','EMAIL','');
633 AddressLine1:= tempINI.ReadString('DATA','ADDRESS_LINE_1','');
634 AddressLine2:= tempINI.ReadString('DATA','ADDRESS_LINE_2','');
635 AddressLine3:= tempINI.ReadString('DATA','ADDRESS_LINE_3','');
636 City:= tempINI.ReadString('DATA','CITY','');
637 State:= tempINI.ReadString('DATA','STATE','');
638 Zip4:= tempINI.ReadString('DATA','ZIP4','');
639 BadAddress:= BoolUC(tempINI.ReadString('DATA','BAD_ADDRESS','')<>'');
640 TempAddressLine1:= tempINI.ReadString('DATA','TEMP_ADDRESS_LINE_1','');
641 TempAddressLine2:= tempINI.ReadString('DATA','TEMP_ADDRESS_LINE_2','');
642 TempAddressLine3:= tempINI.ReadString('DATA','TEMP_ADDRESS_LINE_3','');
643 TempCity:= tempINI.ReadString('DATA','TEMP_CITY','');
644 TempState:=tempINI.ReadString('DATA','TEMP_STATE','');
645 TempZip4:= tempINI.ReadString('DATA','TEMP_ZIP4','');
646 TempStartingDate :=tempINI.ReadString('DATA','TEMP_STARTING_DATE','');
647 TempEndingDate := tempINI.ReadString('DATA','TEMP_ENDING_DATE','');
648 TempAddressActive:= BoolUC(tempINI.ReadString('DATA','TEMP_ADDRESS_ACTIVE','')='YES');
649 ConfidentalAddressLine1:= tempINI.ReadString('DATA','CONF_ADDRESS_LINE_1','');
650 ConfidentalAddressLine2:= tempINI.ReadString('DATA','CONF_ADDRESS_LINE_2','');
651 ConfidentalAddressLine3:= tempINI.ReadString('DATA','CONF_ADDRESS_LINE_3','');
652 ConfidentalCity:= tempINI.ReadString('DATA','CONF_CITY','');
653 ConfidentalState:= tempINI.ReadString('DATA','CONF_STATE','');
654 ConfidentalZip:= tempINI.ReadString('DATA','CONF_ZIP','');
655 ConfidentalStartingDate := tempINI.ReadString('DATA','CONG_STARTING_DATE','');
656 ConfidentalEndingDate := tempINI.ReadString('DATA','CONF_ENDING_DATE','');
657 ConfAddressActive:= BoolUC(tempINI.ReadString('DATA','CONF_ADDRESS_ACTIVE','')='YES');
658 PhoneNumResidence:= tempINI.ReadString('DATA','PHONE_RESIDENCE','');
659 PhoneNumWork:= tempINI.ReadString('DATA','PHONE_WORK','');
660 PhoneNumCell:= tempINI.ReadString('DATA','PHONE_CELL','');
661 PhoneNumTemp:= tempINI.ReadString('DATA','PHONE_TEMP','');
662 end;
663 FCurPatientInfo.Assign(FServerPatientInfo);
664 tempINI.Free; //I don't write out, so should never end up on disk.
665end;
666
667procedure TfrmPtDemoEdit.PostChangedInfo(PatientInfo : TPatientInfo);
668
669 procedure CheckBUCPost(Title : string; Value : BoolUC);
670 begin
671 if Value <> bucUnchanged then begin
672 if Value = bucTrue then RPCBrokerV.Param[1].Mult['"'+Title+'"'] := 'YES';
673 if Value = bucFalse then RPCBrokerV.Param[1].Mult['"'+Title+'"'] := 'NO';
674 end;
675 end;
676
677 procedure CheckPost(Title, Value : string);
678 begin
679 if Value <> '' then RPCBrokerV.Param[1].Mult['"'+Title+'"'] := Value;
680 end;
681
682 var i : integer;
683 pAlias : tAlias;
684begin
685 RPCBrokerV.remoteprocedure := 'TMG SET PATIENT DEMOGRAPHICS';
686 RPCBrokerV.param[0].value := Patient.DFN; RPCBrokerV.param[0].ptype := literal;
687
688 RPCBrokerV.Param[1].PType := list;
689 with PatientInfo do begin
690 CheckPost('COMBINED_NAME',CombinedName);
691 //CheckPost('LNAME', LName); //Don't send because data is in COMBINED NAME
692 //CheckPost('FNAME',FName);
693 //CheckPost('MNAME',MName);
694 //CheckPost('PREFIX',Prefix);
695 //CheckPost('SUFFIX',Suffix);
696 //CheckPost('DEGREE',Degree);
697 CheckPost('DOB',DOB);
698 CheckPost('SEX',Sex);
699 CheckPost('SS_NUM',SSNum);
700 CheckPost('EMAIL',EMail);
701 CheckPost('ADDRESS_LINE_1',AddressLine1);
702 CheckPost('ADDRESS_LINE_2',AddressLine2);
703 CheckPost('ADDRESS_LINE_3',AddressLine3);
704 CheckPost('CITY',City);
705 CheckPost('STATE',State);
706 CheckPost('ZIP4',Zip4);
707
708 CheckPost('TEMP_ADDRESS_LINE_1',TempAddressLine1);
709 CheckPost('TEMP_ADDRESS_LINE_2',TempAddressLine2);
710 CheckPost('TEMP_ADDRESS_LINE_3',TempAddressLine3);
711 CheckPost('TEMP_CITY',TempCity);
712 CheckPost('TEMP_STATE',TempState);
713 CheckPost('TEMP_ZIP4',TempZip4);
714 CheckPost('TEMP_STARTING_DATE',TempStartingDate );
715 CheckPost('TEMP_ENDING_DATE',TempEndingDate );
716 CheckPost('CONF_ADDRESS_LINE_1',ConfidentalAddressLine1);
717 CheckPost('CONF_ADDRESS_LINE_2',ConfidentalAddressLine2);
718 CheckPost('CONF_ADDRESS_LINE_3',ConfidentalAddressLine3);
719 CheckPost('CONF_CITY',ConfidentalCity);
720 CheckPost('CONF_STATE',ConfidentalState);
721 CheckPost('CONF_ZIP',ConfidentalZip);
722 CheckPost('CONG_STARTING_DATE',ConfidentalStartingDate );
723 CheckPost('CONF_ENDING_DATE',ConfidentalEndingDate );
724 CheckPost('PHONE_RESIDENCE',PhoneNumResidence);
725 CheckPost('PHONE_WORK',PhoneNumWork);
726 CheckPost('PHONE_CELL',PhoneNumCell);
727 CheckPost('PHONE_TEMP',PhoneNumTemp);
728
729 case BadAddress of
730 bucTrue: RPCBrokerV.Param[1].Mult['"BAD_ADDRESS"'] := 'UNDELIVERABLE';
731 bucFalse: RPCBrokerV.Param[1].Mult['"BAD_ADDRESS"'] := '@';
732 end; {case}
733 CheckBUCPost('TEMP_ADDRESS_ACTIVE', TempAddressActive);
734 CheckBUCPost('CONF_ADDRESS_ACTIVE', ConfAddressActive);
735
736 for i := 0 to AliasInfo.Count-1 do begin
737 pAlias := tAlias(AliasInfo.Objects[i]);
738 if (pAlias=nil) then continue;
739 RPCBrokerV.Param[1].Mult['"ALIAS ' + AliasInfo.Strings[i] + ' NAME"'] := pAlias.Name;
740 if pAlias.Name <> '@' then begin
741 RPCBrokerV.Param[1].Mult['"ALIAS ' + AliasInfo.Strings[i] + ' SSN"'] := pAlias.SSN;
742 end;
743 end;
744
745 RPCBrokerV.Call;
746 if RPCBrokerV.Results.Strings[0]<>'1' then begin
747 MessageDlg(RPCBrokerV.Results.Strings[0],mtError,[mbOK],0);
748 end else begin
749 ChangesMade := true;
750 end;
751 end;
752end;
753
754
755procedure TfrmPtDemoEdit.ShowPtInfo(Patient : TPatientInfo);
756var i : integer;
757 pAlias : tAlias;
758begin
759 ProgNameChangeOccuring := true;
760 With Patient do begin
761 LNameEdit.Text := LName;
762 FNameEdit.Text := FName;
763 MNameEdit.Text := MName;
764 CombinedNameEdit.Text := CombinedName;
765 PrefixEdit.Text := Prefix;
766 SuffixEdit.Text := Suffix;
767 DegreeEdit.Text := Degree;
768 DOBEdit.Text := DOB;
769 SSNumEdit.Text := SSNum;
770 EMailEdit.Text := EMail;
771 if Sex='MALE' then SexComboBox.ItemIndex := 0 else SexComboBox.ItemIndex := 1;
772 AliasComboBox.Items.Clear;
773 for i := 0 to AliasInfo.Count-1 do begin
774 pAlias := tAlias(AliasInfo.Objects[i]);
775 if pAlias<>nil then begin
776 AliasComboBox.Items.AddObject(pAlias.Name,pAlias);
777 end;
778 end;
779 if AliasComboBox.Items.count>0 then begin
780 AliasComboBox.ItemIndex := 0;
781 SetAliasEnabled(true);
782 end;
783 ShowAliasInfo(Patient);
784
785 PhoneNumGrp.ItemIndex := 0;
786 PhoneNumGrpClick(self);
787 end;
788
789 BadAddressCB.Visible := false;
790 TempActiveCB.Visible := false;
791 ProgNameChangeOccuring := false;
792end;
793
794procedure TfrmPtDemoEdit.ShowAliasInfo(Patient : TPatientInfo);
795var i : integer;
796 pAlias : tAlias;
797begin
798 i := AliasComboBox.ItemIndex;
799 if i > -1 then begin
800 if i < Patient.AliasInfo.Count then begin
801 pAlias := tAlias(Patient.AliasInfo.Objects[i]);
802 end else pAlias := nil;
803 ProgAliasChangeOccuring := true;
804 if pAlias<>nil then begin
805 AliasNameEdit.Text := pAlias.Name;
806 AliasSSNEdit.Text := pAlias.SSN;
807 end else begin
808 AliasNameEdit.Text := '';
809 AliasSSNEdit.Text := '';
810 end;
811 ProgAliasChangeOccuring := false;
812 end;
813end;
814
815
816procedure TfrmPtDemoEdit.AliasComboBoxChange(Sender: TObject);
817var s : string;
818 i : integer;
819begin
820 if ProgAliasChangeOccuring=false then begin
821 i := AliasCombobox.ItemIndex;
822 if i>-1 then begin
823 s := AliasCombobox.Items.Strings[i];
824 SetAliasEnabled(true);
825 end else begin
826 SetAliasEnabled(false);
827 end;
828 ShowAliasInfo(FCurPatientInfo);
829 end;
830end;
831
832procedure TfrmPtDemoEdit.FormCreate(Sender: TObject);
833begin
834 FCurAliasEdit := -1;
835 FCurPatientInfo := TPatientInfo.Create;
836 FServerPatientInfo := TPatientInfo.Create;
837 DataForGrid := TStringList.Create; //will own GridInfo objects.
838 ProgAliasChangeOccuring := false;
839 ProgNameChangeOccuring := false;
840 ProgPhoneChangeOccuring := false;
841 ProgAddressChangeOccuring := false;
842 MaxAliasIEN := 0;
843 ChangesMade := false;
844 CurrentPatientData := TStringList.Create;
845 AddGridInfo(GridPatientDemo,CurrentPatientData,false,GetPatientInfo,'2');
846
847end;
848
849procedure TfrmPtDemoEdit.FormDestroy(Sender: TObject);
850begin
851 DataForGrid.Free;
852 FCurPatientInfo.Destroy;
853 FServerPatientInfo.Destroy;
854 CurrentPatientData.Free;
855end;
856
857
858procedure TfrmPtDemoEdit.AddressRGrpClick(Sender: TObject);
859begin
860 {fill in data for newly selected fields}
861 ProgAddressChangeOccuring := true;
862 TempActiveCB.Visible := false;
863 BadAddressCB.Visible := false;
864 ConfActiveCB.Visible := false;
865 StartingDateLabel.Visible := false;
866 StartingDateEdit.Visible := false;
867 EndingDateLabel.Visible := false;
868 EndingDateEdit.Visible := false;
869 case AddressRGrp.ItemIndex of
870 0 : begin //Permanant
871 AddressLine1Edit.Text := FCurPatientInfo.AddressLine1;
872 AddressLine2Edit.Text := FCurPatientInfo.AddressLine2;
873 AddressLine3Edit.text := FCurPatientInfo.AddressLine3;
874 CityEdit.text := FCurPatientInfo.City;
875 StateComboBox.text := FCurPatientInfo.State;
876 Zip4Edit.text := FCurPatientInfo.Zip4;
877 BadAddressCB.Visible := true;
878 BadAddressCB.Checked := (FCurPatientInfo.BadAddress=bucTrue);
879 end;
880 1 : begin //temp
881 AddressLine1Edit.Text := FCurPatientInfo.TempAddressLine1;
882 AddressLine2Edit.Text := FCurPatientInfo.TempAddressLine2;
883 AddressLine3Edit.Text := FCurPatientInfo.TempAddressLine3;
884 CityEdit.Text := FCurPatientInfo.TempCity;
885 StateComboBox.Text := FCurPatientInfo.TempState;
886 Zip4Edit.Text := FCurPatientInfo.TempZip4;
887 StartingDateEdit.Text := FCurPatientInfo.TempStartingDate ;
888 EndingDateEdit.Text := FCurPatientInfo.TempEndingDate ;
889 StartingDateLabel.Visible := true;
890 StartingDateEdit.Visible := true;
891 EndingDateLabel.Visible := true;
892 EndingDateEdit.Visible := true;
893 TempActiveCB.Visible := true;
894 TempActiveCB.Checked := (FCurPatientInfo.TempAddressActive=bucTrue);
895 end;
896 2 : begin //confidental
897 AddressLine1Edit.Text := FCurPatientInfo.ConfidentalAddressLine1;
898 AddressLine2Edit.Text := FCurPatientInfo.ConfidentalAddressLine2;
899 AddressLine3Edit.Text := FCurPatientInfo.ConfidentalAddressLine3;
900 CityEdit.Text := FCurPatientInfo.ConfidentalCity;
901 StateComboBox.Text := FCurPatientInfo.ConfidentalState;
902 Zip4Edit.Text := FCurPatientInfo.ConfidentalZip;
903 StartingDateEdit.Text := FCurPatientInfo.ConfidentalStartingDate ;
904 EndingDateEdit.Text := FCurPatientInfo.ConfidentalEndingDate ;
905 StartingDateLabel.Visible := true;
906 StartingDateEdit.Visible := true;
907 EndingDateLabel.Visible := true;
908 EndingDateEdit.Visible := true;
909 ConfActiveCB.Visible := true;
910 ConfActiveCB.Checked := (FCurPatientInfo.ConfAddressActive=bucTrue);
911 end;
912 end; {case}
913 ProgAddressChangeOccuring := false;
914end;
915
916procedure TfrmPtDemoEdit.PhoneNumGrpClick(Sender: TObject);
917begin
918 ProgPhoneChangeOccuring := true;
919 case PhoneNumGrp.ItemIndex of
920 0 : begin //Residence
921 PhoneNumEdit.Text := FCurPatientInfo.PhoneNumResidence;
922 end;
923 1 : begin //work
924 PhoneNumEdit.Text := FCurPatientInfo.PhoneNumWork;
925 end;
926 2 : begin //cell
927 PhoneNumEdit.Text := FCurPatientInfo.PhoneNumCell;
928 end;
929 3 : begin //temp
930 PhoneNumEdit.Text := FCurPatientInfo.PhoneNumTemp;
931 end;
932 else begin
933 PhoneNumEdit.Text := '';
934 end;
935 end; {case}
936 ProgPhoneChangeOccuring := false;
937end;
938
939procedure TfrmPtDemoEdit.DelAliasBtnClick(Sender: TObject);
940var i, j : integer;
941 pAlias : tAlias;
942begin
943 i := AliasComboBox.ItemIndex;
944 if i > -1 then begin
945 pAlias := tAlias(AliasComboBox.Items.Objects[i]);
946 if pAlias<>nil then begin
947 for j := 0 to FCurPatientInfo.AliasInfo.Count-1 do begin
948 if FCurPatientInfo.AliasInfo.Objects[j] = pAlias then begin
949 FCurPatientInfo.AliasInfo.Delete(j);
950 SetModified(true);
951 pAlias.Free;
952 AliasComboBox.Items.Delete(i);
953 //AliasComboBox.ItemIndex := 0;
954 //ShowAliasInfo(FCurPatientInfo);
955 ProgAliasChangeOccuring:= true;
956 AliasNameEdit.Text:='';
957 AliasSSNEdit.Text:='';
958 ProgAliasChangeOccuring:= false;
959 break;
960 end;
961 end;
962 end;
963 end;
964 if AliasCombobox.Items.Count=0 then begin
965 AliasNameEdit.Text:='';
966 AliasSSNEdit.Text:='';
967 SetAliasEnabled(false);
968 AliasCombobox.Text := '';
969 end;
970end;
971
972procedure TfrmPtDemoEdit.FormShow(Sender: TObject);
973begin
974 PageControl.ActivePageIndex := 0;
975 GetPtInfo(FServerPatientInfo);
976 FCurPatientInfo.Assign(FServerPatientInfo);
977 ShowPtInfo(FCurPatientInfo);
978end;
979
980procedure TfrmPtDemoEdit.CombinedNameEditChange(Sender: TObject);
981var LName,FName,MName : string;
982begin
983 if ProgNameChangeOccuring = false then begin
984 FCurPatientInfo.CombinedName := CombinedNameEdit.Text;
985 SetModified(true);
986 if CombinedNameEdit.Text <> CombinedName then begin
987 ProgNameChangeOccuring := true;
988 NameParts(CombinedNameEdit.Text, LName, FName, MName);
989 LNameEdit.Text := LName;
990 FNameEdit.Text := FName;
991 MNameEdit.Text := MName;
992 ProgNameChangeOccuring := false;
993 end;
994 end;
995end;
996
997procedure TfrmPtDemoEdit.LNameEditChange(Sender: TObject);
998begin
999 if ProgNameChangeOccuring = false then begin
1000 FCurPatientInfo.LName := LNameEdit.Text;
1001 SetModified(true);
1002 CombinedNameEdit.Text := CombinedName;
1003 end;
1004end;
1005
1006procedure TfrmPtDemoEdit.FNameEditChange(Sender: TObject);
1007begin
1008 if ProgNameChangeOccuring = false then begin
1009 FCurPatientInfo.FName := FNameEdit.Text;
1010 SetModified(true);
1011 CombinedNameEdit.Text := CombinedName;
1012 end
1013end;
1014
1015procedure TfrmPtDemoEdit.MNameEditChange(Sender: TObject);
1016begin
1017 if ProgNameChangeOccuring = false then begin
1018 FCurPatientInfo.MName := MNameEdit.Text;
1019 SetModified(true);
1020 CombinedNameEdit.Text := CombinedName;
1021 end;
1022end;
1023
1024procedure TfrmPtDemoEdit.PrefixEditChange(Sender: TObject);
1025begin
1026 if ProgNameChangeOccuring = false then begin
1027 FCurPatientInfo.Prefix := PrefixEdit.Text;
1028 SetModified(true);
1029 end;
1030end;
1031
1032procedure TfrmPtDemoEdit.SuffixEditChange(Sender: TObject);
1033begin
1034 if ProgNameChangeOccuring = false then begin
1035 FCurPatientInfo.Suffix := SuffixEdit.Text;
1036 SetModified(true);
1037 CombinedNameEdit.Text := CombinedName;
1038 end;
1039end;
1040
1041procedure TfrmPtDemoEdit.DOBEditChange(Sender: TObject);
1042begin
1043 if ProgNameChangeOccuring = false then begin
1044 FCurPatientInfo.DOB := DOBEdit.Text;
1045 SetModified(true);
1046 end;
1047end;
1048
1049procedure TfrmPtDemoEdit.SSNumEditChange(Sender: TObject);
1050begin
1051 if ProgNameChangeOccuring = false then begin
1052 FCurPatientInfo.SSNum := SSNumEdit.Text;
1053 SetModified(true);
1054 end;
1055end;
1056
1057procedure TfrmPtDemoEdit.EMailEditChange(Sender: TObject);
1058begin
1059 if ProgNameChangeOccuring = false then begin
1060 FCurPatientInfo.EMail := EMailEdit.Text;
1061 SetModified(true);
1062 end;
1063end;
1064
1065procedure TfrmPtDemoEdit.SexComboBoxChange(Sender: TObject);
1066begin
1067 if ProgNameChangeOccuring = false then begin
1068 FCurPatientInfo.Sex := SexComboBox.Text;
1069 SetModified(true);
1070 end;
1071end;
1072
1073procedure TfrmPtDemoEdit.DegreeEditChange(Sender: TObject);
1074begin
1075 if ProgNameChangeOccuring = false then begin
1076 FCurPatientInfo.Degree := DegreeEdit.Text;
1077 SetModified(true);
1078 end;
1079end;
1080
1081procedure TfrmPtDemoEdit.AddressLine1EditChange(Sender: TObject);
1082begin
1083 if ProgAddressChangeOccuring = false then SetModified(true);
1084 Case AddressRGrp.ItemIndex of
1085 0 : FCurPatientInfo.AddressLine1 := AddressLine1Edit.Text;
1086 1 : FCurPatientInfo.TempAddressLine1 := AddressLine1Edit.Text;
1087 2 : FCurPatientInfo.ConfidentalAddressLine1 := AddressLine1Edit.Text;
1088 end; {case}
1089end;
1090
1091procedure TfrmPtDemoEdit.AddressLine2EditChange(Sender: TObject);
1092begin
1093 if ProgAddressChangeOccuring = false then SetModified(true);
1094 Case AddressRGrp.ItemIndex of
1095 0 : FCurPatientInfo.AddressLine2 := AddressLine2Edit.Text;
1096 1 : FCurPatientInfo.TempAddressLine2 := AddressLine2Edit.Text;
1097 2 : FCurPatientInfo.ConfidentalAddressLine2 := AddressLine2Edit.Text;
1098 end; {case}
1099end;
1100
1101procedure TfrmPtDemoEdit.AddressLine3EditChange(Sender: TObject);
1102begin
1103 if ProgAddressChangeOccuring = false then SetModified(true);
1104 Case AddressRGrp.ItemIndex of
1105 0 : FCurPatientInfo.AddressLine3 := AddressLine3Edit.Text;
1106 1 : FCurPatientInfo.TempAddressLine3 := AddressLine3Edit.Text;
1107 2 : FCurPatientInfo.ConfidentalAddressLine3 := AddressLine3Edit.Text;
1108 end; {case}
1109end;
1110
1111procedure TfrmPtDemoEdit.CityEditChange(Sender: TObject);
1112begin
1113 if ProgAddressChangeOccuring = false then SetModified(true);
1114 Case AddressRGrp.ItemIndex of
1115 0 : FCurPatientInfo.City := CityEdit.Text;
1116 1 : FCurPatientInfo.TempCity := CityEdit.Text;
1117 2 : FCurPatientInfo.ConfidentalCity := CityEdit.Text;
1118 end; {case}
1119end;
1120
1121procedure TfrmPtDemoEdit.Zip4EditChange(Sender: TObject);
1122begin
1123 if ProgAddressChangeOccuring = false then SetModified(true);
1124 Case AddressRGrp.ItemIndex of
1125 0 : FCurPatientInfo.Zip4 := Zip4Edit.Text;
1126 1 : FCurPatientInfo.TempZip4 := Zip4Edit.Text;
1127 2 : FCurPatientInfo.ConfidentalZip := leftstr(Zip4Edit.Text,5);
1128 end; {case}
1129end;
1130
1131procedure TfrmPtDemoEdit.StateComboBoxChange(Sender: TObject);
1132begin
1133 if ProgAddressChangeOccuring = false then SetModified(true);
1134 Case AddressRGrp.ItemIndex of
1135 0 : FCurPatientInfo.State := StateComboBox.Text;
1136 1 : FCurPatientInfo.TempState := StateComboBox.Text;
1137 2 : FCurPatientInfo.ConfidentalState := StateComboBox.Text;
1138 end; {case}
1139end;
1140
1141procedure TfrmPtDemoEdit.TempActiveCBClick(Sender: TObject);
1142begin
1143 FCurPatientInfo.TempAddressActive := BoolUC(TempActiveCB.Checked);
1144 if ProgAddressChangeOccuring = false then SetModified(true);
1145end;
1146
1147procedure TfrmPtDemoEdit.ConfActiveCBClick(Sender: TObject);
1148begin
1149 FCurPatientInfo.ConfAddressActive := BoolUC(ConfActiveCB.Checked);
1150 if ProgAddressChangeOccuring = false then SetModified(true);
1151end;
1152
1153procedure TfrmPtDemoEdit.BadAddressCBClick(Sender: TObject);
1154begin
1155 FCurPatientInfo.BadAddress := BoolUC(BadAddressCB.Checked);
1156 if ProgAddressChangeOccuring = false then SetModified(true);
1157end;
1158
1159procedure TfrmPtDemoEdit.PhoneNumEditChange(Sender: TObject);
1160begin
1161 if ProgPhoneChangeOccuring = false then SetModified(true);
1162 Case PhoneNumGrp.ItemIndex of
1163 0 : FCurPatientInfo.PhoneNumResidence := PhoneNumEdit.Text;
1164 1 : FCurPatientInfo.PhoneNumWork := PhoneNumEdit.Text;
1165 2 : FCurPatientInfo.PhoneNumCell := PhoneNumEdit.Text;
1166 3 : FCurPatientInfo.PhoneNumTemp := PhoneNumEdit.Text;
1167 end; {case}
1168
1169end;
1170
1171procedure TfrmPtDemoEdit.StartingDateEditChange(Sender: TObject);
1172begin
1173 if ProgAddressChangeOccuring = false then SetModified(true);
1174 Case AddressRGrp.ItemIndex of
1175 1 : FCurPatientInfo.TempStartingDate := StartingDateEdit.Text;
1176 2 : FCurPatientInfo.ConfidentalStartingDate := StartingDateEdit.Text;
1177 end; {case}
1178end;
1179
1180procedure TfrmPtDemoEdit.EndingDateEditChange(Sender: TObject);
1181begin
1182 if ProgAddressChangeOccuring = false then SetModified(true);
1183 Case AddressRGrp.ItemIndex of
1184 1 : FCurPatientInfo.TempEndingDate := EndingDateEdit.Text;
1185 2 : FCurPatientInfo.ConfidentalEndingDate := EndingDateEdit.Text;
1186 end; {case}
1187end;
1188
1189procedure TfrmPtDemoEdit.AliasNameEditChange(Sender: TObject);
1190var i : integer;
1191 pAlias : tAlias;
1192 tempB : boolean;
1193begin
1194 if ProgAliasChangeOccuring=false then begin
1195 i := AliasComboBox.ItemIndex;
1196 if i > -1 then begin
1197 pAlias := tAlias(AliasComboBox.Items.Objects[i]);
1198 if pAlias<>nil then begin
1199 pAlias.Name := AliasNameEdit.Text;
1200 AliasComboBox.Items.Strings[i]:= AliasNameEdit.Text;
1201 AliasComboBox.Text := AliasNameEdit.Text;
1202 tempB := ProgAliasChangeOccuring;
1203 ProgAliasChangeOccuring:=true;
1204 AliasComboBox.ItemIndex := i;
1205 ProgAliasChangeOccuring:=tempB;
1206 SetModified(true);
1207 end;
1208 end;
1209 end;
1210end;
1211
1212
1213procedure TfrmPtDemoEdit.AliasSSNEditChange(Sender: TObject);
1214var i : integer;
1215 pAlias : tAlias;
1216begin
1217 if ProgAliasChangeOccuring=false then begin
1218 i := AliasComboBox.ItemIndex;
1219 if i > -1 then begin
1220 pAlias := tAlias(AliasComboBox.Items.Objects[i]);
1221 if pAlias<>nil then begin
1222 pAlias.SSN := AliasSSNEdit.Text;
1223 SetModified(true);
1224 end;
1225 end;
1226 end;
1227end;
1228
1229procedure TfrmPtDemoEdit.SetAliasEnabled(value : boolean);
1230begin
1231 AliasNameEdit.Enabled := value;
1232 AliasSSNEdit.Enabled := value;
1233 if value=true then begin
1234 AliasNameEdit.Color := clWindow;
1235 AliasSSNEdit.Color := clWindow;
1236 end else begin
1237 AliasNameEdit.Color := clInactiveBorder;
1238 AliasSSNEdit.Color := clInactiveBorder;
1239 end;
1240end;
1241
1242
1243function TfrmPtDemoEdit.CombinedName : string;
1244begin
1245 Result := '';
1246 Result := FNameEdit.Text;
1247 if MNameEdit.Text <> '' then Result := Result + ' ' + MNameEdit.Text;
1248 if SuffixEdit.Text <> '' then Result := Result + ' ' + SuffixEdit.Text;
1249 if Result <> '' then Result := ',' + Result;
1250 Result := LNameEdit.Text + Result;
1251end;
1252
1253procedure TfrmPtDemoEdit.NameParts(CombinedName: string; var LName, FName, MName : string);
1254var tempS : string;
1255begin
1256 LName := piece(CombinedName,',',1);
1257 tempS := piece(CombinedName,',',2);
1258 FName := piece(tempS,' ',1);
1259 MName := piece(tempS,' ',2,16);
1260end;
1261
1262
1263procedure TfrmPtDemoEdit.ApplyBtnClick(Sender: TObject);
1264var TempPatientInfo : tPatientInfo;
1265begin
1266if pagecontrol.ActivePageIndex = 0 then begin
1267 TempPatientInfo := tPatientInfo.Create;
1268 TempPatientInfo.Assign(FCurPatientInfo);
1269 TempPatientInfo.RemoveUnchanged(FServerPatientInfo);
1270 PostChangedInfo(TempPatientInfo);
1271 TempPatientInfo.Destroy;
1272 SetModified(false);
1273end else begin
1274 PostVisibleGrid;
1275 SetModified(false);
1276end;
1277end;
1278function TfrmPtDemoEdit.PostVisibleGrid: TModalResult;
1279 begin
1280 result := PostChanges(gridPatientDemo);
1281 end;
1282
1283function TfrmPtDemoEdit.PostChanges(Grid : TStringGrid) : TModalResult;
1284 //Results: mrNone -- no post done (not needed)
1285 // mrCancel -- user pressed cancel on confirmation screen.
1286 // mrNo -- signals posting error.
1287 var Changes : TStringList;
1288 PostResult : TModalResult;
1289 CurrentData : TStringList;
1290 GridInfo : TGridInfo;
1291 IENS : string;
1292 begin
1293 Result := mrNone; //default to No changes
1294 GridInfo := GetInfoForGrid(Grid);
1295 if GridInfo=nil then exit;
1296 CurrentData := GridInfo.Data;
1297 if CurrentData=nil then exit;
1298 if CurrentData.Count = 0 then exit;
1299 IENS := Patient.DFN;
1300 if IENS='' then exit;
1301 Changes := TStringList.Create;
1302 CompileChanges(Grid,CurrentData,Changes);
1303 if Changes.Count>0 then begin
1304 PostForm.PrepForm(Changes);
1305 PostResult := PostForm.ShowModal;
1306 if PostResult = mrOK then begin
1307 //if DisuserChanged(Changes) then begin //looks for change in file 200, field 4
1308 // InitializeUsersTreeView;
1309 //end else begin
1310 if Pos('+',IENS)>0 then begin
1311 GridInfo.IENS := PostForm.GetNewIENS(IENS);
1312 end;
1313 if assigned(GridInfo.DataLoadProc) then begin
1314 GridInfo.DataLoadProc(GridInfo);
1315 end;
1316 {
1317 if CurrentData = CurrentUserData then begin
1318 LoadUserData(IENS,CurrentData); //reload record from server.
1319 end else if CurrentData = CurrentSettingsData then begin
1320 GetSettingsInfo(GridInfo.FileNum, GridInfo.IENS, CurrentData);
1321 end else if CurrentData = CurrentPatientData then begin
1322 GetPatientInfo(GridInfo.IENS, CurrentData);
1323 end else if CurrentData = CurrentAnyFileData then begin
1324 GetAnyFileInfo(GridInfo.FileNum, GridInfo.IENS, CurrentData);
1325 end;
1326 }
1327 //end;
1328 end else if PostResult = mrNo then begin //mrNo is signal of post Error
1329 // show error...
1330 end;
1331 Result := PostResult;
1332 end else begin
1333 Result := mrNone;
1334 end;
1335 Changes.Free;
1336 end;
1337
1338 procedure TfrmPtDemoEdit.CompileChanges(Grid : TStringGrid; CurrentUserData,Changes : TStringList);
1339 //Output format:
1340 // FileNum^IENS^FieldNum^FieldName^newValue^oldValue
1341
1342 var row : integer;
1343 Entry : tFileEntry;
1344 oneEntry : string;
1345 begin
1346 for row := 1 to Grid.RowCount-1 do begin
1347 Entry := GetLineInfo(Grid,CurrentUserData, row);
1348 if Entry.oldValue <> Entry.newValue then begin
1349 if (Entry.newValue <> CLICK_FOR_SUBS) and
1350 (Entry.newValue <> COMPUTED_FIELD) and
1351 (Entry.newValue <> CLICK_TO_EDIT) then begin
1352 oneEntry := Entry.FileNum + '^' + Entry.IENS + '^' + Entry.Field + '^' + Entry.FieldName;
1353 oneEntry := oneEntry + '^' + Entry.newValue + '^' + Entry.oldValue;
1354 Changes.Add(oneEntry);
1355 end;
1356 end;
1357 end;
1358 end;
1359
1360procedure TfrmPtDemoEdit.SetModified(value : boolean);
1361begin
1362 FCurPatientInfo.Modified := value;
1363 ApplyBtn.Enabled := FCurPatientInfo.Modified;
1364end;
1365
1366procedure TfrmPtDemoEdit.AddAliasBtnClick(Sender: TObject);
1367var pAlias : tAlias;
1368 IEN : string;
1369begin
1370 pAlias := tAlias.Create;
1371 if FCurPatientInfo.AliasInfo.count>0 then begin
1372 IEN := FCurPatientInfo.AliasInfo.Strings[FCurPatientInfo.AliasInfo.count-1];
1373 end else begin
1374 IEN := IntToStr(MaxAliasIEN);
1375 end;
1376 MaxAliasIEN := StrToInt(IEN)+1;
1377 IEN := IntToStr(MaxAliasIEN);
1378 FCurPatientInfo.AliasInfo.AddObject(IEN,pAlias);
1379 SetModified(true);
1380 AliasCombobox.Items.AddObject('<Edit New Alias>',pAlias);
1381 //pAlias.Name := '<Edit New Alias>';
1382 //AliasCombobox.Items.Add(ADD_NEW_ALIAS);
1383 AliasCombobox.ItemIndex := AliasCombobox.Items.Count-1;
1384 SetAliasEnabled(true);
1385 ShowAliasInfo(FCurPatientInfo);
1386end;
1387
1388procedure TfrmPtDemoEdit.OKBtnClick(Sender: TObject);
1389begin
1390 if FCurPatientInfo.Modified = true then begin
1391 case MessageDlg('Apply Changes?',mtConfirmation,mbYesNoCancel,0) of
1392 mrYes : begin
1393 ApplyBtnClick(Sender);
1394 frmPtDemoEdit.ModalResult := mrOK; //closes form
1395 end;
1396 mrNo : begin
1397 if ChangesMade = false then frmPtDemoEdit.ModalResult := mrCancel // closes form, signal no need for refresh
1398 else frmPtDemoEdit.ModalResult := mrOK; // closes form.
1399 end;
1400 mrCancel : frmPtDemoEdit.ModalResult := mrNone; //do nothing
1401 end; {case}
1402 end else begin
1403 if ChangesMade = false then frmPtDemoEdit.ModalResult := mrCancel // closes form, signal no need for refresh
1404 else frmPtDemoEdit.ModalResult := mrOK; // closes form.
1405 end;
1406end;
1407
1408procedure TfrmPtDemoEdit.CancelBtnClick(Sender: TObject);
1409begin
1410 if FCurPatientInfo.Modified = true then begin
1411 case MessageDlg('Cancel Changes?',mtConfirmation,mbYesNoCancel,0) of
1412 mrYes : frmPtDemoEdit.ModalResult := mrCancel; //closes form
1413 mrNo : frmPtDemoEdit.ModalResult := mrNone; //do nothing
1414 mrCancel : frmPtDemoEdit.ModalResult := mrNone; //do nothing
1415 end; {case}
1416 end else begin
1417 frmPtDemoEdit.ModalResult := mrCancel; // closes form.
1418 end;
1419
1420end;
1421
1422
1423procedure TfrmPtDemoEdit.PageControlChange(Sender: TObject);
1424var
1425 GridInfo : TGridInfo;
1426 IEN : longInt;
1427 ModalResult : TModalResult;
1428
1429begin
1430 if pagecontrol.ActivePageIndex = 0 then begin
1431 GetPtInfo(FServerPatientInfo);
1432 FCurPatientInfo.Assign(FServerPatientInfo);
1433 ShowPtInfo(FCurPatientInfo);
1434 end else begin
1435 IEN := strtoint(patient.dfn); //get info from selected patient
1436 if IEN = 0 then exit;
1437 GridInfo := GetInfoForGrid(gridPatientDemo);
1438 if GridInfo = nil then exit;
1439 GridInfo.IENS := IntToStr(IEN)+',';
1440 GetPatientInfo(GridInfo);
1441 end;
1442
1443end;
1444
1445procedure TfrmPtDemoEdit.GetPatientInfo(GridInfo: TGridInfo);
1446
1447var cmd,RPCResult : string;
1448 IENS : String;
1449 grid : TStringGrid;
1450begin
1451// IENS := Patient.DFN;
1452 IENS := GridInfo.IENS;
1453// Data := GridInfo.Data;
1454 grid := GridInfo.Grid;
1455 grid.Cells[0,1] := '';
1456 grid.Cells[1,1] := '';
1457 grid.Cells[2,1] := '';
1458 grid.RowCount :=2;
1459 grid.Cursor := crHourGlass;
1460 if IENS <> '0,' then begin
1461 RPCBrokerV.remoteprocedure := 'TMG CHANNEL';
1462 RPCBrokerV.param[0].ptype := list;
1463 cmd := 'GET ONE RECORD^2^' + IENS;
1464 RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
1465 RPCBrokerV.Call;
1466 RPCResult := RPCBrokerV.Results[0]; //returns: error: -1; success=1
1467 //Results[1]='FileNum^IENS^FieldNum^ExtValue^FieldName^DDInfo...
1468 //Results[2]='FileNum^IENS^FieldNum^ExtValue^FieldName^DDInfo...
1469 if piece(RPCResult,'^',1)='-1' then begin
1470 messagedlg(RPCBrokerV.Results[1],mtError,mbOKCancel,0);
1471 //FMErrorForm.Memo.Lines.Assign(RPCBrokerV.Results);
1472 end else begin
1473 GridInfo.Data.Assign(RPCBrokerV.results);
1474 //LoadAnyGrid(grid,false,'2',IENS,Data);
1475 LoadAnyGridFromInfo(GridInfo);
1476 end;
1477 end;
1478 gridPatientDemo.Cursor := crDefault;
1479end;
1480
1481procedure TfrmPtDemoEdit.LoadAnyGrid(Grid : TStringGrid; //the TStringGrid to load
1482 BasicMode: boolean;
1483 FileNum : string;
1484 IENS : string;
1485 CurrentData : TStringList);
1486 var
1487 GridInfo : TGridInfo;
1488 begin
1489 GridInfo := TGridInfo.Create;
1490 //This stores load information into a GridInfo
1491 GridInfo.Grid := Grid;
1492 GridInfo.BasicMode := BasicMode;
1493 GridInfo.FileNum := FileNum;
1494 GridInfo.IENS := IENS;
1495 GridInfo.Data := CurrentData;
1496 LoadAnyGridFromInfo(GridInfo);
1497 GridInfo.Free;
1498 end;
1499
1500procedure TfrmPtDemoEdit.LoadAnyGridFromInfo(GridInfo : TGridInfo);
1501 //This assumes that GridInfo already has loaded info.
1502 var
1503 Grid : TStringGrid; //the TStringGrid to load
1504 BasicMode: boolean;
1505 FileNum : string;
1506 IENS : string;
1507 CurrentData : TStringList;
1508
1509 procedure LoadOneLine (Grid : TStringGrid; oneEntry : string; GridRow : integer);
1510 var
1511 tempFile,IENS : string;
1512 fieldNum,fieldName,fieldDef : string;
1513 subFileNum : string;
1514 value : string;
1515 begin
1516 tempFile := Piece(oneEntry,'^',1);
1517 if tempFile = FileNum then begin //handle subfiles later...
1518 IENS := Piece(oneEntry,'^',2);
1519 fieldNum := Piece(oneEntry,'^',3);
1520 value := Piece(oneEntry,'^',4);
1521 fieldName := Piece(oneEntry,'^',5);
1522 fieldDef := Piece(oneEntry,'^',6);
1523 Grid.RowCount := GridRow + 1;
1524 Grid.Cells[0,GridRow] := fieldNum;
1525 Grid.Cells[1,GridRow] := fieldName;
1526 if Pos('W',fieldDef)>0 then begin
1527 Grid.Cells[2,GridRow] := CLICK_TO_EDIT;
1528 end else if IsSubFile(fieldDef, subFileNum) then begin
1529 if IsWPField(FileNum,fieldNum) then begin
1530 Grid.Cells[2,GridRow] := CLICK_TO_EDIT;
1531 end else begin
1532 Grid.Cells[2,GridRow] := CLICK_FOR_SUBS;
1533 end;
1534 end else if Pos('C',fieldDef)>0 then begin
1535 Grid.Cells[2,GridRow] := COMPUTED_FIELD;
1536 end else begin
1537 Grid.Cells[2,GridRow] := value;
1538 end;
1539 Grid.RowHeights[GridRow] := DEF_GRID_ROW_HEIGHT;
1540 end;
1541 end;
1542
1543 function getOneLine(CurrentData : TStringList; oneFileNum,oneFieldNum : string) : string;
1544 var i : integer;
1545 FileNum,FieldNum : string;
1546 begin
1547 result := '';
1548 // FileNum^IENS^FieldNum^FieldName^newValue^oldValue
1549 for i := 1 to CurrentData.Count - 1 do begin
1550 FileNum := piece(CurrentData.Strings[i],'^',1);
1551 if FileNum <> oneFileNum then continue;
1552 FieldNum := piece(CurrentData.Strings[i],'^',3);
1553 if FieldNum <> oneFieldNum then continue;
1554 result := CurrentData.Strings[i];
1555 break;
1556 end;
1557 end;
1558
1559 var i : integer;
1560 oneEntry : string;
1561 oneFileNum,oneFieldNum : string;
1562 gridRow : integer;
1563
1564 begin
1565 FLoadingGrid := true;
1566 if GridInfo=nil then exit;
1567 Grid := GridInfo.Grid;
1568 BasicMode := GridInfo.BasicMode;
1569 FileNum := GridInfo.FileNum;
1570 IENS := GridInfo.IENS;
1571 CurrentData := GridInfo.Data;
1572
1573 Grid.Cells[0,1] := '';
1574 Grid.Cells[1,1] := '';
1575 Grid.Cells[2,1] := '';
1576 Grid.RowCount :=2;
1577 Grid.ColWidths[0] := 50;
1578 Grid.ColWidths[1] := 200;
1579 Grid.ColWidths[2] := 300;
1580 Grid.Cells[0,0] := '#';
1581 Grid.Cells[1,0] := 'Name';
1582 Grid.Cells[2,0] := 'Value';
1583
1584 if BasicMode=false then begin
1585 for i := 1 to CurrentData.Count-1 do begin //start at 1 because [0] = 1^Success
1586 oneEntry := CurrentData.Strings[i];
1587 LoadOneLine (Grid,oneEntry,i);
1588 end;
1589 end else if BasicMode=true then begin
1590 gridRow := 1;
1591 for i := 0 to BasicTemplate.Count-1 do begin
1592 oneFileNum := Piece(BasicTemplate.Strings[i],'^',1);
1593 if oneFileNum <> fileNum then continue;
1594 oneFieldNum := Piece(BasicTemplate.Strings[i],'^',2);
1595 oneEntry := getOneLine(CurrentData,oneFileNum,oneFieldNum);
1596 LoadOneLine (Grid,oneEntry,gridRow);
1597 Inc(GridRow);
1598 end;
1599 end;
1600 FLoadingGrid := false;
1601 end;
1602
1603 function TfrmPtDemoEdit.GetInfoForGrid(Grid : TStringGrid) : TGridInfo;
1604 var i : integer;
1605 begin
1606 i := GetInfoIndexForGrid(Grid);
1607 if i > -1 then begin
1608 result := TGridInfo(DataForGrid.Objects[i]);
1609 end else begin
1610 result := nil;
1611 end;
1612 end;
1613
1614
1615 function TfrmPtDemoEdit.GetInfoIndexForGrid(Grid : TStringGrid) : integer;
1616 var s : string;
1617 begin
1618 s := IntToStr(integer(Grid));
1619 result := Dataforgrid.indexof(s);
1620 end;
1621
1622function TfrmPtDemoEdit.IsSubFile(FieldDef: string ; var SubFileNum : string) : boolean;
1623 //SubFileNum is OUT parameter
1624 begin
1625 SubFileNum := ExtractNum(FieldDef,1);
1626 result := (SubFileNum <> '');
1627 end;
1628
1629 function TfrmPtDemoEdit.IsWPField(FileNum,FieldNum : string) : boolean;
1630 var RPCResult : string;
1631 SrchStr : string;
1632 Idx: integer;
1633 begin
1634 SrchStr := FileNum + '^' + FieldNum + '^';
1635 //Idx := CachedWPField.IndexOf(SrchStr + 'YES');
1636 //if Idx > -1 then begin Result := true; exit; end;
1637 //Idx := CachedWPField.IndexOf(SrchStr + 'NO');
1638 //if Idx > -1 then begin Result := false; exit; end;
1639
1640 result := false;
1641 RPCBrokerV.remoteprocedure := 'TMG CHANNEL';
1642 RPCBrokerV.param[0].ptype := list;
1643 RPCBrokerV.Param[0].Mult['"REQUEST"'] := 'IS WP FIELD^' + FileNum + '^' + FieldNum;
1644 RPCBrokerV.Call;
1645 RPCResult := RPCBrokerV.Results[0]; //returns: error: -1; success=1
1646 if piece(RPCResult,'^',1)='-1' then begin
1647 //FMErrorForm.Memo.Lines.Assign(RPCBrokerV.Results);
1648 //FMErrorForm.PrepMessage;
1649 //FMErrorForm.ShowModal;
1650 end else begin
1651 RPCResult := piece(RPCResult,'^',3);
1652 result := (RPCResult = 'YES');
1653 //CachedWPField.Add(SrchStr + RPCResult);
1654 end;
1655 end;
1656
1657 function TfrmPtDemoEdit.ExtractNum (S : String; StartPos : integer) : string;
1658 var i : integer;
1659 ch : char;
1660 begin
1661 result := '';
1662 if (S = '') or (StartPos < 0) then exit;
1663 i := StartPos;
1664 repeat
1665 ch := S[i];
1666 i := i + 1;
1667 if ch in ['0'..'9','.'] then begin
1668 Result := Result + ch;
1669 end;
1670 until (i > length(S)) or not (ch in ['0'..'9','.'])
1671 end;
1672
1673 procedure TfrmPtDemoEdit.gridPatientDemoSelectCell(Sender: TObject; ACol,
1674 ARow: Integer; var CanSelect: Boolean);
1675 (*
1676 For Field def, here is the legend
1677 character meaning
1678
1679 BC The data is Boolean Computed (true or false).
1680 C The data is Computed.
1681 Cm The data is multiline Computed.
1682 DC The data is Date-valued, Computed.
1683 D The data is Date-valued.
1684 F The data is Free text.
1685 I The data is uneditable.
1686 Pn The data is a Pointer reference to file "n".
1687 S The data is from a discrete Set of codes.
1688
1689 N The data is Numeric-valued.
1690
1691 Jn To specify a print length of n characters.
1692 Jn,d To specify printing n characters with decimals.
1693
1694 V The data is a Variable pointer.
1695 W The data is Word processing.
1696 WL The Word processing data is normally printed in Line mode (i.e., without word wrap).
1697 *)
1698 var oneEntry,FieldDef : string;
1699 date,time: string;
1700 FileNum,FieldNum,SubFileNum : string;
1701 GridFileNum : string;
1702 UserLine : integer;
1703 Grid : TStringGrid;
1704 IEN : int64;
1705 IENS : string;
1706 CurrentData : TStringList;
1707 GridInfo : TGridInfo;
1708 SubFileForm : TSubFileForm;
1709 begin
1710 if FLoadingGrid then exit; //prevent pseudo-clicks during loading...
1711 Grid := (Sender as TStringGrid);
1712 GridInfo := GetInfoForGrid(Grid);
1713 if GridInfo=nil then exit;
1714 GridFileNum := GridInfo.FileNum;
1715 CanSelect := false; //default to NOT selectable.
1716 CurrentData := GridInfo.Data;
1717 if CurrentData=nil then exit;
1718 if CurrentData.Count = 0 then exit;
1719 UserLine := GetUserLine(CurrentData,Grid,ARow);
1720 if UserLine = -1 then exit;
1721 oneEntry := CurrentData.Strings[UserLine];
1722 FieldDef := Piece(oneEntry,'^',6);
1723 if Pos('F',FieldDef)>0 then begin //Free text
1724 CanSelect := true;
1725 end else if IsSubFile(FieldDef,SubFileNum) then begin //Subfiles.
1726 FileNum := Piece(oneEntry,'^',1);
1727 FieldNum := Piece(oneEntry,'^',3);
1728 if IsWPField(FileNum,FieldNum) then begin
1729 IENS := Piece(oneEntry,'^',2);
1730 EditTextForm.PrepForm(FileNum,FieldNum,IENS);
1731 EditTextForm.ShowModal;
1732 end else begin
1733 //handle subfiles here
1734 IENS := '';
1735 if GridInfo.Message = MSG_SUB_FILE then begin //used message from subfile Grid
1736 IENS := GridInfo.IENS;
1737 end; // else if LastSelTreeNode <> nil then begin //this is one of the selction trees.
1738 IEN := strtoint(Patient.DFN); //longInt(LastSelTreeNode.Data);
1739 if IEN > 0 then IENS := InttoStr(IEN) + ',';
1740 if GridInfo.Data = CurrentAnyFileData then begin
1741 IEN := strtoint(patient.dfn); //get info from selected record
1742 if IEN > 0 then IENS := InttoStr(IEN) + ',';
1743 end;
1744 if IENS <> '' then begin
1745 SubFileForm := TSubFileForm.Create(self);
1746 SubFileForm.PrepForm(SubFileNum,IENS);
1747 SubfileForm.ShowModal; // note: may call this function again recursively for sub-sub-files etc.
1748 SubFileForm.Free;
1749 end else begin
1750 MessageDlg('IENS for File="". Can''t process.',mtInformation,[MBOK],0);
1751 end;
1752 end;
1753 end else if Pos('C',FieldDef)>0 then begin //computed fields.
1754 CanSelect := false;
1755 end else if Pos('D',FieldDef)>0 then begin //date field
1756 date := piece(Grid.Cells[ACol,ARow],'@',1);
1757 time := piece(Grid.Cells[ACol,ARow],'@',2);
1758 if date <> '' then begin
1759 SelDateTimeForm.DateTimePicker.Date := StrToDate(date);
1760 end else begin
1761 SelDateTimeForm.DateTimePicker.Date := SysUtils.Date;
1762 end;
1763 if SelDateTimeForm.ShowModal = mrOK then begin
1764 date := DateToStr(SelDateTimeForm.DateTimePicker.Date);
1765 time := TimeToStr(SelDateTimeForm.DateTimePicker.Time);
1766 if time <> '' then date := date; // + '@' + time; elh 8/15/08
1767 Grid.Cells[ACol,ARow] := date;
1768 end;
1769 CanSelect := true;
1770 end else if Pos('S',FieldDef)>0 then begin //Set of Codes
1771 SetSelForm.PrepForm(Piece(oneEntry,'^',7));
1772 if SetSelForm.ShowModal = mrOK then begin
1773 Grid.Cells[ACol,ARow] := SetSelForm.ComboBox.Text;
1774 CanSelect := true;
1775 end;
1776 end else if Pos('I',FieldDef)>0 then begin //uneditable
1777 ShowMessage('Sorry. Flagged as UNEDITABLE.');
1778 end else if Pos('P',FieldDef)>0 then begin //Pointer to file.
1779 FileNum := ExtractNum (FieldDef,Pos('P',FieldDef)+1);
1780 //check for validity here...
1781 FieldLookupForm.PrepForm(FileNum,Grid.Cells[ACol,ARow]);
1782 if FieldLookupForm.ShowModal = mrOK then begin
1783 Grid.Cells[ACol,ARow] := FieldLookupForm.ORComboBox.Text;
1784 CanSelect := true;
1785 end;
1786 end;
1787 if CanSelect then begin
1788 FLastSelectedRow := ARow;
1789 FLastSelectedCol := ACol;
1790 SetModified(True);
1791 end;
1792 //GridInfo.ApplyBtn.Enabled := true;
1793 //GridInfo.RevertBtn.Enabled := true;
1794 end;
1795
1796 function TfrmPtDemoEdit.GetLineInfo(Grid : TStringGrid; CurrentUserData : TStringList; ARow: integer) : tFileEntry;
1797 var fieldNum : string;
1798 oneEntry : string;
1799 fileNum : string;
1800 gridRow : integer;
1801 begin
1802 fieldNum := Grid.Cells[0,ARow];
1803 gridRow := FindInStrings(fieldNum, CurrentUserData, fileNum);
1804 if gridRow > -1 then begin
1805 oneEntry := CurrentUserData.Strings[gridRow];
1806 Result.Field := fieldNum;
1807 Result.FieldName := Grid.Cells[1,ARow];
1808 Result.FileNum := fileNum;
1809 Result.IENS := Piece(oneEntry,'^',2);
1810 Result.oldValue := Piece(oneEntry,'^',4);
1811 Result.newValue := Grid.Cells[2,ARow];
1812 end else begin
1813 Result.Field := '';
1814 Result.FieldName := '';
1815 Result.FileNum := '';
1816 Result.IENS := '';
1817 Result.oldValue := '';
1818 Result.newValue := '';
1819 end;
1820 end;
1821
1822procedure TfrmPtDemoEdit.GetOneRecord(FileNum, IENS : string; Data, BlankFileInfo: TStringList);
1823 var cmd,RPCResult : string;
1824 i : integer;
1825 oneEntry : string;
1826 begin
1827 Data.Clear;
1828 if (IENS='') then exit;
1829 if Pos('+',IENS)=0 then begin //don't ask server to load +1 records.
1830 RPCBrokerV.remoteprocedure := 'TMG CHANNEL';
1831 RPCBrokerV.Param[0].Value := '.X'; // not used
1832 RPCBrokerV.param[0].ptype := list;
1833 cmd := 'GET ONE RECORD^' + FileNum + '^' + IENS;
1834 RPCBrokerV.Param[0].Mult['"REQUEST"'] := cmd;
1835 RPCBrokerV.Call;
1836 RPCResult := RPCBrokerV.Results[0]; //returns: error: -1; success=1
1837 if piece(RPCResult,'^',1)='-1' then begin
1838 FMErrorForm.Memo.Lines.Assign(RPCBrokerV.Results);
1839 FMErrorForm.PrepMessage;
1840 FMErrorForm.ShowModal;
1841 end else begin
1842 Data.Assign(RPCBrokerV.Results);
1843 end;
1844 end else begin
1845 Data.Add('1^Success'); //to keep same as call to server
1846 if BlankFileInfo.Count = 0 then begin
1847 //Format is: FileNum^^FieldNum^^DDInfo...
1848 // elh GetBlankFileInfo(FileNum,BlankFileInfo);
1849 end;
1850 for i := 1 to BlankFileInfo.Count-1 do begin //0 is 1^success
1851 oneEntry := BlankFileInfo.Strings[i];
1852 // elh SetPiece(oneEntry,'^',2,IENS);
1853 Data.Add(oneEntry);
1854 end;
1855 end;
1856 end;
1857
1858function TfrmPtDemoEdit.GetUserLine(CurrentUserData : TStringList; Grid : TStringGrid; ARow: integer) : integer;
1859 var fieldNum: string;
1860 tempFileNum : string;
1861 begin
1862 fieldNum := Grid.Cells[0,ARow];
1863 Result := FindInStrings(fieldNum,CurrentUserData,tempFileNum);
1864 end;
1865
1866 function TfrmPtDemoEdit.FindInStrings(fieldNum : string; Strings : TStringList; var fileNum : string) : integer;
1867 //Note: if fileNum is passed blank, then first matching file will be placed in it (i.e. OUT parameter)
1868 var tempFieldNum : string;
1869 oneEntry,tempFile : string;
1870 i : integer;
1871 begin
1872 result := -1;
1873 fileNum := '';
1874 for i := 1 to Strings.Count-1 do begin //0 --> 1^success
1875 oneEntry := Strings.Strings[i];
1876 tempFile := Piece(oneEntry,'^',1);
1877 if fileNum='' then fileNum := tempFile;
1878 if tempFile <> fileNum then continue; //ignore subfiles
1879 tempFieldNum := Piece(oneEntry,'^',3);
1880 if tempFieldNum <> fieldNum then continue;
1881 Result := i;
1882 break;
1883 end;
1884 end;
1885
1886 procedure TfrmPtDemoEdit.AddGridInfo(Grid: TStringGrid;
1887 Data : TStringList;
1888 BasicMode : boolean;
1889 DataLoader : TGridDataLoader;
1890 FileNum : string);
1891 var tempGridInfo : TGridInfo;
1892 begin
1893 tempGridInfo := TGridInfo.Create;
1894 tempGridInfo.Grid := Grid;
1895 tempGridInfo.Data := Data;
1896 tempGridInfo.BasicMode := BasicMode;
1897 tempGridInfo.FileNum := FileNum;
1898 tempGridInfo.DataLoadProc := DataLoader;
1899 //tempGridInfo.ApplyBtn := ApplyBtn;
1900 //tempGridInfo.RevertBtn := RevertBtn;
1901 RegisterGridInfo(tempGridInfo);
1902 end;
1903
1904procedure TfrmPtDemoEdit.RegisterGridInfo(GridInfo : TGridInfo);
1905 var s : string;
1906 begin
1907 if GridInfo = nil then exit;
1908 s := IntToStr(integer(GridInfo.Grid));
1909 DataForGrid.AddObject(s,GridInfo);
1910 end;
1911
1912procedure TfrmPtDemoEdit.gridPatientDemoSetEditText(Sender: TObject; ACol,
1913 ARow: Integer; const Value: String);
1914begin
1915 SetModified(True);
1916end;
1917
1918procedure TfrmPtDemoEdit.PageControlChanging(Sender: TObject;
1919 var AllowChange: Boolean);
1920var
1921 intAnswer : Integer;
1922begin
1923//Before changing the form, find out if changes need to be applied and
1924//prompt user. elh
1925 if ApplyBtn.enabled = True then begin
1926 intAnswer := messagedlg('Do you want to apply your changes?', mtWarning,mbYesNoCancel,0);
1927 if intAnswer = mrYes then begin //Yes
1928 ApplyBtnClick(Sender);
1929 //messagedlg('Changes Saved.', mtWarning,[mbOK],0);
1930 SetModified(False);
1931 end else if intAnswer = mrNo then begin //No
1932 SetModified(False);
1933 end else if intAnswer = mrCancel then begin //Cancel
1934 AllowChange := False;
1935 end;
1936 end;
1937end;
1938end.
Note: See TracBrowser for help on using the repository browser.