当前位置: 代码迷 >> 综合 >> orthanc 实例唯一哈希算法
  详细解决方案

orthanc 实例唯一哈希算法

热度:66   发布时间:2023-12-28 05:59:31.0

orthanc 实例唯一哈希算法

orthanc给每个实例都自定义了唯一hash,采用SHA-1 hash算法,具体代码是用c++写的,官方代码如下:

#include "../PrecompiledHeaders.h"
#include "DicomInstanceHasher.h"#include "../OrthancException.h"
#include "../Toolbox.h"namespace Orthanc
{void DicomInstanceHasher::Setup(const std::string& patientId,const std::string& studyUid,const std::string& seriesUid,const std::string& instanceUid){patientId_ = patientId;studyUid_ = studyUid;seriesUid_ = seriesUid;instanceUid_ = instanceUid;if (studyUid_.size() == 0 ||seriesUid_.size() == 0 ||instanceUid_.size() == 0){throw OrthancException(ErrorCode_BadFileFormat, "missing StudyInstanceUID, SeriesInstanceUID or SOPInstanceUID");}}DicomInstanceHasher::DicomInstanceHasher(const DicomMap& instance){const DicomValue* patientId = instance.TestAndGetValue(DICOM_TAG_PATIENT_ID);Setup(patientId == NULL ? "" : patientId->GetContent(),instance.GetValue(DICOM_TAG_STUDY_INSTANCE_UID).GetContent(),instance.GetValue(DICOM_TAG_SERIES_INSTANCE_UID).GetContent(),instance.GetValue(DICOM_TAG_SOP_INSTANCE_UID).GetContent());}DicomInstanceHasher::DicomInstanceHasher(const std::string &patientId,const std::string &studyUid,const std::string &seriesUid,const std::string &instanceUid){Setup(patientId, studyUid, seriesUid, instanceUid);}const std::string &DicomInstanceHasher::GetPatientId() const{return patientId_;}const std::string &DicomInstanceHasher::GetStudyUid() const{return studyUid_;}const std::string &DicomInstanceHasher::GetSeriesUid() const{return seriesUid_;}const std::string &DicomInstanceHasher::GetInstanceUid() const{return instanceUid_;}const std::string& DicomInstanceHasher::HashPatient(){if (patientHash_.size() == 0){Toolbox::ComputeSHA1(patientHash_, patientId_);}return patientHash_;}const std::string& DicomInstanceHasher::HashStudy(){if (studyHash_.size() == 0){Toolbox::ComputeSHA1(studyHash_, patientId_ + "|" + studyUid_);}return studyHash_;}const std::string& DicomInstanceHasher::HashSeries(){if (seriesHash_.size() == 0){Toolbox::ComputeSHA1(seriesHash_, patientId_ + "|" + studyUid_ + "|" + seriesUid_);}return seriesHash_;}const std::string& DicomInstanceHasher::HashInstance(){if (instanceHash_.size() == 0){Toolbox::ComputeSHA1(instanceHash_, patientId_ + "|" + studyUid_ + "|" + seriesUid_ + "|" + instanceUid_);}return instanceHash_;}
}

要计算一个实例的hash值,有4个非常关键的标签:

0010,0020(PatientID)
0020,000d(StudyInstanceUID)
0020,000e(SeriesInstanceUID)
0008,0018(SOPInstanceUID)

源码中ComputeSHA1函数的作用就是对第二个参数计算SHA1哈希值
现在假设有一个实例:

PatientID: 5024112
StudyInstanceUID: 1.2.194.0.108707908.20200408091149.1350.12100.20947723
SeriesInstanceUID: 1.2.826.0.1.3680043.8.498.86781401740916960075135438897159436378
SOPInstanceUID: 1.2.826.0.1.3680043.8.498.11797881978550468522282411251518447481

  • studyID对应的hash: 即 PatientID+"|"+StudyInstanceUID
  • SeriesID对应的hash: 即 PatientID+"|"+StudyInstanceUID+"|"+SeriesInstanceUID
  • InstanceID对应的hash: 即 PatientID+"|"+StudyInstanceUID+"|"+SeriesInstanceUID+"|"+SOPInstanceUID

上边那个实例对应的hash应该就是字符串5024112|1.2.194.0.108707908.20200408091149.1350.12100.20947723|1.2.826.0.1.3680043.8.498.86781401740916960075135438897159436378|1.2.826.0.1.3680043.8.498.11797881978550468522282411251518447481对应的hash

在这里插入图片描述
通过这个hash值在orthanc提供的api也可以找到对应的instanceid
在这里插入图片描述