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