comparison OrthancFramework/UnitTestsSources/FromDcmtkTests.cpp @ 4685:693f049729ba

New versions of Keep(), Remove() and Replace() in DicomModification that use DicomPath
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 08 Jun 2021 18:28:57 +0200
parents 7182f5732480
children ead3b81f4541
comparison
equal deleted inserted replaced
4684:e3810750dc9d 4685:693f049729ba
2445 static const char* PURPOSE_CODE_SEQ = "0040,a170"; 2445 static const char* PURPOSE_CODE_SEQ = "0040,a170";
2446 static const char* REF_IM_SEQ = "0008,1140"; 2446 static const char* REF_IM_SEQ = "0008,1140";
2447 static const char* REF_SOP_CLASS = "0008,1150"; 2447 static const char* REF_SOP_CLASS = "0008,1150";
2448 static const char* REF_SOP_INSTANCE = "0008,1155"; 2448 static const char* REF_SOP_INSTANCE = "0008,1155";
2449 static const char* REL_SERIES_SEQ = "0008,1250"; 2449 static const char* REL_SERIES_SEQ = "0008,1250";
2450 static const char* STUDY_INSTANCE_UID = "0020,000d";
2450 2451
2451 { 2452 {
2452 std::unique_ptr<ParsedDicomFile> dicom(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, "")); 2453 std::unique_ptr<ParsedDicomFile> dicom(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, ""));
2453 2454
2454 Json::Value vv; 2455 Json::Value vv;
2610 2611
2611 ASSERT_EQ("", vv[REF_IM_SEQ][1][REF_SOP_CLASS].asString()); 2612 ASSERT_EQ("", vv[REF_IM_SEQ][1][REF_SOP_CLASS].asString());
2612 ASSERT_EQ("1.2.840.113619.2.176.2025.1499492.7040.1171286241.726", vv[REF_IM_SEQ][1][REF_SOP_INSTANCE].asString()); 2613 ASSERT_EQ("1.2.840.113619.2.176.2025.1499492.7040.1171286241.726", vv[REF_IM_SEQ][1][REF_SOP_INSTANCE].asString());
2613 2614
2614 ASSERT_EQ("", vv[REL_SERIES_SEQ][0][PURPOSE_CODE_SEQ][0][CODE_VALUE].asString()); 2615 ASSERT_EQ("", vv[REL_SERIES_SEQ][0][PURPOSE_CODE_SEQ][0][CODE_VALUE].asString());
2616 }
2617
2618 {
2619 std::unique_ptr<ParsedDicomFile> dicom(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, ""));
2620
2621 {
2622 DicomModification modif;
2623 modif.Replace(DicomPath(DICOM_TAG_PATIENT_NAME), "Hello1", false);
2624 modif.Replace(DicomPath::Parse("ReferencedImageSequence[1].ReferencedSOPClassUID"), "Hello2", false);
2625 modif.Replace(DicomPath::Parse("RelatedSeriesSequence[0].PurposeOfReferenceCodeSequence[0].CodeValue"), "Hello3", false);
2626 modif.Apply(*dicom);
2627 }
2628
2629 Json::Value vv;
2630 dicom->DatasetToJson(vv, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
2631
2632 ASSERT_TRUE(vv.isMember(PATIENT_NAME));
2633 ASSERT_EQ("Hello1", vv[PATIENT_NAME].asString());
2634 ASSERT_EQ("1.2.840.10008.5.1.4.1.1.4", vv[REF_IM_SEQ][0][REF_SOP_CLASS].asString());
2635 ASSERT_EQ("Hello2", vv[REF_IM_SEQ][1][REF_SOP_CLASS].asString());
2636 ASSERT_EQ("Hello3", vv[REL_SERIES_SEQ][0][PURPOSE_CODE_SEQ][0][CODE_VALUE].asString());
2637 ASSERT_EQ(2u, vv[REL_SERIES_SEQ][0].size());
2638 }
2639
2640 {
2641 std::unique_ptr<ParsedDicomFile> dicom(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, ""));
2642
2643 {
2644 DicomModification modif;
2645 modif.Remove(DicomPath(DICOM_TAG_PATIENT_NAME));
2646 modif.Remove(DicomPath::Parse("ReferencedImageSequence[1].ReferencedSOPClassUID"));
2647 modif.Remove(DicomPath::Parse("RelatedSeriesSequence[0].PurposeOfReferenceCodeSequence"));
2648 modif.Apply(*dicom);
2649 }
2650
2651 Json::Value vv;
2652 dicom->DatasetToJson(vv, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
2653
2654 ASSERT_FALSE(vv.isMember(PATIENT_NAME));
2655 ASSERT_EQ(2u, vv[REF_IM_SEQ][0].size());
2656 ASSERT_TRUE(vv[REF_IM_SEQ][0].isMember(REF_SOP_CLASS));
2657 ASSERT_EQ(1u, vv[REF_IM_SEQ][1].size());
2658 ASSERT_FALSE(vv[REF_IM_SEQ][1].isMember(REF_SOP_CLASS));
2659 ASSERT_EQ(1u, vv[REL_SERIES_SEQ][0].size());
2660 }
2661
2662 {
2663 std::unique_ptr<ParsedDicomFile> dicom1(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, ""));
2664 std::unique_ptr<ParsedDicomFile> dicom2(dicom1->Clone(true));
2665
2666 {
2667 DicomModification modif;
2668 modif.SetupAnonymization(DicomVersion_2021b);
2669 modif.Apply(*dicom1);
2670 modif.Apply(*dicom2);
2671 }
2672
2673 // Same anonymization context and same input DICOM => hence, same output DICOM
2674 Json::Value vv1, vv2;
2675 dicom1->DatasetToJson(vv1, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
2676 dicom2->DatasetToJson(vv2, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
2677 ASSERT_EQ(vv1.toStyledString(), vv2.toStyledString());
2678
2679 ASSERT_TRUE(Toolbox::IsUuid(vv1[PATIENT_NAME].asString()));
2680 ASSERT_EQ("1.2.840.10008.5.1.4.1.1.4", vv1[REF_IM_SEQ][0][REF_SOP_CLASS].asString());
2681 ASSERT_NE("1.2.840.113619.2.176.2025.1499492.7040.1171286241.719", vv1[REF_IM_SEQ][0][REF_SOP_INSTANCE].asString());
2682 ASSERT_NE("1.2.840.113619.2.176.2025.1499492.7040.1171286241.726", vv1[REF_IM_SEQ][1][REF_SOP_INSTANCE].asString());
2683 ASSERT_NE("1.2.840.113704.1.111.7016.1342451220.40", vv1[REL_SERIES_SEQ][0][STUDY_INSTANCE_UID].asString());
2684 ASSERT_EQ("WORLD", vv1[REL_SERIES_SEQ][0][PURPOSE_CODE_SEQ][0][PATIENT_NAME].asString());
2685 }
2686
2687 {
2688 std::unique_ptr<ParsedDicomFile> dicom(ParsedDicomFile::CreateFromJson(v, DicomFromJsonFlags_None, ""));
2689
2690 {
2691 DicomModification modif;
2692 modif.SetupAnonymization(DicomVersion_2021b);
2693 modif.Keep(DicomPath::Parse("ReferencedImageSequence[1].ReferencedSOPInstanceUID"));
2694 modif.Keep(DicomPath::Parse("RelatedSeriesSequence"));
2695 modif.Apply(*dicom);
2696 }
2697
2698 Json::Value vv;
2699 dicom->DatasetToJson(vv, DicomToJsonFormat_Short, DicomToJsonFlags_None, 0);
2700
2701 ASSERT_NE("1.2.840.113619.2.176.2025.1499492.7040.1171286241.719", vv[REF_IM_SEQ][0][REF_SOP_INSTANCE].asString());
2702 ASSERT_EQ("1.2.840.113619.2.176.2025.1499492.7040.1171286241.726", vv[REF_IM_SEQ][1][REF_SOP_INSTANCE].asString()); // kept
2703 ASSERT_EQ("1.2.840.113704.1.111.7016.1342451220.40", vv[REL_SERIES_SEQ][0][STUDY_INSTANCE_UID].asString()); // kept
2615 } 2704 }
2616 } 2705 }
2617 2706
2618 2707
2619 2708