void FillInstance(DcmDirectoryRecord& record, DcmItem& dicom, DcmMetaInfo& metaInfo, const char* path) { // cf. "DicomDirInterface::buildImageRecord()" /* copy attribute values from dataset to image record */ copyElementType1(dicom, DCM_InstanceNumber, record); //copyElementType1C(dicom, DCM_ImageType, record); copyElementType1C(dicom, DCM_ReferencedImageSequence, record); OFString tmp; DcmElement* item = record.remove(DCM_ReferencedImageSequence); if (item != NULL) { delete item; } if (record.putAndInsertString(DCM_ReferencedFileID, path).bad() || dicom.findAndGetOFStringArray(DCM_SOPClassUID, tmp).bad() || record.putAndInsertString(DCM_ReferencedSOPClassUIDInFile, tmp.c_str()).bad() || dicom.findAndGetOFStringArray(DCM_SOPInstanceUID, tmp).bad() || record.putAndInsertString(DCM_ReferencedSOPInstanceUIDInFile, tmp.c_str()).bad() || metaInfo.findAndGetOFStringArray(DCM_TransferSyntaxUID, tmp).bad() || record.putAndInsertString(DCM_ReferencedTransferSyntaxUIDInFile, tmp.c_str()).bad()) { throw OrthancException(ErrorCode_BadFileFormat); } }
// copy optional string value from dataset to directory record static void copyStringWithDefault(DcmItem& dataset, const DcmTagKey &key, DcmDirectoryRecord& record, const char *defaultValue, const OFBool printWarning) { OFCondition status; if (dataset.tagExistsWithValue(key)) { OFString stringValue; /* retrieve string value from source dataset and put it into the destination dataset */ status = dataset.findAndGetOFStringArray(key, stringValue); if (status.good()) status = record.putAndInsertString(key, stringValue.c_str()); } else { if (printWarning && (defaultValue != NULL)) { /* create warning message */ LOG(WARNING) << "DICOMDIR: " << DcmTag(key).getTagName() << " " << key << " missing, using alternative: " << defaultValue; } /* put default value */ status = record.putAndInsertString(key, defaultValue); } }