Mercurial > hg > orthanc-stone
annotate Resources/Orthanc/Core/Enumerations.cpp @ 47:28956ed68280
agpl license
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 27 Apr 2017 11:00:15 +0200 |
parents | 7207a407bcd8 |
children |
rev | line source |
---|---|
1 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
40
7207a407bcd8
shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
30
diff
changeset
|
5 * Copyright (C) 2017 Osimis, Belgium |
1 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #include "PrecompiledHeaders.h" | |
35 #include "Enumerations.h" | |
36 | |
37 #include "OrthancException.h" | |
38 #include "Toolbox.h" | |
39 #include "Logging.h" | |
40 | |
41 #include <string.h> | |
42 #include <cassert> | |
43 | |
44 namespace Orthanc | |
45 { | |
46 // This function is autogenerated by the script | |
47 // "Resources/GenerateErrorCodes.py" | |
48 const char* EnumerationToString(ErrorCode error) | |
49 { | |
50 switch (error) | |
51 { | |
52 case ErrorCode_InternalError: | |
53 return "Internal error"; | |
54 | |
55 case ErrorCode_Success: | |
56 return "Success"; | |
57 | |
58 case ErrorCode_Plugin: | |
59 return "Error encountered within the plugin engine"; | |
60 | |
61 case ErrorCode_NotImplemented: | |
62 return "Not implemented yet"; | |
63 | |
64 case ErrorCode_ParameterOutOfRange: | |
65 return "Parameter out of range"; | |
66 | |
67 case ErrorCode_NotEnoughMemory: | |
12 | 68 return "The server hosting Orthanc is running out of memory"; |
1 | 69 |
70 case ErrorCode_BadParameterType: | |
71 return "Bad type for a parameter"; | |
72 | |
73 case ErrorCode_BadSequenceOfCalls: | |
74 return "Bad sequence of calls"; | |
75 | |
76 case ErrorCode_InexistentItem: | |
77 return "Accessing an inexistent item"; | |
78 | |
79 case ErrorCode_BadRequest: | |
80 return "Bad request"; | |
81 | |
82 case ErrorCode_NetworkProtocol: | |
83 return "Error in the network protocol"; | |
84 | |
85 case ErrorCode_SystemCommand: | |
86 return "Error while calling a system command"; | |
87 | |
88 case ErrorCode_Database: | |
89 return "Error with the database engine"; | |
90 | |
91 case ErrorCode_UriSyntax: | |
92 return "Badly formatted URI"; | |
93 | |
94 case ErrorCode_InexistentFile: | |
95 return "Inexistent file"; | |
96 | |
97 case ErrorCode_CannotWriteFile: | |
98 return "Cannot write to file"; | |
99 | |
100 case ErrorCode_BadFileFormat: | |
101 return "Bad file format"; | |
102 | |
103 case ErrorCode_Timeout: | |
104 return "Timeout"; | |
105 | |
106 case ErrorCode_UnknownResource: | |
107 return "Unknown resource"; | |
108 | |
109 case ErrorCode_IncompatibleDatabaseVersion: | |
110 return "Incompatible version of the database"; | |
111 | |
112 case ErrorCode_FullStorage: | |
113 return "The file storage is full"; | |
114 | |
115 case ErrorCode_CorruptedFile: | |
116 return "Corrupted file (e.g. inconsistent MD5 hash)"; | |
117 | |
118 case ErrorCode_InexistentTag: | |
119 return "Inexistent tag"; | |
120 | |
121 case ErrorCode_ReadOnly: | |
122 return "Cannot modify a read-only data structure"; | |
123 | |
124 case ErrorCode_IncompatibleImageFormat: | |
125 return "Incompatible format of the images"; | |
126 | |
127 case ErrorCode_IncompatibleImageSize: | |
128 return "Incompatible size of the images"; | |
129 | |
130 case ErrorCode_SharedLibrary: | |
131 return "Error while using a shared library (plugin)"; | |
132 | |
133 case ErrorCode_UnknownPluginService: | |
134 return "Plugin invoking an unknown service"; | |
135 | |
136 case ErrorCode_UnknownDicomTag: | |
137 return "Unknown DICOM tag"; | |
138 | |
139 case ErrorCode_BadJson: | |
140 return "Cannot parse a JSON document"; | |
141 | |
142 case ErrorCode_Unauthorized: | |
143 return "Bad credentials were provided to an HTTP request"; | |
144 | |
145 case ErrorCode_BadFont: | |
146 return "Badly formatted font file"; | |
147 | |
148 case ErrorCode_DatabasePlugin: | |
149 return "The plugin implementing a custom database back-end does not fulfill the proper interface"; | |
150 | |
151 case ErrorCode_StorageAreaPlugin: | |
152 return "Error in the plugin implementing a custom storage area"; | |
153 | |
154 case ErrorCode_EmptyRequest: | |
155 return "The request is empty"; | |
156 | |
157 case ErrorCode_NotAcceptable: | |
158 return "Cannot send a response which is acceptable according to the Accept HTTP header"; | |
159 | |
12 | 160 case ErrorCode_NullPointer: |
161 return "Cannot handle a NULL pointer"; | |
162 | |
1 | 163 case ErrorCode_SQLiteNotOpened: |
164 return "SQLite: The database is not opened"; | |
165 | |
166 case ErrorCode_SQLiteAlreadyOpened: | |
167 return "SQLite: Connection is already open"; | |
168 | |
169 case ErrorCode_SQLiteCannotOpen: | |
170 return "SQLite: Unable to open the database"; | |
171 | |
172 case ErrorCode_SQLiteStatementAlreadyUsed: | |
173 return "SQLite: This cached statement is already being referred to"; | |
174 | |
175 case ErrorCode_SQLiteExecute: | |
176 return "SQLite: Cannot execute a command"; | |
177 | |
178 case ErrorCode_SQLiteRollbackWithoutTransaction: | |
179 return "SQLite: Rolling back a nonexistent transaction (have you called Begin()?)"; | |
180 | |
181 case ErrorCode_SQLiteCommitWithoutTransaction: | |
182 return "SQLite: Committing a nonexistent transaction"; | |
183 | |
184 case ErrorCode_SQLiteRegisterFunction: | |
185 return "SQLite: Unable to register a function"; | |
186 | |
187 case ErrorCode_SQLiteFlush: | |
188 return "SQLite: Unable to flush the database"; | |
189 | |
190 case ErrorCode_SQLiteCannotRun: | |
191 return "SQLite: Cannot run a cached statement"; | |
192 | |
193 case ErrorCode_SQLiteCannotStep: | |
194 return "SQLite: Cannot step over a cached statement"; | |
195 | |
196 case ErrorCode_SQLiteBindOutOfRange: | |
197 return "SQLite: Bing a value while out of range (serious error)"; | |
198 | |
199 case ErrorCode_SQLitePrepareStatement: | |
200 return "SQLite: Cannot prepare a cached statement"; | |
201 | |
202 case ErrorCode_SQLiteTransactionAlreadyStarted: | |
203 return "SQLite: Beginning the same transaction twice"; | |
204 | |
205 case ErrorCode_SQLiteTransactionCommit: | |
206 return "SQLite: Failure when committing the transaction"; | |
207 | |
208 case ErrorCode_SQLiteTransactionBegin: | |
209 return "SQLite: Cannot start a transaction"; | |
210 | |
211 case ErrorCode_DirectoryOverFile: | |
212 return "The directory to be created is already occupied by a regular file"; | |
213 | |
214 case ErrorCode_FileStorageCannotWrite: | |
215 return "Unable to create a subdirectory or a file in the file storage"; | |
216 | |
217 case ErrorCode_DirectoryExpected: | |
218 return "The specified path does not point to a directory"; | |
219 | |
220 case ErrorCode_HttpPortInUse: | |
221 return "The TCP port of the HTTP server is privileged or already in use"; | |
222 | |
223 case ErrorCode_DicomPortInUse: | |
224 return "The TCP port of the DICOM server is privileged or already in use"; | |
225 | |
226 case ErrorCode_BadHttpStatusInRest: | |
227 return "This HTTP status is not allowed in a REST API"; | |
228 | |
229 case ErrorCode_RegularFileExpected: | |
230 return "The specified path does not point to a regular file"; | |
231 | |
232 case ErrorCode_PathToExecutable: | |
233 return "Unable to get the path to the executable"; | |
234 | |
235 case ErrorCode_MakeDirectory: | |
236 return "Cannot create a directory"; | |
237 | |
238 case ErrorCode_BadApplicationEntityTitle: | |
239 return "An application entity title (AET) cannot be empty or be longer than 16 characters"; | |
240 | |
241 case ErrorCode_NoCFindHandler: | |
242 return "No request handler factory for DICOM C-FIND SCP"; | |
243 | |
244 case ErrorCode_NoCMoveHandler: | |
245 return "No request handler factory for DICOM C-MOVE SCP"; | |
246 | |
247 case ErrorCode_NoCStoreHandler: | |
248 return "No request handler factory for DICOM C-STORE SCP"; | |
249 | |
250 case ErrorCode_NoApplicationEntityFilter: | |
251 return "No application entity filter"; | |
252 | |
253 case ErrorCode_NoSopClassOrInstance: | |
254 return "DicomUserConnection: Unable to find the SOP class and instance"; | |
255 | |
256 case ErrorCode_NoPresentationContext: | |
257 return "DicomUserConnection: No acceptable presentation context for modality"; | |
258 | |
259 case ErrorCode_DicomFindUnavailable: | |
260 return "DicomUserConnection: The C-FIND command is not supported by the remote SCP"; | |
261 | |
262 case ErrorCode_DicomMoveUnavailable: | |
263 return "DicomUserConnection: The C-MOVE command is not supported by the remote SCP"; | |
264 | |
265 case ErrorCode_CannotStoreInstance: | |
266 return "Cannot store an instance"; | |
267 | |
268 case ErrorCode_CreateDicomNotString: | |
269 return "Only string values are supported when creating DICOM instances"; | |
270 | |
271 case ErrorCode_CreateDicomOverrideTag: | |
272 return "Trying to override a value inherited from a parent module"; | |
273 | |
274 case ErrorCode_CreateDicomUseContent: | |
275 return "Use \"Content\" to inject an image into a new DICOM instance"; | |
276 | |
277 case ErrorCode_CreateDicomNoPayload: | |
278 return "No payload is present for one instance in the series"; | |
279 | |
280 case ErrorCode_CreateDicomUseDataUriScheme: | |
281 return "The payload of the DICOM instance must be specified according to Data URI scheme"; | |
282 | |
283 case ErrorCode_CreateDicomBadParent: | |
284 return "Trying to attach a new DICOM instance to an inexistent resource"; | |
285 | |
286 case ErrorCode_CreateDicomParentIsInstance: | |
287 return "Trying to attach a new DICOM instance to an instance (must be a series, study or patient)"; | |
288 | |
289 case ErrorCode_CreateDicomParentEncoding: | |
290 return "Unable to get the encoding of the parent resource"; | |
291 | |
292 case ErrorCode_UnknownModality: | |
293 return "Unknown modality"; | |
294 | |
295 case ErrorCode_BadJobOrdering: | |
296 return "Bad ordering of filters in a job"; | |
297 | |
298 case ErrorCode_JsonToLuaTable: | |
299 return "Cannot convert the given JSON object to a Lua table"; | |
300 | |
301 case ErrorCode_CannotCreateLua: | |
302 return "Cannot create the Lua context"; | |
303 | |
304 case ErrorCode_CannotExecuteLua: | |
305 return "Cannot execute a Lua command"; | |
306 | |
307 case ErrorCode_LuaAlreadyExecuted: | |
308 return "Arguments cannot be pushed after the Lua function is executed"; | |
309 | |
310 case ErrorCode_LuaBadOutput: | |
311 return "The Lua function does not give the expected number of outputs"; | |
312 | |
313 case ErrorCode_NotLuaPredicate: | |
314 return "The Lua function is not a predicate (only true/false outputs allowed)"; | |
315 | |
316 case ErrorCode_LuaReturnsNoString: | |
317 return "The Lua function does not return a string"; | |
318 | |
319 case ErrorCode_StorageAreaAlreadyRegistered: | |
320 return "Another plugin has already registered a custom storage area"; | |
321 | |
322 case ErrorCode_DatabaseBackendAlreadyRegistered: | |
323 return "Another plugin has already registered a custom database back-end"; | |
324 | |
325 case ErrorCode_DatabaseNotInitialized: | |
326 return "Plugin trying to call the database during its initialization"; | |
327 | |
328 case ErrorCode_SslDisabled: | |
329 return "Orthanc has been built without SSL support"; | |
330 | |
331 case ErrorCode_CannotOrderSlices: | |
332 return "Unable to order the slices of the series"; | |
333 | |
334 case ErrorCode_NoWorklistHandler: | |
335 return "No request handler factory for DICOM C-Find Modality SCP"; | |
336 | |
337 case ErrorCode_AlreadyExistingTag: | |
338 return "Cannot override the value of a tag that already exists"; | |
339 | |
340 default: | |
341 if (error >= ErrorCode_START_PLUGINS) | |
342 { | |
343 return "Error encountered within some plugin"; | |
344 } | |
345 else | |
346 { | |
347 return "Unknown error code"; | |
348 } | |
349 } | |
350 } | |
351 | |
352 | |
353 const char* EnumerationToString(HttpMethod method) | |
354 { | |
355 switch (method) | |
356 { | |
357 case HttpMethod_Get: | |
358 return "GET"; | |
359 | |
360 case HttpMethod_Post: | |
361 return "POST"; | |
362 | |
363 case HttpMethod_Delete: | |
364 return "DELETE"; | |
365 | |
366 case HttpMethod_Put: | |
367 return "PUT"; | |
368 | |
369 default: | |
370 return "?"; | |
371 } | |
372 } | |
373 | |
374 | |
375 const char* EnumerationToString(HttpStatus status) | |
376 { | |
377 switch (status) | |
378 { | |
379 case HttpStatus_100_Continue: | |
380 return "Continue"; | |
381 | |
382 case HttpStatus_101_SwitchingProtocols: | |
383 return "Switching Protocols"; | |
384 | |
385 case HttpStatus_102_Processing: | |
386 return "Processing"; | |
387 | |
388 case HttpStatus_200_Ok: | |
389 return "OK"; | |
390 | |
391 case HttpStatus_201_Created: | |
392 return "Created"; | |
393 | |
394 case HttpStatus_202_Accepted: | |
395 return "Accepted"; | |
396 | |
397 case HttpStatus_203_NonAuthoritativeInformation: | |
398 return "Non-Authoritative Information"; | |
399 | |
400 case HttpStatus_204_NoContent: | |
401 return "No Content"; | |
402 | |
403 case HttpStatus_205_ResetContent: | |
404 return "Reset Content"; | |
405 | |
406 case HttpStatus_206_PartialContent: | |
407 return "Partial Content"; | |
408 | |
409 case HttpStatus_207_MultiStatus: | |
410 return "Multi-Status"; | |
411 | |
412 case HttpStatus_208_AlreadyReported: | |
413 return "Already Reported"; | |
414 | |
415 case HttpStatus_226_IMUsed: | |
416 return "IM Used"; | |
417 | |
418 case HttpStatus_300_MultipleChoices: | |
419 return "Multiple Choices"; | |
420 | |
421 case HttpStatus_301_MovedPermanently: | |
422 return "Moved Permanently"; | |
423 | |
424 case HttpStatus_302_Found: | |
425 return "Found"; | |
426 | |
427 case HttpStatus_303_SeeOther: | |
428 return "See Other"; | |
429 | |
430 case HttpStatus_304_NotModified: | |
431 return "Not Modified"; | |
432 | |
433 case HttpStatus_305_UseProxy: | |
434 return "Use Proxy"; | |
435 | |
436 case HttpStatus_307_TemporaryRedirect: | |
437 return "Temporary Redirect"; | |
438 | |
439 case HttpStatus_400_BadRequest: | |
440 return "Bad Request"; | |
441 | |
442 case HttpStatus_401_Unauthorized: | |
443 return "Unauthorized"; | |
444 | |
445 case HttpStatus_402_PaymentRequired: | |
446 return "Payment Required"; | |
447 | |
448 case HttpStatus_403_Forbidden: | |
449 return "Forbidden"; | |
450 | |
451 case HttpStatus_404_NotFound: | |
452 return "Not Found"; | |
453 | |
454 case HttpStatus_405_MethodNotAllowed: | |
455 return "Method Not Allowed"; | |
456 | |
457 case HttpStatus_406_NotAcceptable: | |
458 return "Not Acceptable"; | |
459 | |
460 case HttpStatus_407_ProxyAuthenticationRequired: | |
461 return "Proxy Authentication Required"; | |
462 | |
463 case HttpStatus_408_RequestTimeout: | |
464 return "Request Timeout"; | |
465 | |
466 case HttpStatus_409_Conflict: | |
467 return "Conflict"; | |
468 | |
469 case HttpStatus_410_Gone: | |
470 return "Gone"; | |
471 | |
472 case HttpStatus_411_LengthRequired: | |
473 return "Length Required"; | |
474 | |
475 case HttpStatus_412_PreconditionFailed: | |
476 return "Precondition Failed"; | |
477 | |
478 case HttpStatus_413_RequestEntityTooLarge: | |
479 return "Request Entity Too Large"; | |
480 | |
481 case HttpStatus_414_RequestUriTooLong: | |
482 return "Request-URI Too Long"; | |
483 | |
484 case HttpStatus_415_UnsupportedMediaType: | |
485 return "Unsupported Media Type"; | |
486 | |
487 case HttpStatus_416_RequestedRangeNotSatisfiable: | |
488 return "Requested Range Not Satisfiable"; | |
489 | |
490 case HttpStatus_417_ExpectationFailed: | |
491 return "Expectation Failed"; | |
492 | |
493 case HttpStatus_422_UnprocessableEntity: | |
494 return "Unprocessable Entity"; | |
495 | |
496 case HttpStatus_423_Locked: | |
497 return "Locked"; | |
498 | |
499 case HttpStatus_424_FailedDependency: | |
500 return "Failed Dependency"; | |
501 | |
502 case HttpStatus_426_UpgradeRequired: | |
503 return "Upgrade Required"; | |
504 | |
505 case HttpStatus_500_InternalServerError: | |
506 return "Internal Server Error"; | |
507 | |
508 case HttpStatus_501_NotImplemented: | |
509 return "Not Implemented"; | |
510 | |
511 case HttpStatus_502_BadGateway: | |
512 return "Bad Gateway"; | |
513 | |
514 case HttpStatus_503_ServiceUnavailable: | |
515 return "Service Unavailable"; | |
516 | |
517 case HttpStatus_504_GatewayTimeout: | |
518 return "Gateway Timeout"; | |
519 | |
520 case HttpStatus_505_HttpVersionNotSupported: | |
521 return "HTTP Version Not Supported"; | |
522 | |
523 case HttpStatus_506_VariantAlsoNegotiates: | |
524 return "Variant Also Negotiates"; | |
525 | |
526 case HttpStatus_507_InsufficientStorage: | |
527 return "Insufficient Storage"; | |
528 | |
529 case HttpStatus_509_BandwidthLimitExceeded: | |
530 return "Bandwidth Limit Exceeded"; | |
531 | |
532 case HttpStatus_510_NotExtended: | |
533 return "Not Extended"; | |
534 | |
535 default: | |
536 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
537 } | |
538 } | |
539 | |
540 | |
541 const char* EnumerationToString(ResourceType type) | |
542 { | |
543 switch (type) | |
544 { | |
545 case ResourceType_Patient: | |
546 return "Patient"; | |
547 | |
548 case ResourceType_Study: | |
549 return "Study"; | |
550 | |
551 case ResourceType_Series: | |
552 return "Series"; | |
553 | |
554 case ResourceType_Instance: | |
555 return "Instance"; | |
556 | |
557 default: | |
558 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
559 } | |
560 } | |
561 | |
562 | |
563 const char* EnumerationToString(ImageFormat format) | |
564 { | |
565 switch (format) | |
566 { | |
567 case ImageFormat_Png: | |
568 return "Png"; | |
569 | |
570 default: | |
571 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
572 } | |
573 } | |
574 | |
575 | |
576 const char* EnumerationToString(Encoding encoding) | |
577 { | |
578 switch (encoding) | |
579 { | |
580 case Encoding_Ascii: | |
581 return "Ascii"; | |
582 | |
583 case Encoding_Utf8: | |
584 return "Utf8"; | |
585 | |
586 case Encoding_Latin1: | |
587 return "Latin1"; | |
588 | |
589 case Encoding_Latin2: | |
590 return "Latin2"; | |
591 | |
592 case Encoding_Latin3: | |
593 return "Latin3"; | |
594 | |
595 case Encoding_Latin4: | |
596 return "Latin4"; | |
597 | |
598 case Encoding_Latin5: | |
599 return "Latin5"; | |
600 | |
601 case Encoding_Cyrillic: | |
602 return "Cyrillic"; | |
603 | |
604 case Encoding_Windows1251: | |
605 return "Windows1251"; | |
606 | |
607 case Encoding_Arabic: | |
608 return "Arabic"; | |
609 | |
610 case Encoding_Greek: | |
611 return "Greek"; | |
612 | |
613 case Encoding_Hebrew: | |
614 return "Hebrew"; | |
615 | |
616 case Encoding_Thai: | |
617 return "Thai"; | |
618 | |
619 case Encoding_Japanese: | |
620 return "Japanese"; | |
621 | |
622 case Encoding_Chinese: | |
623 return "Chinese"; | |
624 | |
625 default: | |
626 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
627 } | |
628 } | |
629 | |
630 | |
631 const char* EnumerationToString(PhotometricInterpretation photometric) | |
632 { | |
633 switch (photometric) | |
634 { | |
635 case PhotometricInterpretation_RGB: | |
636 return "RGB"; | |
637 | |
638 case PhotometricInterpretation_Monochrome1: | |
639 return "Monochrome1"; | |
640 | |
641 case PhotometricInterpretation_Monochrome2: | |
642 return "Monochrome2"; | |
643 | |
644 case PhotometricInterpretation_ARGB: | |
645 return "ARGB"; | |
646 | |
647 case PhotometricInterpretation_CMYK: | |
648 return "CMYK"; | |
649 | |
650 case PhotometricInterpretation_HSV: | |
651 return "HSV"; | |
652 | |
653 case PhotometricInterpretation_Palette: | |
654 return "Palette color"; | |
655 | |
656 case PhotometricInterpretation_YBRFull: | |
657 return "YBR full"; | |
658 | |
659 case PhotometricInterpretation_YBRFull422: | |
660 return "YBR full 422"; | |
661 | |
662 case PhotometricInterpretation_YBRPartial420: | |
663 return "YBR partial 420"; | |
664 | |
665 case PhotometricInterpretation_YBRPartial422: | |
666 return "YBR partial 422"; | |
667 | |
668 case PhotometricInterpretation_YBR_ICT: | |
669 return "YBR ICT"; | |
670 | |
671 case PhotometricInterpretation_YBR_RCT: | |
672 return "YBR RCT"; | |
673 | |
674 case PhotometricInterpretation_Unknown: | |
675 return "Unknown"; | |
676 | |
677 default: | |
678 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
679 } | |
680 } | |
681 | |
682 | |
683 const char* EnumerationToString(RequestOrigin origin) | |
684 { | |
685 switch (origin) | |
686 { | |
687 case RequestOrigin_Unknown: | |
688 return "Unknown"; | |
689 | |
690 case RequestOrigin_DicomProtocol: | |
691 return "DicomProtocol"; | |
692 | |
693 case RequestOrigin_RestApi: | |
694 return "RestApi"; | |
695 | |
696 case RequestOrigin_Plugins: | |
697 return "Plugins"; | |
698 | |
699 case RequestOrigin_Lua: | |
700 return "Lua"; | |
701 | |
702 default: | |
703 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
704 } | |
705 } | |
706 | |
707 | |
708 const char* EnumerationToString(LogLevel level) | |
709 { | |
710 switch (level) | |
711 { | |
712 case LogLevel_Error: | |
713 return "ERROR"; | |
714 | |
715 case LogLevel_Warning: | |
716 return "WARNING"; | |
717 | |
718 case LogLevel_Info: | |
719 return "INFO"; | |
720 | |
721 case LogLevel_Trace: | |
722 return "TRACE"; | |
723 | |
724 default: | |
725 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
726 } | |
727 } | |
728 | |
729 | |
730 const char* EnumerationToString(PixelFormat format) | |
731 { | |
732 switch (format) | |
733 { | |
734 case PixelFormat_RGB24: | |
735 return "RGB24"; | |
736 | |
737 case PixelFormat_RGBA32: | |
738 return "RGBA32"; | |
739 | |
740 case PixelFormat_BGRA32: | |
741 return "BGRA32"; | |
742 | |
743 case PixelFormat_Grayscale8: | |
744 return "Grayscale (unsigned 8bpp)"; | |
745 | |
746 case PixelFormat_Grayscale16: | |
747 return "Grayscale (unsigned 16bpp)"; | |
748 | |
749 case PixelFormat_SignedGrayscale16: | |
750 return "Grayscale (signed 16bpp)"; | |
751 | |
752 case PixelFormat_Float32: | |
753 return "Grayscale (float 32bpp)"; | |
754 | |
755 default: | |
756 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
757 } | |
758 } | |
759 | |
760 | |
761 Encoding StringToEncoding(const char* encoding) | |
762 { | |
763 std::string s(encoding); | |
764 Toolbox::ToUpperCase(s); | |
765 | |
766 if (s == "UTF8") | |
767 { | |
768 return Encoding_Utf8; | |
769 } | |
770 | |
771 if (s == "ASCII") | |
772 { | |
773 return Encoding_Ascii; | |
774 } | |
775 | |
776 if (s == "LATIN1") | |
777 { | |
778 return Encoding_Latin1; | |
779 } | |
780 | |
781 if (s == "LATIN2") | |
782 { | |
783 return Encoding_Latin2; | |
784 } | |
785 | |
786 if (s == "LATIN3") | |
787 { | |
788 return Encoding_Latin3; | |
789 } | |
790 | |
791 if (s == "LATIN4") | |
792 { | |
793 return Encoding_Latin4; | |
794 } | |
795 | |
796 if (s == "LATIN5") | |
797 { | |
798 return Encoding_Latin5; | |
799 } | |
800 | |
801 if (s == "CYRILLIC") | |
802 { | |
803 return Encoding_Cyrillic; | |
804 } | |
805 | |
806 if (s == "WINDOWS1251") | |
807 { | |
808 return Encoding_Windows1251; | |
809 } | |
810 | |
811 if (s == "ARABIC") | |
812 { | |
813 return Encoding_Arabic; | |
814 } | |
815 | |
816 if (s == "GREEK") | |
817 { | |
818 return Encoding_Greek; | |
819 } | |
820 | |
821 if (s == "HEBREW") | |
822 { | |
823 return Encoding_Hebrew; | |
824 } | |
825 | |
826 if (s == "THAI") | |
827 { | |
828 return Encoding_Thai; | |
829 } | |
830 | |
831 if (s == "JAPANESE") | |
832 { | |
833 return Encoding_Japanese; | |
834 } | |
835 | |
836 if (s == "CHINESE") | |
837 { | |
838 return Encoding_Chinese; | |
839 } | |
840 | |
841 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
842 } | |
843 | |
844 | |
845 ResourceType StringToResourceType(const char* type) | |
846 { | |
847 std::string s(type); | |
848 Toolbox::ToUpperCase(s); | |
849 | |
850 if (s == "PATIENT" || s == "PATIENTS") | |
851 { | |
852 return ResourceType_Patient; | |
853 } | |
854 else if (s == "STUDY" || s == "STUDIES") | |
855 { | |
856 return ResourceType_Study; | |
857 } | |
858 else if (s == "SERIES") | |
859 { | |
860 return ResourceType_Series; | |
861 } | |
862 else if (s == "INSTANCE" || s == "IMAGE" || | |
863 s == "INSTANCES" || s == "IMAGES") | |
864 { | |
865 return ResourceType_Instance; | |
866 } | |
867 | |
868 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
869 } | |
870 | |
871 | |
872 ImageFormat StringToImageFormat(const char* format) | |
873 { | |
874 std::string s(format); | |
875 Toolbox::ToUpperCase(s); | |
876 | |
877 if (s == "PNG") | |
878 { | |
879 return ImageFormat_Png; | |
880 } | |
881 | |
882 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
883 } | |
884 | |
885 | |
886 LogLevel StringToLogLevel(const char *level) | |
887 { | |
888 if (strcmp(level, "ERROR") == 0) | |
889 { | |
890 return LogLevel_Error; | |
891 } | |
892 else if (strcmp(level, "WARNING") == 0) | |
893 { | |
894 return LogLevel_Warning; | |
895 } | |
896 else if (strcmp(level, "INFO") == 0) | |
897 { | |
898 return LogLevel_Info; | |
899 } | |
900 else if (strcmp(level, "TRACE") == 0) | |
901 { | |
902 return LogLevel_Trace; | |
903 } | |
904 else | |
905 { | |
906 throw OrthancException(ErrorCode_InternalError); | |
907 } | |
908 } | |
909 | |
910 | |
911 ValueRepresentation StringToValueRepresentation(const std::string& vr, | |
912 bool throwIfUnsupported) | |
913 { | |
914 if (vr == "AE") | |
915 { | |
916 return ValueRepresentation_ApplicationEntity; | |
917 } | |
918 else if (vr == "AS") | |
919 { | |
920 return ValueRepresentation_AgeString; | |
921 } | |
922 else if (vr == "AT") | |
923 { | |
924 return ValueRepresentation_AttributeTag; | |
925 } | |
926 else if (vr == "CS") | |
927 { | |
928 return ValueRepresentation_CodeString; | |
929 } | |
930 else if (vr == "DA") | |
931 { | |
932 return ValueRepresentation_Date; | |
933 } | |
934 else if (vr == "DS") | |
935 { | |
936 return ValueRepresentation_DecimalString; | |
937 } | |
938 else if (vr == "DT") | |
939 { | |
940 return ValueRepresentation_DateTime; | |
941 } | |
942 else if (vr == "FL") | |
943 { | |
944 return ValueRepresentation_FloatingPointSingle; | |
945 } | |
946 else if (vr == "FD") | |
947 { | |
948 return ValueRepresentation_FloatingPointDouble; | |
949 } | |
950 else if (vr == "IS") | |
951 { | |
952 return ValueRepresentation_IntegerString; | |
953 } | |
954 else if (vr == "LO") | |
955 { | |
956 return ValueRepresentation_LongString; | |
957 } | |
958 else if (vr == "LT") | |
959 { | |
960 return ValueRepresentation_LongText; | |
961 } | |
962 else if (vr == "OB") | |
963 { | |
964 return ValueRepresentation_OtherByte; | |
965 } | |
966 else if (vr == "OD") | |
967 { | |
968 return ValueRepresentation_OtherDouble; | |
969 } | |
970 else if (vr == "OF") | |
971 { | |
972 return ValueRepresentation_OtherFloat; | |
973 } | |
974 else if (vr == "OL") | |
975 { | |
976 return ValueRepresentation_OtherLong; | |
977 } | |
978 else if (vr == "OW") | |
979 { | |
980 return ValueRepresentation_OtherWord; | |
981 } | |
982 else if (vr == "PN") | |
983 { | |
984 return ValueRepresentation_PersonName; | |
985 } | |
986 else if (vr == "SH") | |
987 { | |
988 return ValueRepresentation_ShortString; | |
989 } | |
990 else if (vr == "SL") | |
991 { | |
992 return ValueRepresentation_SignedLong; | |
993 } | |
994 else if (vr == "SQ") | |
995 { | |
996 return ValueRepresentation_Sequence; | |
997 } | |
998 else if (vr == "SS") | |
999 { | |
1000 return ValueRepresentation_SignedShort; | |
1001 } | |
1002 else if (vr == "ST") | |
1003 { | |
1004 return ValueRepresentation_ShortText; | |
1005 } | |
1006 else if (vr == "TM") | |
1007 { | |
1008 return ValueRepresentation_Time; | |
1009 } | |
1010 else if (vr == "UC") | |
1011 { | |
1012 return ValueRepresentation_UnlimitedCharacters; | |
1013 } | |
1014 else if (vr == "UI") | |
1015 { | |
1016 return ValueRepresentation_UniqueIdentifier; | |
1017 } | |
1018 else if (vr == "UL") | |
1019 { | |
1020 return ValueRepresentation_UnsignedLong; | |
1021 } | |
1022 else if (vr == "UN") | |
1023 { | |
1024 return ValueRepresentation_Unknown; | |
1025 } | |
1026 else if (vr == "UR") | |
1027 { | |
1028 return ValueRepresentation_UniversalResource; | |
1029 } | |
1030 else if (vr == "US") | |
1031 { | |
1032 return ValueRepresentation_UnsignedShort; | |
1033 } | |
1034 else if (vr == "UT") | |
1035 { | |
1036 return ValueRepresentation_UnlimitedText; | |
1037 } | |
1038 else | |
1039 { | |
1040 std::string s = "Unsupported value representation encountered: " + vr; | |
1041 | |
1042 if (throwIfUnsupported) | |
1043 { | |
1044 LOG(ERROR) << s; | |
1045 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1046 } | |
1047 else | |
1048 { | |
1049 LOG(INFO) << s; | |
1050 return ValueRepresentation_NotSupported; | |
1051 } | |
1052 } | |
1053 } | |
1054 | |
1055 | |
1056 unsigned int GetBytesPerPixel(PixelFormat format) | |
1057 { | |
1058 switch (format) | |
1059 { | |
1060 case PixelFormat_Grayscale8: | |
1061 return 1; | |
1062 | |
1063 case PixelFormat_Grayscale16: | |
1064 case PixelFormat_SignedGrayscale16: | |
1065 return 2; | |
1066 | |
1067 case PixelFormat_RGB24: | |
1068 return 3; | |
1069 | |
1070 case PixelFormat_RGBA32: | |
1071 case PixelFormat_BGRA32: | |
1072 return 4; | |
1073 | |
1074 case PixelFormat_Float32: | |
1075 assert(sizeof(float) == 4); | |
1076 return 4; | |
1077 | |
1078 default: | |
1079 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1080 } | |
1081 } | |
1082 | |
1083 | |
1084 bool GetDicomEncoding(Encoding& encoding, | |
1085 const char* specificCharacterSet) | |
1086 { | |
30 | 1087 std::string s = Toolbox::StripSpaces(specificCharacterSet); |
1 | 1088 Toolbox::ToUpperCase(s); |
1089 | |
1090 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2 | |
1091 // https://github.com/dcm4che/dcm4che/blob/master/dcm4che-core/src/main/java/org/dcm4che3/data/SpecificCharacterSet.java | |
1092 if (s == "ISO_IR 6" || | |
1093 s == "ISO 2022 IR 6") | |
1094 { | |
30 | 1095 encoding = Encoding_Ascii; |
1096 } | |
1097 else if (s == "ISO_IR 192") | |
1098 { | |
1 | 1099 encoding = Encoding_Utf8; |
1100 } | |
1101 else if (s == "ISO_IR 100" || | |
1102 s == "ISO 2022 IR 100") | |
1103 { | |
1104 encoding = Encoding_Latin1; | |
1105 } | |
1106 else if (s == "ISO_IR 101" || | |
1107 s == "ISO 2022 IR 101") | |
1108 { | |
1109 encoding = Encoding_Latin2; | |
1110 } | |
1111 else if (s == "ISO_IR 109" || | |
1112 s == "ISO 2022 IR 109") | |
1113 { | |
1114 encoding = Encoding_Latin3; | |
1115 } | |
1116 else if (s == "ISO_IR 110" || | |
1117 s == "ISO 2022 IR 110") | |
1118 { | |
1119 encoding = Encoding_Latin4; | |
1120 } | |
1121 else if (s == "ISO_IR 148" || | |
1122 s == "ISO 2022 IR 148") | |
1123 { | |
1124 encoding = Encoding_Latin5; | |
1125 } | |
1126 else if (s == "ISO_IR 144" || | |
1127 s == "ISO 2022 IR 144") | |
1128 { | |
1129 encoding = Encoding_Cyrillic; | |
1130 } | |
1131 else if (s == "ISO_IR 127" || | |
1132 s == "ISO 2022 IR 127") | |
1133 { | |
1134 encoding = Encoding_Arabic; | |
1135 } | |
1136 else if (s == "ISO_IR 126" || | |
1137 s == "ISO 2022 IR 126") | |
1138 { | |
1139 encoding = Encoding_Greek; | |
1140 } | |
1141 else if (s == "ISO_IR 138" || | |
1142 s == "ISO 2022 IR 138") | |
1143 { | |
1144 encoding = Encoding_Hebrew; | |
1145 } | |
1146 else if (s == "ISO_IR 166" || s == "ISO 2022 IR 166") | |
1147 { | |
1148 encoding = Encoding_Thai; | |
1149 } | |
1150 else if (s == "ISO_IR 13" || s == "ISO 2022 IR 13") | |
1151 { | |
1152 encoding = Encoding_Japanese; | |
1153 } | |
1154 else if (s == "GB18030") | |
1155 { | |
1156 encoding = Encoding_Chinese; | |
1157 } | |
1158 /* | |
1159 else if (s == "ISO 2022 IR 149") | |
1160 { | |
1161 TODO | |
1162 } | |
1163 else if (s == "ISO 2022 IR 159") | |
1164 { | |
1165 TODO | |
1166 } | |
1167 else if (s == "ISO 2022 IR 87") | |
1168 { | |
1169 TODO | |
1170 } | |
1171 */ | |
1172 else | |
1173 { | |
1174 return false; | |
1175 } | |
1176 | |
1177 // The encoding was properly detected | |
1178 return true; | |
1179 } | |
1180 | |
1181 | |
1182 ResourceType GetChildResourceType(ResourceType type) | |
1183 { | |
1184 switch (type) | |
1185 { | |
1186 case ResourceType_Patient: | |
1187 return ResourceType_Study; | |
1188 | |
1189 case ResourceType_Study: | |
1190 return ResourceType_Series; | |
1191 | |
1192 case ResourceType_Series: | |
1193 return ResourceType_Instance; | |
1194 | |
1195 default: | |
1196 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1197 } | |
1198 } | |
1199 | |
1200 | |
1201 ResourceType GetParentResourceType(ResourceType type) | |
1202 { | |
1203 switch (type) | |
1204 { | |
1205 case ResourceType_Study: | |
1206 return ResourceType_Patient; | |
1207 | |
1208 case ResourceType_Series: | |
1209 return ResourceType_Study; | |
1210 | |
1211 case ResourceType_Instance: | |
1212 return ResourceType_Series; | |
1213 | |
1214 default: | |
1215 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1216 } | |
1217 } | |
1218 | |
1219 | |
1220 DicomModule GetModule(ResourceType type) | |
1221 { | |
1222 switch (type) | |
1223 { | |
1224 case ResourceType_Patient: | |
1225 return DicomModule_Patient; | |
1226 | |
1227 case ResourceType_Study: | |
1228 return DicomModule_Study; | |
1229 | |
1230 case ResourceType_Series: | |
1231 return DicomModule_Series; | |
1232 | |
1233 default: | |
1234 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1235 } | |
1236 } | |
1237 | |
1238 | |
1239 | |
1240 const char* GetDicomSpecificCharacterSet(Encoding encoding) | |
1241 { | |
1242 // http://dicom.nema.org/medical/dicom/current/output/html/part03.html#sect_C.12.1.1.2 | |
1243 switch (encoding) | |
1244 { | |
30 | 1245 case Encoding_Ascii: |
1246 return "ISO_IR 6"; | |
1247 | |
1 | 1248 case Encoding_Utf8: |
1249 return "ISO_IR 192"; | |
1250 | |
1251 case Encoding_Latin1: | |
1252 return "ISO_IR 100"; | |
1253 | |
1254 case Encoding_Latin2: | |
1255 return "ISO_IR 101"; | |
1256 | |
1257 case Encoding_Latin3: | |
1258 return "ISO_IR 109"; | |
1259 | |
1260 case Encoding_Latin4: | |
1261 return "ISO_IR 110"; | |
1262 | |
1263 case Encoding_Latin5: | |
1264 return "ISO_IR 148"; | |
1265 | |
1266 case Encoding_Cyrillic: | |
1267 return "ISO_IR 144"; | |
1268 | |
1269 case Encoding_Arabic: | |
1270 return "ISO_IR 127"; | |
1271 | |
1272 case Encoding_Greek: | |
1273 return "ISO_IR 126"; | |
1274 | |
1275 case Encoding_Hebrew: | |
1276 return "ISO_IR 138"; | |
1277 | |
1278 case Encoding_Japanese: | |
1279 return "ISO_IR 13"; | |
1280 | |
1281 case Encoding_Chinese: | |
1282 return "GB18030"; | |
1283 | |
1284 case Encoding_Thai: | |
1285 return "ISO_IR 166"; | |
1286 | |
1287 default: | |
1288 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1289 } | |
1290 } | |
1291 | |
1292 | |
1293 // This function is autogenerated by the script | |
1294 // "Resources/GenerateErrorCodes.py" | |
1295 HttpStatus ConvertErrorCodeToHttpStatus(ErrorCode error) | |
1296 { | |
1297 switch (error) | |
1298 { | |
1299 case ErrorCode_Success: | |
1300 return HttpStatus_200_Ok; | |
1301 | |
1302 case ErrorCode_ParameterOutOfRange: | |
1303 return HttpStatus_400_BadRequest; | |
1304 | |
1305 case ErrorCode_BadParameterType: | |
1306 return HttpStatus_400_BadRequest; | |
1307 | |
1308 case ErrorCode_InexistentItem: | |
1309 return HttpStatus_404_NotFound; | |
1310 | |
1311 case ErrorCode_BadRequest: | |
1312 return HttpStatus_400_BadRequest; | |
1313 | |
1314 case ErrorCode_UriSyntax: | |
1315 return HttpStatus_400_BadRequest; | |
1316 | |
1317 case ErrorCode_InexistentFile: | |
1318 return HttpStatus_404_NotFound; | |
1319 | |
1320 case ErrorCode_BadFileFormat: | |
1321 return HttpStatus_400_BadRequest; | |
1322 | |
1323 case ErrorCode_UnknownResource: | |
1324 return HttpStatus_404_NotFound; | |
1325 | |
1326 case ErrorCode_InexistentTag: | |
1327 return HttpStatus_404_NotFound; | |
1328 | |
1329 case ErrorCode_BadJson: | |
1330 return HttpStatus_400_BadRequest; | |
1331 | |
1332 case ErrorCode_Unauthorized: | |
1333 return HttpStatus_401_Unauthorized; | |
1334 | |
1335 case ErrorCode_NotAcceptable: | |
1336 return HttpStatus_406_NotAcceptable; | |
1337 | |
1338 default: | |
1339 return HttpStatus_500_InternalServerError; | |
1340 } | |
1341 } | |
1342 | |
1343 | |
1344 bool IsUserContentType(FileContentType type) | |
1345 { | |
1346 return (type >= FileContentType_StartUser && | |
1347 type <= FileContentType_EndUser); | |
1348 } | |
1349 | |
1350 | |
1351 bool IsBinaryValueRepresentation(ValueRepresentation vr) | |
1352 { | |
1353 // http://dicom.nema.org/medical/dicom/current/output/chtml/part05/sect_6.2.html | |
1354 | |
1355 switch (vr) | |
1356 { | |
1357 case ValueRepresentation_ApplicationEntity: // AE | |
1358 case ValueRepresentation_AgeString: // AS | |
1359 case ValueRepresentation_CodeString: // CS | |
1360 case ValueRepresentation_Date: // DA | |
1361 case ValueRepresentation_DecimalString: // DS | |
1362 case ValueRepresentation_DateTime: // DT | |
1363 case ValueRepresentation_IntegerString: // IS | |
1364 case ValueRepresentation_LongString: // LO | |
1365 case ValueRepresentation_LongText: // LT | |
1366 case ValueRepresentation_PersonName: // PN | |
1367 case ValueRepresentation_ShortString: // SH | |
1368 case ValueRepresentation_ShortText: // ST | |
1369 case ValueRepresentation_Time: // TM | |
1370 case ValueRepresentation_UnlimitedCharacters: // UC | |
1371 case ValueRepresentation_UniqueIdentifier: // UI (UID) | |
1372 case ValueRepresentation_UniversalResource: // UR (URI or URL) | |
1373 case ValueRepresentation_UnlimitedText: // UT | |
1374 { | |
1375 return false; | |
1376 } | |
1377 | |
1378 /** | |
1379 * Below are all the VR whose character repertoire is tagged as | |
1380 * "not applicable" | |
1381 **/ | |
1382 case ValueRepresentation_AttributeTag: // AT (2 x uint16_t) | |
1383 case ValueRepresentation_FloatingPointSingle: // FL (float) | |
1384 case ValueRepresentation_FloatingPointDouble: // FD (double) | |
1385 case ValueRepresentation_OtherByte: // OB | |
1386 case ValueRepresentation_OtherDouble: // OD | |
1387 case ValueRepresentation_OtherFloat: // OF | |
1388 case ValueRepresentation_OtherLong: // OL | |
1389 case ValueRepresentation_OtherWord: // OW | |
1390 case ValueRepresentation_SignedLong: // SL (int32_t) | |
1391 case ValueRepresentation_Sequence: // SQ | |
1392 case ValueRepresentation_SignedShort: // SS (int16_t) | |
1393 case ValueRepresentation_UnsignedLong: // UL (uint32_t) | |
1394 case ValueRepresentation_Unknown: // UN | |
1395 case ValueRepresentation_UnsignedShort: // US (uint16_t) | |
1396 { | |
1397 return true; | |
1398 } | |
1399 | |
1400 case ValueRepresentation_NotSupported: | |
1401 default: | |
1402 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
1403 } | |
1404 } | |
1405 } |