forked from tryphon/rivendell2-debian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_bmiemr.cpp
149 lines (130 loc) · 3.78 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
// export_bmiemr.cpp
//
// Export a Rivendell Report to BMI EMR Format
//
// (C) Copyright 2002-2006 Fred Gleason <[email protected]>
//
// $Id: export_bmiemr.cpp,v 1.10.8.1.2.1 2014/03/19 23:50:20 cvs Exp $
//
// 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 <rddb.h>
#include <rddatedecode.h>
#include <rdreport.h>
#include <rdcart.h>
bool RDReport::ExportBmiEmr(const QDate &startdate,const QDate &enddate,
const QString &mixtable)
{
QString sql;
RDSqlQuery *q;
FILE *f;
int records=0;
QDateTime current_datetime=
QDateTime(QDate::currentDate(),QTime::currentTime());
QString type_code;
QString usage_code;
QString station_format=stationFormat();
#ifdef WIN32
QString filename=RDDateDecode(exportPath(RDReport::Windows),startdate);
#else
QString filename=RDDateDecode(exportPath(RDReport::Linux),startdate);
#endif
//
// Station Type
//
switch(stationType()) {
case RDReport::TypeAm:
type_code="AM";
break;
case RDReport::TypeFm:
type_code="FM";
break;
default:
type_code="OT";
break;
}
if((f=fopen((const char *)filename,"wb"))==NULL) {
report_error_code=RDReport::ErrorCantOpen;
return false;
}
/*
sql=QString().sprintf("select EVENT_DATETIME,TITLE,ARTIST,COMPOSER,\
LENGTH,ISRC,USAGE_CODE from `%s_SRT` \
order by EVENT_DATETIME",
(const char *)mixtable);
*/
sql=QString("select EVENT_DATETIME,TITLE,ARTIST,COMPOSER,")+
"LENGTH,ISRC,USAGE_CODE from `"+
mixtable+"_SRT` order by EVENT_DATETIME";
q=new RDSqlQuery(sql);
//
// Write HEDR Record
//
fprintf(f,"HEDRSTA%-25s%22sFMDT \x0d\x0a",
(const char *)stationId().utf8(),
(const char *)current_datetime.toString("yyyyMMddhhmmssyyyyMMdd"));
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;
}
fprintf(f,"FMDT%-40s%2s%-25s%6s01%14s000000001%-40s%-40s%-40s%8s %12s%2s \x0d\x0a",
(const char *)stationId().utf8(),
(const char *)type_code.utf8(),
(const char *)station_format.utf8(),
(const char *)startdate.toString("yyyyMM"),
(const char *)q->value(0).toDateTime().
toString("yyyyMMddhh:mm:ss"),
(const char *)q->value(1).toString().utf8(),
(const char *)q->value(2).toString().utf8(),
(const char *)q->value(3).toString().utf8(),
(const char *)QTime().addMSecs(q->value(4).toInt()).
toString("hh:mm:ss"),
(const char *)q->value(5).toString().utf8(),
(const char *)usage_code.utf8());
records++;
}
delete q;
//
// Write TRLR Record
//
fprintf(f,"TRLR%012d \x0d\x0a",++records);
fclose(f);
report_error_code=RDReport::ErrorOk;
return true;
}