-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbFormExport.dpr
More file actions
61 lines (56 loc) · 1.68 KB
/
Copy pathDbFormExport.dpr
File metadata and controls
61 lines (56 loc) · 1.68 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
program DbFormExport;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Emetra.Logging.PlainText,
Emetra.Database.Simple,
Emetra.Utils.Params,
Emetra.Logging.Interfaces,
Emetra.Database.ConnectionString,
System.SysUtils, System.StrUtils,
FormExport.SqlGenerator in 'FormExport.SqlGenerator.pas';
var
db: TSimpleDatabase;
formDumper: TFormDumper;
prm: TParamList;
formId: integer;
ageInfo: char;
begin
prm := TParamList.CreateFromCommandLine;
WriteLn( '/* Form Export Utility v1.11, DIPS AS 2022 */' );
formId := StrToIntDef( ParamStr( 1 ), 0 );
ageInfo := AnsiUppercase( prm.ReadString( 'Age' ) + ' ' )[1];
if formId = 0 then
begin
WriteLn( 'Use the FormId you want to export as the first parameter.' );
WriteLn( 'Add /DoIt to save to a CSV file in current the directory.' );
WriteLn( 'Use parameter Age=(Y|M|D) to include patient age at event.' );
end
else
begin
db := TSimpleDatabase.Create( GlobalLog );
db.ConnectionString := GetFastTrakParentConnection;
formDumper := TFormDumper.Create( db );
case ageInfo of
'Y': formDumper.DateInfo := diAgeYears;
'M': formDumper.DateInfo := diAgeMonths;
'D': formDumper.DateInfo := diAgeDays;
else formDumper.DateInfo := diNone;
end;
try
db.Connect;
WriteLn( formDumper.GeneratePivotSQL( formId ) );
if prm.Switch( 'DoIt' ) then
formDumper.SaveToCSV( formId );
WriteLn;
WriteLn( 'The file ', formDumper.FileName, ' contains ', formDumper.LinesWritten, ' data rows. ' );
db.Disconnect;
except
on E: Exception do
WriteLn( E.ClassName, ': ', E.Message );
end;
formDumper.Free;
db.Free;
end;
prm.Free;
end.