[459] | 1 | unit fOptionsTeams;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
| 7 | StdCtrls, ExtCtrls, ORCtrls, OrFn, Menus;
|
---|
| 8 |
|
---|
| 9 | type
|
---|
| 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 |
|
---|
| 51 | var
|
---|
| 52 | frmOptionsTeams: TfrmOptionsTeams;
|
---|
| 53 |
|
---|
| 54 | procedure DialogOptionsTeams(topvalue, leftvalue, fontsize: integer; var actiontype: Integer);
|
---|
| 55 |
|
---|
| 56 | implementation
|
---|
| 57 |
|
---|
| 58 | uses rOptions, uOptions, rCore, fOptions;
|
---|
| 59 |
|
---|
| 60 | {$R *.DFM}
|
---|
| 61 |
|
---|
| 62 | procedure DialogOptionsTeams(topvalue, leftvalue, fontsize: integer; var actiontype: Integer);
|
---|
| 63 | // create the form and make it modal, return an action
|
---|
| 64 | var
|
---|
| 65 | frmOptionsTeams: TfrmOptionsTeams;
|
---|
| 66 | begin
|
---|
| 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;
|
---|
| 86 | end;
|
---|
| 87 |
|
---|
| 88 | procedure TfrmOptionsTeams.FormCreate(Sender: TObject);
|
---|
| 89 | begin
|
---|
| 90 | rpcGetTeams(lstTeams.Items);
|
---|
| 91 | lstTeams.ItemIndex := -1;
|
---|
| 92 | FillATeams;
|
---|
| 93 | end;
|
---|
| 94 |
|
---|
| 95 | procedure TfrmOptionsTeams.FillATeams;
|
---|
| 96 | var
|
---|
| 97 | i: integer;
|
---|
| 98 | alist: TStringList;
|
---|
| 99 | begin
|
---|
| 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;
|
---|
| 109 | end;
|
---|
| 110 |
|
---|
| 111 | procedure TfrmOptionsTeams.FillList(alist: TORListBox; members: TStrings);
|
---|
| 112 | var
|
---|
| 113 | i: integer;
|
---|
| 114 | begin
|
---|
| 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]);
|
---|
| 118 | end;
|
---|
| 119 |
|
---|
| 120 | procedure TfrmOptionsTeams.MergeList(alist: TORListBox; members: TStrings);
|
---|
| 121 | var
|
---|
| 122 | i: integer;
|
---|
| 123 | begin
|
---|
| 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);
|
---|
| 127 | end;
|
---|
| 128 |
|
---|
| 129 | function TfrmOptionsTeams.ItemNotAMember(alist: TStrings; listnum: string): boolean;
|
---|
| 130 | var
|
---|
| 131 | i: integer;
|
---|
| 132 | begin
|
---|
| 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;
|
---|
| 140 | end;
|
---|
| 141 |
|
---|
| 142 | function TfrmOptionsTeams.MemberNotOnList(alist: TStrings; listnum: string): boolean;
|
---|
| 143 | var
|
---|
| 144 | i: integer;
|
---|
| 145 | begin
|
---|
| 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;
|
---|
| 154 | end;
|
---|
| 155 |
|
---|
| 156 | procedure TfrmOptionsTeams.chkPersonalClick(Sender: TObject);
|
---|
| 157 | begin
|
---|
| 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);
|
---|
| 165 | end;
|
---|
| 166 |
|
---|
| 167 | procedure TfrmOptionsTeams.lstTeamsClick(Sender: TObject);
|
---|
| 168 | var
|
---|
| 169 | i, teamid, cnt: integer;
|
---|
| 170 | astrings: TStringList;
|
---|
| 171 | begin
|
---|
| 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;
|
---|
| 217 | end;
|
---|
| 218 |
|
---|
| 219 | procedure TfrmOptionsTeams.chkRestrictClick(Sender: TObject);
|
---|
| 220 | begin
|
---|
| 221 | lstTeamsClick(self);
|
---|
| 222 | end;
|
---|
| 223 |
|
---|
| 224 | procedure TfrmOptionsTeams.cboSubscribeClick(Sender: TObject);
|
---|
| 225 | begin
|
---|
| 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;
|
---|
| 249 | end;
|
---|
| 250 |
|
---|
| 251 | procedure TfrmOptionsTeams.btnRemoveClick(Sender: TObject);
|
---|
| 252 | begin
|
---|
| 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;
|
---|
| 263 | end;
|
---|
| 264 |
|
---|
| 265 | procedure TfrmOptionsTeams.mnuPatientIDClick(Sender: TObject);
|
---|
| 266 | begin
|
---|
| 267 | DisplayPtInfo(lstPatients.ItemID);
|
---|
| 268 | end;
|
---|
| 269 |
|
---|
| 270 | procedure TfrmOptionsTeams.lstPatientsMouseDown(Sender: TObject;
|
---|
| 271 | Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
|
---|
| 272 | begin
|
---|
| 273 | mnuPopPatient.AutoPopup := (lstPatients.Items.Count > 0)
|
---|
| 274 | and (lstPatients.ItemIndex > -1)
|
---|
| 275 | and (Button = mbRight);
|
---|
| 276 | end;
|
---|
| 277 |
|
---|
| 278 | procedure TfrmOptionsTeams.cboSubscribeKeyDown(Sender: TObject;
|
---|
| 279 | var Key: Word; Shift: TShiftState);
|
---|
| 280 | begin
|
---|
| 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;
|
---|
| 287 | end;
|
---|
| 288 |
|
---|
| 289 | end.
|
---|