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