forked from ElvishArtisan/rivendell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_bmiemr.cpp
152 lines (132 loc) · 3.84 KB
/
export_bmiemr.cpp
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
// export_bmiemr.cpp
//
// Export a Rivendell Report to BMI EMR Format
//
// (C) Copyright 2002-2021 Fred Gleason <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// 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, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include <stdio.h>
#include <QFile>
#include <QTextStream>
#include <rdcart.h>
#include <rddb.h>
#include <rddatedecode.h>
#include <rdescape_string.h>
#include <rdreport.h>
bool RDReport::ExportBmiEmr(const QString &filename,const QDate &startdate,
const QDate &enddate,const QString &mixtable)
{
QString sql;
RDSqlQuery *q;
int records=0;
QDateTime current_datetime=
QDateTime(QDate::currentDate(),QTime::currentTime());
QString type_code;
QString usage_code;
QString station_format=stationFormat();
QFile *file=new QFile(filename);
if(!file->open(QIODevice::WriteOnly|QIODevice::Truncate)) {
report_error_code=RDReport::ErrorCantOpen;
delete file;
return false;
}
QTextStream *strm=new QTextStream(file);
strm->setCodec("UTF-8");
//
// Station Type
//
switch(stationType()) {
case RDReport::TypeAm:
type_code="AM";
break;
case RDReport::TypeFm:
type_code="FM";
break;
default:
type_code="OT";
break;
}
sql=QString("select ")+
"`EVENT_DATETIME`,"+ // 00
"`TITLE`,"+ // 01
"`ARTIST`,"+ // 02
"`COMPOSER`,"+ // 03
"`LENGTH`,"+ // 04
"`ISRC`,"+ // 05
"`USAGE_CODE` "+ // 06
"from `ELR_LINES` where "+
"`SERVICE_NAME`='"+RDEscapeString(mixtable)+"' "+
"order by `EVENT_DATETIME`";
q=new RDSqlQuery(sql);
//
// Write HEDR Record
//
*strm << QString("HEDRSTA")+RDReport::leftJustify(stationId(),25)+
RDReport::leftJustify(current_datetime.toString("yyyyMMddhhmmssyyyyMMdd"),22)+
"FMDT \x0d\x0a";
records++;
//
// Write FMDT Records
//
while(q->next()) {
switch((RDCart::UsageCode)q->value(6).toInt()) {
case RDCart::UsageFeature:
usage_code="F1";
break;
case RDCart::UsageOpen:
usage_code="TO";
break;
case RDCart::UsageClose:
usage_code="TC";
break;
case RDCart::UsageTheme:
usage_code="TT";
break;
case RDCart::UsageBackground:
usage_code="B ";
break;
case RDCart::UsagePromo:
usage_code="JP";
break;
default:
usage_code="F1";
break;
}
*strm << QString("FMDT")+
RDReport::leftJustify(stationId(),40)+
type_code+
RDReport::leftJustify(station_format,25)+
startdate.toString("yyyyMM")+"01"+
RDReport::leftJustify(q->value(0).toDateTime().toString("yyyyMMddhh:mm:ss"),16)+
"000000001"+
RDReport::leftJustify(q->value(1).toString(),40)+
RDReport::leftJustify(q->value(2).toString(),40)+
RDReport::leftJustify(q->value(3).toString(),40)+
QTime(0,0,0).addMSecs(q->value(4).toInt()).toString("hh:mm:ss")+" "+
RDReport::rightJustify(q->value(5).toString(),12)+
usage_code+" \x0d\x0a";
records++;
}
delete q;
//
// Write TRLR Record
//
*strm << QString("TRLR")+
QString::asprintf("%012d \x0d\x0a",++records);
delete strm;
delete file;
report_error_code=RDReport::ErrorOk;
return true;
}