comparison Tests/Tests.py @ 424:934f505677da Orthanc-1.9.5

test_anonymize_nested
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 06 Jul 2021 08:07:06 +0200
parents cef3847dc8af
children 77455e156112
comparison
equal deleted inserted replaced
423:cef3847dc8af 424:934f505677da
6968 6968
6969 # The expected result can be found by typing "dcm2json Database/Issue195-bis.dcm" 6969 # The expected result can be found by typing "dcm2json Database/Issue195-bis.dcm"
6970 self.assertEqual(5, len(b)) 6970 self.assertEqual(5, len(b))
6971 self.assertEqual(2, len(b["00080018"])) 6971 self.assertEqual(2, len(b["00080018"]))
6972 self.assertEqual("UI", b["00080018"]["vr"]) 6972 self.assertEqual("UI", b["00080018"]["vr"])
6973 self.assertEqual("1.2.276.0.7230010.3.1.4.8323329.23653.1620311964.865420", 6973 self.assertEqual("1.2.276.0.7230010.3.1.4.8323329.6792.1625504071.652470",
6974 b["00080018"]["Value"][0]) 6974 b["00080018"]["Value"][0])
6975 6975
6976 self.assertEqual(2, len(b["0020000D"])) 6976 self.assertEqual(2, len(b["0020000D"]))
6977 self.assertEqual("UI", b["0020000D"]["vr"]) 6977 self.assertEqual("UI", b["0020000D"]["vr"])
6978 self.assertEqual("1.2.276.0.7230010.3.1.2.8323329.23653.1620311964.865418", 6978 self.assertEqual("1.2.276.0.7230010.3.1.2.8323329.6792.1625504071.652468",
6979 b["0020000D"]["Value"][0]) 6979 b["0020000D"]["Value"][0])
6980 6980
6981 self.assertEqual(2, len(b["0020000E"])) 6981 self.assertEqual(2, len(b["0020000E"]))
6982 self.assertEqual("UI", b["0020000E"]["vr"]) 6982 self.assertEqual("UI", b["0020000E"]["vr"])
6983 self.assertEqual("1.2.276.0.7230010.3.1.3.8323329.23653.1620311964.865419", 6983 self.assertEqual("1.2.276.0.7230010.3.1.3.8323329.6792.1625504071.652469",
6984 b["0020000E"]["Value"][0]) 6984 b["0020000E"]["Value"][0])
6985 6985
6986 self.assertEqual(2, len(b["0008103E"])) 6986 self.assertEqual(2, len(b["00084567"]))
6987 self.assertEqual("UN", b["0008103E"]["vr"]) 6987 self.assertEqual("UN", b["00084567"]["vr"])
6988 6988
6989 # NB: "QgA=" corresponds to the base64 encoding of (uint16_t) 0x42 in little endian: 6989 # NB: "QgA=" corresponds to the base64 encoding of (uint16_t) 0x42 in little endian:
6990 # $ echo -n 'QgA=' | base64 -d | hexdump -C 6990 # $ echo -n 'QgA=' | base64 -d | hexdump -C
6991 self.assertEqual("QgA=", b["0008103E"]["InlineBinary"]) 6991 self.assertEqual("QgA=", b["00084567"]["InlineBinary"])
6992 6992
6993 # Case of an empty value, fails in Orthanc <= 1.9.2 because of issue #195 6993 # Case of an empty value, fails in Orthanc <= 1.9.2 because of issue #195
6994 self.assertEqual(1, len(b["00081030"])) 6994 self.assertEqual(1, len(b["00084565"]))
6995 self.assertEqual("UN", b["00081030"]["vr"]) 6995 self.assertEqual("UN", b["00084565"]["vr"])
6996 6996
6997 6997
6998 def test_modify_attribute(self): 6998 def test_modify_attribute(self):
6999 # This fails on Orthanc <= 1.9.3 (not implemented) 6999 # This fails on Orthanc <= 1.9.3 (not implemented)
7000 # https://groups.google.com/g/orthanc-users/c/1pzCqT-ByXg/m/VyIGK5i5BgAJ 7000 # https://groups.google.com/g/orthanc-users/c/1pzCqT-ByXg/m/VyIGK5i5BgAJ
7172 ], 7172 ],
7173 'Keep' : [ 7173 'Keep' : [
7174 'ReferencedImageEvidenceSequence', # 0008,9092 7174 'ReferencedImageEvidenceSequence', # 0008,9092
7175 'DimensionIndexSequence', # 0020,9222 7175 'DimensionIndexSequence', # 0020,9222
7176 'PerFrameFunctionalGroupsSequence[*].2005,140f[*].SOPInstanceUID', # 5200,9230 7176 'PerFrameFunctionalGroupsSequence[*].2005,140f[*].SOPInstanceUID', # 5200,9230
7177 ] 7177 '(5200,9230)[*].2005,140f[*].(0008,0023)', # Compatibility with Orthanc 1.9.4
7178 '(5200,9230)[*].2005,140f[*].(0008,0033)', # Compatibility with Orthanc 1.9.4
7179 ],
7180 'KeepPrivateTags' : True # Compatibility with Orthanc 1.9.4
7178 }) 7181 })
7179 tags3 = GetTags(a['ID']) 7182 tags3 = GetTags(a['ID'])
7180 7183
7181 # UIDs 7184 # UIDs
7182 for i in [ '0008,0018', 7185 for i in [ '0008,0018',
7935 self.assertEqual(4, len(b['Query'][0])) 7938 self.assertEqual(4, len(b['Query'][0]))
7936 self.assertEqual('A10003245599', b['Query'][0]['AccessionNumber']) 7939 self.assertEqual('A10003245599', b['Query'][0]['AccessionNumber'])
7937 self.assertEqual('STUDY', b['Query'][0]['QueryRetrieveLevel']) 7940 self.assertEqual('STUDY', b['Query'][0]['QueryRetrieveLevel'])
7938 self.assertEqual('887', b['Query'][0]['PatientID']) 7941 self.assertEqual('887', b['Query'][0]['PatientID'])
7939 self.assertEqual('2.16.840.1.113669.632.20.121711.10000160881', b['Query'][0]['StudyInstanceUID']) 7942 self.assertEqual('2.16.840.1.113669.632.20.121711.10000160881', b['Query'][0]['StudyInstanceUID'])
7943
7944
7945 def test_anonymize_nested(self):
7946 # New in Orthanc 1.9.5
7947
7948 tags = {
7949 'MappingResourceIdentificationSequence' : [
7950 {
7951 # Test "DicomModification::RelationshipsVisitor::GetDefaultAction()"
7952 '0009,1002' : 'ABCD', # Private tag not registered in dictionary
7953 '0016,0071' : '-12', # "GPS Latitude" whose VR is DS in "removals_"
7954 '0034,0005' : '13', # VR is OB, and in "clearings_" (only in DCMTK 3.6.2)
7955
7956 # Test "DicomModification::RelationshipsVisitor::VisitString()"
7957 'StudyDescription' : 'Hello', # Removed
7958 'StudyDate' : '20210705', # Cleared
7959 '0009,1001' : '-1234', # Private tag whose VR is DS
7960
7961 # Test anonymization of nested sequences
7962 'ReferencedStudySequence' : [
7963 {
7964 'PatientID' : 'HELLO'
7965 }
7966 ],
7967
7968 # Non-anonymized tags
7969 'CodeMeaning' : 'MEANING1',
7970 'EquivalentCodeSequence' : [
7971 {
7972 'CodeMeaning' : 'MEANING2',
7973 }
7974 ],
7975 }
7976 ],
7977 }
7978
7979 a = DoPost(_REMOTE, '/tools/create-dicom',
7980 json.dumps({
7981 'Tags' : tags,
7982 'PrivateCreator' : 'Lunit',
7983 })) ['ID']
7984
7985 study = DoGet(_REMOTE, '/instances/%s/study' % a) ['ID']
7986 b = DoPost(_REMOTE, '/studies/%s/anonymize' % study, {}) ['ID']
7987 c = DoGet(_REMOTE, '/studies/%s/instances' % b)
7988 self.assertEqual(1, len(c))
7989
7990 tags1 = DoGet(_REMOTE, '/instances/%s/tags?short' % a)
7991 tags2 = DoGet(_REMOTE, '/instances/%s/tags?short' % c[0]['ID'])
7992
7993 # Only "StudyDate" must be present in
7994 # "MappingResourceIdentificationSequence" after anonymization
7995 self.assertEqual(1, len(tags1['0008,0124']))
7996 self.assertEqual(1, len(tags2['0008,0124']))
7997 self.assertEqual(9, len(tags1['0008,0124'][0]))
7998 self.assertEqual(3, len(tags2['0008,0124'][0]))
7999 self.assertEqual('', tags2['0008,0124'][0]['0008,0020'])
8000 self.assertEqual('MEANING1', tags2['0008,0124'][0]['0008,0104'])
8001 self.assertEqual('MEANING2', tags2['0008,0124'][0]['0008,0121'][0]['0008,0104'])
8002
8003 self.assertTrue('0008,1110' in tags1['0008,0124'][0])
8004 self.assertFalse('0008,1110' in tags2['0008,0124'][0])