-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.cpp
154 lines (130 loc) · 3.77 KB
/
helper.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
152
153
154
#include "dcmtk/dcmdata/dcuid.h"
#include "global.h"
#include "runtime.h"
#include "settings.h"
#include "helper.h"
QString Helper::getAETfromTagsFile(QFileInfo currentFile)
{
QString filePath=currentFile.absolutePath() + "/" + currentFile.completeBaseName() + ".tags";
QFile tagsFile(filePath);
if (!tagsFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
OUT("ERROR: Unable to open tags file")
return "";
}
QByteArray data = tagsFile.readAll();
tagsFile.close();
QJsonParseError errorPtr;
QJsonDocument doc = QJsonDocument::fromJson(data, &errorPtr);
if (doc.isNull())
{
OUT("ERROR: Unable to parse tags file")
return "";
}
QJsonObject root = doc.object();
if (!root.contains("ReceiverAET"))
{
OUT("ERROR: Invalid tags file (ReceiverAET not found)")
return "";
}
// Convert the AET to lower case to avoid problems with capitalization
return root.value("ReceiverAET").toString().toLower();
}
QString Helper::getACCfromTagsFile(QFileInfo currentFile)
{
QString filePath=currentFile.absolutePath() + "/" + currentFile.completeBaseName() + ".tags";
QFile tagsFile(filePath);
if (!tagsFile.open(QIODevice::ReadOnly | QIODevice::Text))
{
OUT("ERROR: Unable to open tags file")
return "";
}
QByteArray data = tagsFile.readAll();
tagsFile.close();
QJsonParseError errorPtr;
QJsonDocument doc = QJsonDocument::fromJson(data, &errorPtr);
if (doc.isNull())
{
OUT("ERROR: Unable to parse tags file")
return "";
}
QJsonObject root = doc.object();
if (!root.contains("AccessionNumber"))
{
OUT("ERROR: Invalid tags file (AccessionNumber not found)")
return "";
}
// Convert the Accession Number to lower case to avoid problems with capitalization
return root.value("AccessionNumber").toString().toLower();
}
void Helper::generateStudyUID()
{
char uid[100];
dcmGenerateUniqueIdentifier(uid, SITE_STUDY_UID_ROOT);
RTI->newStudyUID=QString(uid);
}
void Helper::generateSeriesUID()
{
char uid[100];
dcmGenerateUniqueIdentifier(uid, SITE_SERIES_UID_ROOT);
RTI->newSeriesUID=QString(uid);
}
void Helper::generateInstanceUID()
{
char uid[100];
dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
RTI->newInstanceUID=QString(uid);
}
void Helper::generateRandomUID()
{
char uid[100];
dcmGenerateUniqueIdentifier(uid, SITE_INSTANCE_UID_ROOT);
RTI->randomUID=QString(uid);
}
#define GREEK_ALPHABET_COUNT 24
static QString greek_alphabet[]
{
"Alpha",
"Beta",
"Gamma",
"Delta",
"Epsilon",
"Zeta",
"Eta",
"Theta",
"Iota",
"Kappa",
"Lambda",
"Mu",
"Nu",
"Xi",
"Omicron",
"Pi",
"Rho",
"Sigma",
"Tau",
"Upsilon",
"Phi",
"Chi",
"Psi",
"Omega"
};
QString Helper::getFakeName()
{
int firstIndex = QRandomGenerator::global()->bounded(0, GREEK_ALPHABET_COUNT);
int lastIndex = QRandomGenerator::global()->bounded(0, GREEK_ALPHABET_COUNT);
return QString(greek_alphabet[lastIndex] + "^" + greek_alphabet[firstIndex] + "^^^");
}
QString Helper::getFakeMRN()
{
// Generate a integer number from the time, ensuring that the number always increases
QDateTime refDate(QDate(2020, 1, 1), QTime(0, 0, 0));
return QString::number(QDateTime::currentMSecsSinceEpoch()-refDate.toMSecsSinceEpoch());
}
QString Helper::getFakeACC()
{
// Generate a integer number from the time, ensuring that the number always increases
// A different offset is used for the ACC and MRN to get two different numbers
QDateTime refDate(QDate(2013, 4, 12), QTime(11, 13, 33));
return QString::number(QDateTime::currentMSecsSinceEpoch()-refDate.toMSecsSinceEpoch());
}