[go: up one dir, main page]

Menu

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

Download this file

641 lines (580 with data), 19.0 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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
{
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;
actHospitalsAdd: TAction;
actHospitalsList: TAction;
actExaminationsNamesAdd: TAction;
actExaminationsNamesList: TAction;
actExaminationsAdd: TAction;
actExaminationsList: TAction;
actExaminationsNamesCategoriesAdd: TAction;
actExaminationsNamesCategoriesList: TAction;
actDocumentsAdd: TAction;
actDocumentsList: TAction;
actPrescriptionsList: TAction;
actPrescriptionsAdd: TAction;
actMeasurementsList: TAction;
actPathologiesAdd: TAction;
actPathologiesList: TAction;
actMeasurementsAdd: TAction;
actPersonsAdd: TAction;
actPersonsList: TAction;
actQuit: TAction;
MainActionList: TActionList;
MainMenu: TMainMenu;
MenuItem1: TMenuItem;
MenuItem2: TMenuItem;
MenuItem6: TMenuItem;
miPrescriptionsList: TMenuItem;
miPrescriptionsAdd: TMenuItem;
miPatientsPrescriptions: TMenuItem;
miDocumentsList: TMenuItem;
miDocumentsAdd: TMenuItem;
miPersonsDocuments: TMenuItem;
miExaminationsNamesCategoriesList: TMenuItem;
miExaminationsNamesCategoriesAdd: TMenuItem;
miGeneralDataExaminationsNamesCategories: TMenuItem;
miExaminationsList: TMenuItem;
miExaminationsAdd: TMenuItem;
miPatientsExaminations: TMenuItem;
miMeasurementsList: TMenuItem;
miExaminationsNamesList: TMenuItem;
MenuItem7: TMenuItem;
miGeneralDataExaminationsNames: TMenuItem;
miHospitalsAdd: TMenuItem;
miGeneralDataHospitals: 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;
pgConnectionDefData: TPQConnection;
pgQuery: TSQLQuery;
pgQueryDefData: TSQLQuery;
pgTransaction: TSQLTransaction;
pgScript: TSQLScript;
pgTransactionDefData: TSQLTransaction;
StatusBar: TStatusBar;
XmlPropStor: TXMLPropStorage;
procedure actCountriesAddExecute(Sender: TObject);
procedure actCountriesListExecute(Sender: TObject);
procedure actDbCheckSystemTablesExecute(Sender: TObject);
procedure actDbConnectExecute(Sender: TObject);
procedure actDocumentsAddExecute(Sender: TObject);
procedure actDocumentsListExecute(Sender: TObject);
procedure actExaminationsAddExecute(Sender: TObject);
procedure actExaminationsListExecute(Sender: TObject);
procedure actExaminationsNamesAddExecute(Sender: TObject);
procedure actExaminationsNamesCategoriesAddExecute(Sender: TObject);
procedure actExaminationsNamesCategoriesListExecute(Sender: TObject);
procedure actExaminationsNamesListExecute(Sender: TObject);
procedure actHeAboutExecute(Sender: TObject);
procedure actHospitalsAddExecute(Sender: TObject);
procedure actHospitalsListExecute(Sender: TObject);
procedure actMeasurementsAddExecute(Sender: TObject);
procedure actMeasurementsListExecute(Sender: TObject);
procedure actPathologiesAddExecute(Sender: TObject);
procedure actPathologiesListExecute(Sender: TObject);
procedure actPersonsAddExecute(Sender: TObject);
procedure actPersonsListExecute(Sender: TObject);
procedure actPrescriptionsAddExecute(Sender: TObject);
procedure actPrescriptionsListExecute(Sender: TObject);
procedure actProblemsAddExecute(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 exists, 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;
// It asks to the user to select a person.
// If no person exists, the user can create a new one
// If only one person exists, that one is returned
// Otherwise the selection mask is showed in modal form
// Returns true if PersonID and PersonName contain valid data.
function SelectPerson( var PersonID : LongInt; var PersonName : string ):
boolean;
end;
var
frmMain: TfrmMain;
Traduzioni: string;
const
constMyLatestKnownDbVersion=1;
constMyLatestKnownDbDefDataVersion=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_patient, hor_edit_mdl_measurements,
hor_navigation_pathologies, hor_edit_pathologies, hor_navigation_hospitals,
hor_edit_hospitals, hor_navigation_examinations_names,
hor_edit_examinations_names, hor_navigation_measurements,
hor_edit_examinations, hor_navigation_examinations,
hor_navigation_examinations_names_categories,
hor_edit_examinations_names_categories, hor_edit_documents,
hor_navigation_documents, hor_combobox_person, hor_edit_prescriptions,
hor_navigation_prescriptions;
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.actDocumentsAddExecute(Sender: TObject);
var
vPersonID : LongInt;
vPersonName : string;
begin
// First of all I have to request for which person
vPersonID:=0;
vPersonName:='';
if ( SelectPerson( vPersonID, vPersonName ) ) then
begin
with TfrmEditDocuments.Create( Application ) do
begin
Caption := Format( Caption, [ vPersonName ] );
lblTitle.Caption := Caption;
NewRecord;
qDataID_Person.Value:=vPersonID;
Show;
end;
end;
end;
procedure TfrmMain.actDocumentsListExecute(Sender: TObject);
var
vPersonID : LongInt;
vPersonName : string;
begin
// First of all I have to request for which person
vPersonID:=0;
vPersonName:='';
if ( SelectPerson( vPersonID, vPersonName ) ) then
begin
with TfrmNavigationDocuments.Create( Application ) do
begin
qList.ParamByName('ID').Value := vPersonID;
PersonName := vPersonName;
PersonID := vPersonID;
Show();
end;
end;
end;
procedure TfrmMain.actExaminationsAddExecute(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 TfrmEditExaminations.Create( Application ) do
begin
PatientName:=vPatientName;
PatientID:=vPatientID;
Caption := Format( Caption, [ vPatientName ] );
lblTitle.Caption := Caption;
NewRecord;
qDataID_Patient.Value:=vPatientID;
Show;
end;
end;
end;
procedure TfrmMain.actExaminationsListExecute(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 TfrmNavigationExaminations.Create( Application ) do
begin
qList.ParamByName('ID').Value := vPatientID;
PatientName := vPatientName;
PatientID := vPatientID;
Show;
end;
end;
end;
procedure TfrmMain.actExaminationsNamesAddExecute(Sender: TObject);
begin
with TfrmEditExaminations_Names.Create(Self) do
begin
NewRecord;
Show;
end;
end;
procedure TfrmMain.actExaminationsNamesCategoriesAddExecute(Sender: TObject);
begin
with TfrmEditExaminations_Names_Categories.Create(Self) do
begin
NewRecord;
Show;
end;
end;
procedure TfrmMain.actExaminationsNamesCategoriesListExecute(Sender: TObject);
begin
TfrmNavigationExaminations_Names_Categories.Create(Self).Show();
end;
procedure TfrmMain.actExaminationsNamesListExecute(Sender: TObject);
begin
TfrmNavigationExaminations_Names.Create(Self).Show();
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.actHospitalsAddExecute(Sender: TObject);
begin
with TfrmEditHospitals.Create(Self) do
begin
NewRecord;
Show;
end;
end;
procedure TfrmMain.actHospitalsListExecute(Sender: TObject);
begin
TfrmNavigationHospitals.Create(Self).Show();
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.actMeasurementsListExecute(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 TfrmNavigationMeasurements.Create( Application ) do
begin
qList.ParamByName('ID').Value := vPatientID;
PatientName := vPatientName;
PatientID := 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.actPrescriptionsAddExecute(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 TfrmEditPrescriptions.Create( Application ) do
begin
PatientID:=vPatientID;
PatientName:=vPatientName;
Caption := Format( Caption, [ vPatientName ] );
lblTitle.Caption := Caption;
NewRecord;
qDataID_Patient.Value:=vPatientID;
Show;
end;
end;
end;
procedure TfrmMain.actPrescriptionsListExecute(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 TfrmNavigationPrescriptions.Create( Application ) do
begin
qList.ParamByName('ID').Value := vPatientID;
PatientName := vPatientName;
PatientID := vPatientID;
Show;
end;
end;
end;
procedure TfrmMain.actProblemsAddExecute(Sender: TObject);
begin
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);
if ( pgConnectionDefData.Connected ) then
pgConnectionDefData.Connected:=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;
Language : string;
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
Language := 'it'
else if ( miLanguage.Items[I] = miLaPortuguese ) then
Language := 'pt_PT'
else if ( miLanguage.Items[I] = miLaFrancais ) then
Language := 'fr_FR'
else
// The default in the case of not already handled language
Language := 'en';
SetDefaultLang( Language );
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);
var
I : integer;
begin
// It enables or disables (according to the EnableThem parameter) all the
// functions that needs an established database connection to work properly
// In other words, all the commands except the language selection, information
// and database connection
for I := 1 to MainActionList.ActionCount do
begin
(MainActionList.Actions[I-1] as TAction).Enabled :=
EnableThem;
end;
if ( not EnableThem ) then
Begin
// I enable some standard features
actDbConnect.Enabled:=true;
actHeAbout.Enabled:=true;
actQuit.Enabled:=true;
end;
end;
function TfrmMain.SelectPatient(var PatientID: LongInt; var PatientName: string
): boolean;
begin
result := false;
with TfrmComboBoxPatient.Create( Application ) do
begin
if ShowModal=mrOK then
begin
PatientID:= Patient__ID;
PatientName := Patient__Name;
result := true;
end;
Release;
end;
end;
function TfrmMain.SelectPerson(var PersonID: LongInt; var PersonName: string
): boolean;
begin
result := false;
with TfrmComboBoxPerson.Create( Application ) do
begin
if ShowModal=mrOK then
begin
PersonID:= Person__ID;
PersonName := Person__Name;
result := true;
end;
Release;
end;
end;
end.