comparison OrthancServer/OrthancRestApi/OrthancRestAnonymizeModify.cpp @ 3691:4922bdd046dd

Fix issue #140 (Modifying private tags with REST API changes VR from LO to UN) - DANGEROUS COMMIT
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Feb 2020 21:44:09 +0100
parents 94f4a18a79cc
children 1f4910999fe7
comparison
equal deleted inserted replaced
3690:a9ce35d67c3c 3691:4922bdd046dd
265 } 265 }
266 266
267 267
268 static void InjectTags(ParsedDicomFile& dicom, 268 static void InjectTags(ParsedDicomFile& dicom,
269 const Json::Value& tags, 269 const Json::Value& tags,
270 bool decodeBinaryTags) 270 bool decodeBinaryTags,
271 const std::string& privateCreator)
271 { 272 {
272 if (tags.type() != Json::objectValue) 273 if (tags.type() != Json::objectValue)
273 { 274 {
274 throw OrthancException(ErrorCode_BadRequest, "Tags field is not an array"); 275 throw OrthancException(ErrorCode_BadRequest, "Tags field is not an array");
275 } 276 }
303 { 304 {
304 throw OrthancException(ErrorCode_CreateDicomUseContent); 305 throw OrthancException(ErrorCode_CreateDicomUseContent);
305 } 306 }
306 else 307 else
307 { 308 {
308 dicom.Replace(tag, tags[name], decodeBinaryTags, DicomReplaceMode_InsertIfAbsent); 309 dicom.Replace(tag, tags[name], decodeBinaryTags, DicomReplaceMode_InsertIfAbsent, privateCreator);
309 } 310 }
310 } 311 }
311 } 312 }
312 } 313 }
313 314
314 315
315 static void CreateSeries(RestApiPostCall& call, 316 static void CreateSeries(RestApiPostCall& call,
316 ParsedDicomFile& base /* in */, 317 ParsedDicomFile& base /* in */,
317 const Json::Value& content, 318 const Json::Value& content,
318 bool decodeBinaryTags) 319 bool decodeBinaryTags,
320 const std::string& privateCreator)
319 { 321 {
320 assert(content.isArray()); 322 assert(content.isArray());
321 assert(content.size() > 0); 323 assert(content.size() > 0);
322 ServerContext& context = OrthancRestApi::GetContext(call); 324 ServerContext& context = OrthancRestApi::GetContext(call);
323 325
346 348
347 payload = &content[i]["Content"]; 349 payload = &content[i]["Content"];
348 350
349 if (content[i].isMember("Tags")) 351 if (content[i].isMember("Tags"))
350 { 352 {
351 InjectTags(*dicom, content[i]["Tags"], decodeBinaryTags); 353 InjectTags(*dicom, content[i]["Tags"], decodeBinaryTags, privateCreator);
352 } 354 }
353 } 355 }
354 356
355 if (payload == NULL || 357 if (payload == NULL ||
356 payload->type() != Json::stringValue) 358 payload->type() != Json::stringValue)
536 } 538 }
537 539
538 decodeBinaryTags = v.asBool(); 540 decodeBinaryTags = v.asBool();
539 } 541 }
540 542
543
544 // New argument in Orthanc 1.6.0
545 std::string privateCreator;
546 if (request.isMember("PrivateCreator"))
547 {
548 const Json::Value& v = request["PrivateCreator"];
549 if (v.type() != Json::stringValue)
550 {
551 throw OrthancException(ErrorCode_BadRequest);
552 }
553
554 privateCreator = v.asString();
555 }
556
541 557
542 // Inject time-related information 558 // Inject time-related information
543 std::string date, time; 559 std::string date, time;
544 SystemToolbox::GetNowDicom(date, time, true /* use UTC time (not local time) */); 560 SystemToolbox::GetNowDicom(date, time, true /* use UTC time (not local time) */);
545 dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_DATE, date); 561 dicom.ReplacePlainString(DICOM_TAG_ACQUISITION_DATE, date);
563 dicom.ReplacePlainString(DICOM_TAG_STUDY_DATE, date); 579 dicom.ReplacePlainString(DICOM_TAG_STUDY_DATE, date);
564 dicom.ReplacePlainString(DICOM_TAG_STUDY_TIME, time); 580 dicom.ReplacePlainString(DICOM_TAG_STUDY_TIME, time);
565 } 581 }
566 582
567 583
568 InjectTags(dicom, request["Tags"], decodeBinaryTags); 584 InjectTags(dicom, request["Tags"], decodeBinaryTags, privateCreator);
569 585
570 586
571 // Inject the content (either an image, or a PDF file) 587 // Inject the content (either an image, or a PDF file)
572 if (request.isMember("Content")) 588 if (request.isMember("Content"))
573 { 589 {
581 else if (content.type() == Json::arrayValue) 597 else if (content.type() == Json::arrayValue)
582 { 598 {
583 if (content.size() > 0) 599 if (content.size() > 0)
584 { 600 {
585 // Let's create a series instead of a single instance 601 // Let's create a series instead of a single instance
586 CreateSeries(call, dicom, content, decodeBinaryTags); 602 CreateSeries(call, dicom, content, decodeBinaryTags, privateCreator);
587 return; 603 return;
588 } 604 }
589 } 605 }
590 else 606 else
591 { 607 {