[go: up one dir, main page]

Menu

[r41]: / trunk / hor_main.pas  Maximize  Restore  History

Download this file

390 lines (346 with data), 11.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
{
Health Organizer (http://sourceforge.net/projects/hor/,
http://hor.sourceforge.net/)
Copyright (C) 2014-2015 Andrea Urbani ( matfanjol@users.sf.net,
matfanjol@mail.com )
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
}
unit hor_main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, pqconnection, sqldb, FileUtil, Forms, Controls, Graphics,
Dialogs, defaulttranslator, ComCtrls, Menus, ActnList, XMLPropStorage;
type
{ TfrmMain }
TfrmMain = class(TForm)
actDbConnect: TAction;
actHeAbout: TAction;
actCountriesAdd: TAction;
actCountriesList: TAction;
actDbCheckSystemTables: TAction;
actPathologiesAdd: TAction;
actPathologiesList: TAction;
actMeasurementsAdd: TAction;
actPersonsAdd: TAction;
actPersonsList: TAction;
actQuit: TAction;
MainActionList: TActionList;
MainMenu: TMainMenu;
MenuItem1: TMenuItem;
miPathologiesList: TMenuItem;
miPathologiesAdd: TMenuItem;
miGeneralDataPathologies: TMenuItem;
miGeneralData: TMenuItem;
miLaFrancais: TMenuItem;
miLaPortuguese: TMenuItem;
miMeasurementsAdd: TMenuItem;
miPatientsMeasurements: TMenuItem;
miPatients: TMenuItem;
miDbCheckST: TMenuItem;
MenuItem5: TMenuItem;
miCountriesList: TMenuItem;
miCountriesAdd: TMenuItem;
miGdCountries: TMenuItem;
miGeneralDataGeographical: TMenuItem;
miPersons: TMenuItem;
MenuItem3: TMenuItem;
MenuItem4: TMenuItem;
miHeAbout: TMenuItem;
miHelp: TMenuItem;
miLaItaliano: TMenuItem;
miLaEnglish: TMenuItem;
miLanguage: TMenuItem;
miDbQuit: TMenuItem;
miDbOpen: TMenuItem;
miDatabase: TMenuItem;
pgConnection: TPQConnection;
pgQuery: TSQLQuery;
pgTransaction: TSQLTransaction;
pgScript: TSQLScript;
StatusBar: TStatusBar;
XmlPropStor: TXMLPropStorage;
procedure actCountriesAddExecute(Sender: TObject);
procedure actCountriesListExecute(Sender: TObject);
procedure actDbCheckSystemTablesExecute(Sender: TObject);
procedure actDbConnectExecute(Sender: TObject);
procedure actHeAboutExecute(Sender: TObject);
procedure actMeasurementsAddExecute(Sender: TObject);
procedure actPathologiesAddExecute(Sender: TObject);
procedure actPathologiesListExecute(Sender: TObject);
procedure actPersonsAddExecute(Sender: TObject);
procedure actPersonsListExecute(Sender: TObject);
procedure actQuitExecute(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure miLaEnglishClick(Sender: TObject);
procedure pgConnectionAfterConnect(Sender: TObject);
procedure pgConnectionAfterDisconnect(Sender: TObject);
procedure pgScriptException(Sender: TObject; Statement: TStrings;
TheException: Exception; var Continue: boolean);
protected
procedure SelectLanguage( MenuItem : TMenuItem );
procedure BuildTitle;
procedure EnableDisableDatabaseRelativeFunction( const EnableThem :
boolean);
private
{ private declarations }
public
var ReadOnlyMode: boolean;
// It asks to the user to select a patient.
// If no patient exist, the user can create a new one
// If only one patient exists, that one is returned
// Otherwise the selection mask is showed in modal form
// Returns true if PatientID and PatientName contain valid data.
function SelectPatient( var PatientID : LongInt; var PatientName : string ):
boolean;
end;
var
frmMain: TfrmMain;
Traduzioni: string;
const
constMyLatestKnownDbVersion=1;
// The default data database is built with the <database name> +
// constDefaultDataDatabaseSuffix name and will contain default data like the
// list of countries, cities, drugs, etc..
// The idea is to store inside the main database just the used data.
constDefaultDataDatabaseSuffix='_defdata';
implementation
{$R *.lfm}
{ TfrmMain }
Uses hor_dbopen, hor_about, hor_navigation_persons,
hor_edit_persons, hor_navigation_countries, hor_edit_countries, LCLTranslator,
hor_messages, hor_database, hor_combobox, hor_edit_mdl_measurements,
hor_navigation_pathologies, hor_edit_pathologies;
procedure TfrmMain.actQuitExecute(Sender: TObject);
begin
Application.Terminate;
end;
procedure TfrmMain.FormActivate(Sender: TObject);
begin
if ( not pgConnection.Connected ) then
// I automatically start the connection action if no connection is available
actDbConnect.Execute;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
begin
XmlPropStor.FileName:=GetAppConfigFileUTF8(false,false,true);
ReadOnlyMode := false;
BuildTitle;
// At the beginning, that there is no database connection, all the function
// relative to the database has to be disabled
EnableDisableDatabaseRelativeFunction(false);
end;
procedure TfrmMain.actDbConnectExecute(Sender: TObject);
begin
Application.CreateForm(TfrmDbConnect,frmDbConnect);
frmDbConnect.ShowModal;
// if ( frmDbConnect.ShowModal = mrOK ) then
// DatabaseChanged
frmDbConnect.Release;
end;
procedure TfrmMain.actCountriesListExecute(Sender: TObject);
begin
TfrmNavigationCountries.Create(Self).Show();
end;
procedure TfrmMain.actDbCheckSystemTablesExecute(Sender: TObject);
begin
Screen.Cursor := crSQLWait;
try
try
if ( DB_CheckSystemData() ) then
MessageDlg( rsMsgDone, rsMsgCheckSuccess, mtInformation, [mbOk], 0 )
else
MessageDlg( rsMsgError, rsMsgUnknown, mtError, [mbOk], 0 );
except
on E: Exception do
MessageDlg( rsMsgError, Format( rsMsgErrorCheckingSystemData, [
e.Message ] ), mtError, [mbOk], 0 );
end;
finally
Screen.Cursor := crDefault;
end;
end;
procedure TfrmMain.actCountriesAddExecute(Sender: TObject);
begin
with TfrmEditCountries.Create(Self) do
begin
NewRecord;
Show;
end;
end;
procedure TfrmMain.actHeAboutExecute(Sender: TObject);
begin
Application.CreateForm(TfrmAbout, frmAbout);
frmAbout.ShowModal;
frmAbout.Release;
end;
procedure TfrmMain.actMeasurementsAddExecute(Sender: TObject);
var
vPatientID : LongInt;
vPatientName : string;
begin
// First of all I have to request for which patiente
vPatientID:=0;
vPatientName:='';
if ( SelectPatient( vPatientID, vPatientName ) ) then
begin
with TfrmEditMdlMeasurements.Create( Application ) do
begin
Caption := Format( Caption, [ vPatientName ] );
lblTitle.Caption := Caption;
NewRecord;
qDataID_Patient.Value:=vPatientID;
Show;
end;
end;
end;
procedure TfrmMain.actPathologiesAddExecute(Sender: TObject);
begin
with TfrmEditPathologies.Create(Self) do
begin
NewRecord;
Show;
end;
end;
procedure TfrmMain.actPathologiesListExecute(Sender: TObject);
begin
TfrmNavigationPathologies.Create(Self).Show();
end;
procedure TfrmMain.actPersonsAddExecute(Sender: TObject);
begin
with TfrmEditPersons.Create(Self) do
begin
NewRecord;
Show;
end;
end;
procedure TfrmMain.actPersonsListExecute(Sender: TObject);
begin
TfrmNavigationPersons.Create(Self).Show();
end;
procedure TfrmMain.miLaEnglishClick(Sender: TObject);
begin
if ( Sender is TMenuItem ) then
SelectLanguage( Sender as TMenuItem );
end;
procedure TfrmMain.pgConnectionAfterConnect(Sender: TObject);
begin
EnableDisableDatabaseRelativeFunction(true);
end;
procedure TfrmMain.pgConnectionAfterDisconnect(Sender: TObject);
begin
EnableDisableDatabaseRelativeFunction(false);
end;
procedure TfrmMain.pgScriptException(Sender: TObject; Statement: TStrings;
TheException: Exception; var Continue: boolean);
begin
Continue := false;
raise Exception.Create( Statement.Text + LineEnding + TheException.Message );
end;
procedure TfrmMain.SelectLanguage(MenuItem: TMenuItem);
var
I : integer;
begin
I := miLanguage.Count-1;
while ( I >= 0 ) do
begin
if ( miLanguage.Items[I] = MenuItem ) then
begin
miLanguage.Items[I].Checked:=true;
if ( miLanguage.Items[I] = miLaItaliano ) then
SetDefaultLang('it')
else if ( miLanguage.Items[I] = miLaPortuguese ) then
SetDefaultLang('pt_PT')
else if ( miLanguage.Items[I] = miLaFrancais ) then
SetDefaultLang('fr_FR')
else
// The default in the case of not already handled language
SetDefaultLang('en');
BuildTitle;
end
else
miLanguage.Items[I].Checked:=false;
Dec(I);
end;
end;
procedure TfrmMain.BuildTitle;
begin
Caption := rsAboutTitle + ' - ' + rsAboutBrief;
end;
procedure TfrmMain.EnableDisableDatabaseRelativeFunction(
const EnableThem: boolean);
begin
// It enables or disables (according to the EnableThem parameter) all the
// functions that needs an established database connection to work properly
actDbCheckSystemTables.Enabled:=EnableThem;
actPersonsAdd.Enabled:=EnableThem;
actPersonsList.Enabled:=EnableThem;
actCountriesAdd.Enabled:=EnableThem;
actCountriesList.Enabled:=EnableThem;
actMeasurementsAdd.Enabled:=EnableThem;
end;
function TfrmMain.SelectPatient(var PatientID: LongInt; var PatientName: string
): boolean;
begin
result := false;
with TfrmComboBox.Create( Application ) do
begin
qList.Sql.Clear;
qList.Sql.Add('select');
qList.Sql.Add('"ID",');
qList.Sql.Add('cast(trim(');
qList.Sql.Add('case');
qList.Sql.Add('when "tPersons"."Surname" is null then ''''');
qList.Sql.Add('else "tPersons"."Surname" end || '' '' || "tPersons"."Name"');
qList.Sql.Add(') as varchar(80)) as "Name"');
qList.Sql.Add('from "tPatients"');
qList.Sql.Add('inner join "tPersons"');
qList.Sql.Add('on ( "tPatients"."ID_Person" = "tPersons"."ID" )');
qList.Sql.Add('where');
qList.Sql.Add('"tPersons"."Dead_Day" is null');
qList.Sql.Add('order by');
qList.Sql.Add('trim(');
qList.Sql.Add('case');
qList.Sql.Add('when "tPersons"."Surname" is null then ''''');
qList.Sql.Add('else "tPersons"."Surname" end || '' '' || "tPersons"."Name"');
qList.Sql.Add(')');
dlCombobox.KeyField := 'ID';
dlCombobox.ListField:='Name';
lblTitle.Caption:=rsMsgSelectThePatient;
Caption := lblTitle.Caption;
qList.Open;
if ( qList.IsEmpty ) then
begin
if ( MessageDlg( rsMsgNoPatient, rsQMsgNoPatientExistsCreateOne,
mtConfirmation, [mbYes,mbNo], 0 ) = mrYes ) then
actPersonsAdd.Execute;
end
else if ( qList.RecordCount = 1 ) then
begin
PatientID:=qList.FieldByName('ID').AsInteger;
PatientName := qList.FieldByName('Name').AsString;
result := true;
end
else
begin
if ShowModal=mrOK then
begin
PatientID:=dlCombobox.KeyValue;
PatientName := dlCombobox.Text;
result := true;
end;
end;
Release;
end;
end;
end.