source: cprs/branches/foia-cprs/CPRS-Chart/Options/fOptionsTeams.pas@ 459

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

Adding foia-cprs branch

File size: 7.8 KB
Line 
1unit fOptionsTeams;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls, ExtCtrls, ORCtrls, OrFn, Menus;
8
9type
10 TfrmOptionsTeams = class(TForm)
11 pnlBottom: TPanel;
12 btnClose: TButton;
13 lstPatients: TORListBox;
14 lstTeams: TORListBox;
15 lblTeams: TLabel;
16 lblPatients: TLabel;
17 lstUsers: TORListBox;
18 lblTeamMembers: TLabel;
19 btnRemove: TButton;
20 chkPersonal: TCheckBox;
21 chkRestrict: TCheckBox;
22 bvlBottom: TBevel;
23 lblInfo: TMemo;
24 lblSubscribe: TLabel;
25 cboSubscribe: TORComboBox;
26 mnuPopPatient: TPopupMenu;
27 mnuPatientID: TMenuItem;
28 procedure FormCreate(Sender: TObject);
29 procedure chkPersonalClick(Sender: TObject);
30 procedure lstTeamsClick(Sender: TObject);
31 procedure chkRestrictClick(Sender: TObject);
32 procedure cboSubscribeClick(Sender: TObject);
33 procedure btnRemoveClick(Sender: TObject);
34 procedure mnuPatientIDClick(Sender: TObject);
35 procedure lstPatientsMouseDown(Sender: TObject; Button: TMouseButton;
36 Shift: TShiftState; X, Y: Integer);
37 procedure cboSubscribeKeyDown(Sender: TObject; var Key: Word;
38 Shift: TShiftState);
39 private
40 FKeyBoarding: boolean;
41 { Private declarations }
42 procedure FillATeams;
43 procedure FillList(alist: TORListBox; members: TStrings);
44 procedure MergeList(alist: TORListBox; members: TStrings);
45 function ItemNotAMember(alist: TStrings; listnum: string): boolean;
46 function MemberNotOnList(alist: TStrings; listnum: string): boolean;
47 public
48 { Public declarations }
49 end;
50
51var
52 frmOptionsTeams: TfrmOptionsTeams;
53
54procedure DialogOptionsTeams(topvalue, leftvalue, fontsize: integer; var actiontype: Integer);
55
56implementation
57
58uses rOptions, uOptions, rCore, fOptions;
59
60{$R *.DFM}
61
62procedure DialogOptionsTeams(topvalue, leftvalue, fontsize: integer; var actiontype: Integer);
63// create the form and make it modal, return an action
64var
65 frmOptionsTeams: TfrmOptionsTeams;
66begin
67 frmOptionsTeams := TfrmOptionsTeams.Create(Application);
68 actiontype := 0;
69 try
70 with frmOptionsTeams do
71 begin
72 if (topvalue < 0) or (leftvalue < 0) then
73 Position := poScreenCenter
74 else
75 begin
76 Position := poDesigned;
77 Top := topvalue;
78 Left := leftvalue;
79 end;
80 ResizeAnchoredFormToFont(frmOptionsTeams);
81 ShowModal;
82 end;
83 finally
84 frmOptionsTeams.Release;
85 end;
86end;
87
88procedure TfrmOptionsTeams.FormCreate(Sender: TObject);
89begin
90 rpcGetTeams(lstTeams.Items);
91 lstTeams.ItemIndex := -1;
92 FillATeams;
93end;
94
95procedure TfrmOptionsTeams.FillATeams;
96var
97 i: integer;
98 alist: TStringList;
99begin
100 cboSubscribe.Items.Clear;
101 alist := TStringList.Create;
102 rpcGetAteams(alist);
103 for i := 0 to alist.Count - 1 do
104 if MemberNotOnList(lstTeams.Items, Piece(alist[i], '^', 1)) then
105 cboSubscribe.Items.Add(alist[i]);
106 cboSubscribe.Enabled := cboSubscribe.Items.Count > 0;
107 lblSubscribe.Enabled := cboSubscribe.Items.Count > 0;
108 alist.Free;
109end;
110
111procedure TfrmOptionsTeams.FillList(alist: TORListBox; members: TStrings);
112var
113 i: integer;
114begin
115 for i := 0 to members.Count - 1 do
116 if MemberNotOnList(alist.Items, Piece(members[i], '^', 1)) then
117 alist.Items.Add(members[i]);
118end;
119
120procedure TfrmOptionsTeams.MergeList(alist: TORListBox; members: TStrings);
121var
122 i: integer;
123begin
124 for i := alist.Items.Count - 1 downto 0 do
125 if ItemNotAMember(members, Piece(alist.Items[i], '^', 1)) then
126 alist.Items.Delete(i);
127end;
128
129function TfrmOptionsTeams.ItemNotAMember(alist: TStrings; listnum: string): boolean;
130var
131 i: integer;
132begin
133 result := true;
134 for i := 0 to alist.Count - 1 do
135 if listnum = Piece(alist[i], '^', 1) then
136 begin
137 result := false;
138 break;
139 end;
140end;
141
142function TfrmOptionsTeams.MemberNotOnList(alist: TStrings; listnum: string): boolean;
143var
144 i: integer;
145begin
146 result := true;
147 with alist do
148 for i := 0 to Count - 1 do
149 if listnum = Piece(alist[i], '^', 1) then
150 begin
151 result := false;
152 break;
153 end;
154end;
155
156procedure TfrmOptionsTeams.chkPersonalClick(Sender: TObject);
157begin
158 lstTeams.Items.Clear;
159 if chkPersonal.Checked then
160 rpcGetAllTeams(lstTeams.Items)
161 else
162 rpcGetTeams(lstTeams.Items);
163 lstTeams.ItemIndex := -1;
164 lstTeamsClick(self);
165end;
166
167procedure TfrmOptionsTeams.lstTeamsClick(Sender: TObject);
168var
169 i, teamid, cnt: integer;
170 astrings: TStringList;
171begin
172 lstPatients.Items.Clear;
173 lstUsers.Items.Clear;
174 chkRestrict.Enabled := lstTeams.SelCount > 1;
175 astrings := TStringList.Create;
176 cnt := 0;
177 with lstTeams do
178 begin
179 for i := 0 to Items.Count - 1 do
180 if Selected[i] then
181 begin
182 inc(cnt);
183 teamid := strtointdef(Piece(Items[i], '^', 1), 0);
184 if (cnt > 1) and chkRestrict.Checked then
185 begin
186 ListPtByTeam(astrings, teamid);
187 MergeList(lstPatients, astrings);
188 rpcListUsersByTeam(astrings, teamid);
189 MergeList(lstUsers, astrings);
190 end
191 else
192 begin
193 ListPtByTeam(astrings, teamid);
194 if astrings.Count = 1 then // don't fill the '^No patients found.' msg
195 begin
196 if Piece(astrings[0], '^', 1) <> '' then
197 FillList(lstPatients, astrings);
198 end
199 else
200 FillList(lstPatients, astrings);
201 rpcListUsersByTeam(astrings, teamid);
202 FillList(lstUsers, astrings);
203 end;
204 end;
205 btnRemove.Enabled := (SelCount = 1)
206 and (Piece(Items[ItemIndex], '^', 3) <> 'P')
207 and (Piece(Items[ItemIndex], '^', 7) = 'Y');
208 if SelCount > 0 then
209 begin
210 if lstPatients.Items.Count = 0 then
211 lstPatients.Items.Add('^No patients found.');
212 if lstUsers.Items.Count = 0 then
213 lstUsers.Items.Add('^No team members found.');
214 end;
215 end;
216 astrings.Free;
217end;
218
219procedure TfrmOptionsTeams.chkRestrictClick(Sender: TObject);
220begin
221 lstTeamsClick(self);
222end;
223
224procedure TfrmOptionsTeams.cboSubscribeClick(Sender: TObject);
225begin
226 if FKeyBoarding then
227 FKeyBoarding := False
228 else
229 begin
230 with cboSubscribe do
231 if InfoBox('Do you want to join '
232 + Piece(Items[ItemIndex], '^', 2) + '?',
233 'Confirmation', MB_YESNO or MB_ICONQUESTION) = IDYES then
234 begin
235 rpcAddList(ItemIEN);
236 lstTeams.Items.Add(Items[ItemIndex]);
237 Items.Delete(ItemIndex);
238 ItemIndex := -1;
239 Text := '';
240 Enabled := Items.Count > 0;
241 lblSubscribe.Enabled := Items.Count > 0;
242 end
243 else
244 begin
245 ItemIndex := -1;
246 Text := '';
247 end;
248 end;
249end;
250
251procedure TfrmOptionsTeams.btnRemoveClick(Sender: TObject);
252begin
253 with lstTeams do
254 if InfoBox('Do you want to remove yourself from '
255 + Piece(Items[ItemIndex], '^', 2) + '?',
256 'Confirmation', MB_YESNO or MB_ICONQUESTION) = IDYES then
257 begin
258 rpcRemoveList(ItemIEN);
259 Items.Delete(ItemIndex);
260 lstTeamsClick(self);
261 FillATeams;
262 end;
263end;
264
265procedure TfrmOptionsTeams.mnuPatientIDClick(Sender: TObject);
266begin
267 DisplayPtInfo(lstPatients.ItemID);
268end;
269
270procedure TfrmOptionsTeams.lstPatientsMouseDown(Sender: TObject;
271 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
272begin
273 mnuPopPatient.AutoPopup := (lstPatients.Items.Count > 0)
274 and (lstPatients.ItemIndex > -1)
275 and (Button = mbRight);
276end;
277
278procedure TfrmOptionsTeams.cboSubscribeKeyDown(Sender: TObject;
279 var Key: Word; Shift: TShiftState);
280begin
281 case Key of VK_RETURN:
282 if (lstTeams.ItemIndex > 0) then
283 cboSubscribeClick(self); // Provide onclick behavior.
284 else
285 FKeyBoarding := True; // Suppress onclick behavior.
286 end;
287end;
288
289end.
Note: See TracBrowser for help on using the repository browser.