comparison Plugins/Engine/OrthancPlugins.cpp @ 1821:580951a33583

OrthancPluginDicomFromJson
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 24 Nov 2015 17:46:32 +0100
parents 9a6de24209cf
children f0f8a94c0858
comparison
equal deleted inserted replaced
1820:2d8191b13567 1821:580951a33583
412 } 412 }
413 413
414 414
415 OrthancPlugins::OrthancPlugins() 415 OrthancPlugins::OrthancPlugins()
416 { 416 {
417 /* Sanity check of the compiler */
417 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) || 418 if (sizeof(int32_t) != sizeof(OrthancPluginErrorCode) ||
418 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) || 419 sizeof(int32_t) != sizeof(OrthancPluginHttpMethod) ||
419 sizeof(int32_t) != sizeof(_OrthancPluginService) || 420 sizeof(int32_t) != sizeof(_OrthancPluginService) ||
420 sizeof(int32_t) != sizeof(_OrthancPluginProperty) || 421 sizeof(int32_t) != sizeof(_OrthancPluginProperty) ||
421 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) || 422 sizeof(int32_t) != sizeof(OrthancPluginPixelFormat) ||
425 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) || 426 sizeof(int32_t) != sizeof(OrthancPluginImageFormat) ||
426 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) || 427 sizeof(int32_t) != sizeof(OrthancPluginCompressionType) ||
427 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) || 428 sizeof(int32_t) != sizeof(OrthancPluginValueRepresentation) ||
428 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) || 429 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFlags) ||
429 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) || 430 sizeof(int32_t) != sizeof(OrthancPluginDicomToJsonFormat) ||
431 sizeof(int32_t) != sizeof(OrthancPluginDicomFromJsonFlags) ||
430 sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType) || 432 sizeof(int32_t) != sizeof(_OrthancPluginDatabaseAnswerType) ||
431 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) || 433 sizeof(int32_t) != sizeof(OrthancPluginIdentifierConstraint) ||
432 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) || 434 sizeof(int32_t) != sizeof(OrthancPluginInstanceOrigin) ||
433 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeBinary) != static_cast<int>(DicomToJsonFlags_IncludeBinary) || 435 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeBinary) != static_cast<int>(DicomToJsonFlags_IncludeBinary) ||
434 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePrivateTags) != static_cast<int>(DicomToJsonFlags_IncludePrivateTags) || 436 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePrivateTags) != static_cast<int>(DicomToJsonFlags_IncludePrivateTags) ||
435 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeUnknownTags) != static_cast<int>(DicomToJsonFlags_IncludeUnknownTags) || 437 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludeUnknownTags) != static_cast<int>(DicomToJsonFlags_IncludeUnknownTags) ||
436 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePixelData) != static_cast<int>(DicomToJsonFlags_IncludePixelData) || 438 static_cast<int>(OrthancPluginDicomToJsonFlags_IncludePixelData) != static_cast<int>(DicomToJsonFlags_IncludePixelData) ||
437 static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToNull) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToNull) || 439 static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToNull) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToNull) ||
438 static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToAscii)) 440 static_cast<int>(OrthancPluginDicomToJsonFlags_ConvertBinaryToAscii) != static_cast<int>(DicomToJsonFlags_ConvertBinaryToAscii) ||
439 { 441 static_cast<int>(OrthancPluginDicomFromJsonFlags_DecodeDataUriScheme) != static_cast<int>(DicomFromJsonFlags_DecodeDataUriScheme) ||
440 /* Sanity check of the compiler */ 442 static_cast<int>(OrthancPluginDicomFromJsonFlags_GenerateIdentifiers) != static_cast<int>(DicomFromJsonFlags_GenerateIdentifiers))
443
444 {
441 throw OrthancException(ErrorCode_Plugin); 445 throw OrthancException(ErrorCode_Plugin);
442 } 446 }
443 447
444 pimpl_.reset(new PImpl()); 448 pimpl_.reset(new PImpl());
445 pimpl_->manager_.RegisterServiceProvider(*this); 449 pimpl_->manager_.RegisterServiceProvider(*this);
1411 Json::FastWriter writer; 1415 Json::FastWriter writer;
1412 *p.result = CopyString(writer.write(json)); 1416 *p.result = CopyString(writer.write(json));
1413 } 1417 }
1414 1418
1415 1419
1420 void OrthancPlugins::ApplyDicomFromJson(_OrthancPluginService service,
1421 const void* parameters)
1422 {
1423 const _OrthancPluginDicomFromJson& p =
1424 *reinterpret_cast<const _OrthancPluginDicomFromJson*>(parameters);
1425
1426 Json::Value json;
1427 Json::Reader reader;
1428 if (!reader.parse(p.json, json))
1429 {
1430 throw OrthancException(ErrorCode_BadJson);
1431 }
1432
1433 std::string dicom;
1434
1435 {
1436 std::auto_ptr<ParsedDicomFile> file
1437 (ParsedDicomFile::CreateFromJson(json, static_cast<DicomFromJsonFlags>(p.flags)));
1438 file->SaveToMemoryBuffer(dicom);
1439 }
1440
1441 CopyToMemoryBuffer(*p.target, dicom);
1442 }
1443
1444
1416 void OrthancPlugins::DatabaseAnswer(const void* parameters) 1445 void OrthancPlugins::DatabaseAnswer(const void* parameters)
1417 { 1446 {
1418 const _OrthancPluginDatabaseAnswer& p = 1447 const _OrthancPluginDatabaseAnswer& p =
1419 *reinterpret_cast<const _OrthancPluginDatabaseAnswer*>(parameters); 1448 *reinterpret_cast<const _OrthancPluginDatabaseAnswer*>(parameters);
1420 1449
1936 case _OrthancPluginService_DicomBufferToJson: 1965 case _OrthancPluginService_DicomBufferToJson:
1937 case _OrthancPluginService_DicomInstanceToJson: 1966 case _OrthancPluginService_DicomInstanceToJson:
1938 ApplyDicomToJson(service, parameters); 1967 ApplyDicomToJson(service, parameters);
1939 return true; 1968 return true;
1940 1969
1970 case _OrthancPluginService_DicomFromJson:
1971 ApplyDicomFromJson(service, parameters);
1972 return true;
1973
1941 case _OrthancPluginService_WorklistAddAnswer: 1974 case _OrthancPluginService_WorklistAddAnswer:
1942 { 1975 {
1943 const _OrthancPluginWorklistAnswersOperation& p = 1976 const _OrthancPluginWorklistAnswersOperation& p =
1944 *reinterpret_cast<const _OrthancPluginWorklistAnswersOperation*>(parameters); 1977 *reinterpret_cast<const _OrthancPluginWorklistAnswersOperation*>(parameters);
1945 reinterpret_cast<const WorklistHandler*>(p.query)->AddAnswer(p.answers, p.dicom, p.size); 1978 reinterpret_cast<const WorklistHandler*>(p.query)->AddAnswer(p.answers, p.dicom, p.size);