How to use the pydicom.uid.generate_uid function in pydicom

To help you get started, we’ve selected a few pydicom examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pydicom / pydicom / tests / test_uid.py View on Github external
'1',
                               '1.2',
                               '1.2..3.',
                               '1.a.2.',
                               '1.01.1.'):
            self.assertRaises(ValueError,
                              lambda: generate_uid(prefix=invalid_prefix))

        # Test some valid prefixes and make sure they survive
        for valid_prefix in ('0.',
                             '1.',
                             '1.23.',
                             '1.0.23.',
                             ('1' * 62) + '.',
                             '1.2.3.444444.'):
            uid = generate_uid(prefix=valid_prefix)
            self.assertEqual(uid[:len(valid_prefix)], valid_prefix)
            self.assertTrue(len(uid) <= 64)
github radiasoft / sirepo / sirepo / template / rs4pi.py View on Github external
def _create_dicom_dataset(study_uid, dicom_class, modality):
    sop_uid = dicom.uid.generate_uid()

    file_meta = dicom.dataset.Dataset()
    file_meta.MediaStorageSOPClassUID = _DICOM_CLASS[dicom_class]
    file_meta.MediaStorageSOPInstanceUID = sop_uid
    #TODO(pjm): need proper implementation uid
    file_meta.ImplementationClassUID = "1.2.3.4"
    file_meta.ImplementationVersionName = 'dcm4che-2.0'

    ds = dicom.dataset.FileDataset('', {}, file_meta=file_meta, preamble=b"\0" * 128)
    now = datetime.datetime.now()
    ds.InstanceCreationDate = now.strftime('%Y%m%d')
    ds.InstanceCreationTime = now.strftime('%H%M%S.%f')
    ds.SOPClassUID = _DICOM_CLASS[dicom_class]
    ds.SOPInstanceUID = sop_uid
    ds.StudyDate = ''
    ds.StudyTime = ''
github pymedphys / pymedphys / packages / pymedphys_pinnacle / src / pymedphys_pinnacle / export / pinnacle_plan.py View on Github external
"""

        entropy_srcs = None
        if uid_type == "HASH":
            entropy_srcs = []
            entropy_srcs.append(self._pinnacle.patient_info["MedicalRecordNumber"])
            entropy_srcs.append(self.plan_info["PlanName"])
            entropy_srcs.append(self.trial_info["Name"])
            entropy_srcs.append(self.trial_info["ObjectVersion"]["WriteTimeStamp"])

        RTPLAN_prefix = self._uid_prefix + "1."
        self._plan_inst_uid = pydicom.uid.generate_uid(
            prefix=RTPLAN_prefix, entropy_srcs=entropy_srcs
        )
        RTDOSE_prefix = self._uid_prefix + "2."
        self._dose_inst_uid = pydicom.uid.generate_uid(
            prefix=RTDOSE_prefix, entropy_srcs=entropy_srcs
        )
        RTSTRUCT_prefix = self._uid_prefix + "3."
        self._struct_inst_uid = pydicom.uid.generate_uid(
            prefix=RTSTRUCT_prefix, entropy_srcs=entropy_srcs
        )

        self.logger.debug("Plan Instance UID: " + self._plan_inst_uid)
        self.logger.debug("Dose Instance UID: " + self._dose_inst_uid)
        self.logger.debug("Struct Instance UID: " + self._struct_inst_uid)
github pymedphys / pymedphys / notebooks / dcmplan / generate_rp.py View on Github external
ds.StudyInstanceUID = pydicom.uid.generate_uid()
    ds.StudyDate = ""  # Required - can be empty
    ds.StudyTime = ""  # Required - can be empty'
    ds.ReferringPhysicianName = ""  # Required - can be empty'
    ds.StudyID = ""  # Required - can be empty'
    ds.AccessionNumber = ""  # Required - can be empty'

    # ----- RT Series Module -----
    ds.Modality = "RTPLAN"
    ds.SeriesInstanceUID = pydicom.uid.generate_uid()
    ds.SeriesNumber = ""  # Required - can be empty'
    ds.OperatorsName = ""  # Required - can be empty'

    # ----- Frame of Reference Module -----
    ds.FrameOfReferenceUID = pydicom.uid.generate_uid()
    ds.PositionReferenceIndicator = ""  # Required - can be empty'

    # ----- General Equipment Module -----
    ds.Manufacturer = ""  # Required - can be empty TODO: Check if RS is happy'
    # ds.ManufacturerModelName = '' # Optional TODO: Check if RS is happy'

    # ----- RT General Plan Module -----
    ds.RTPlanLabel = "PyMedPhys"  # Set from field definition?
    ds.RTPlanName = "PyMedPhys"  # Optional, Set from field definition?
    ds.RTPlanDescription = "PyMedPhys"  # Optional, Set from field definition?
    # Required - can be empty TODO: Check if RS is happy
    ds.RTPlanDate = datetime.now().strftime("%Y%m%d")
    # Required - can be empty TODO: Check if RS is happy
    ds.RTPlanTime = datetime.now().strftime("%H%M%S")
    ds.PlanIntent = "VERIFICATION"
    ds.RTPlanGeometry = "TREATMENT_DEVICE"  # Structure Set will probably not exist
github ryanneph / PyMedImage / pymedimage / dcmio.py View on Github external
ds.SeriesNumber = '0001'
    ds.StudyDate = datestr
    ds.StudyTime = timestr
    ds.AccessionNumber = ''
    ds.ReferringPhysiciansName = ''
    ds.PatientName = 'ANON0001'
    ds.PatientSex = ''
    ds.PatientAge = ''
    ds.PatientBirthDate = ''
    ds.PatientOrientation = 'LA'
    ds.PatientPosition = 'HFS'
    ds.ImagePositionPatient = [0, 0, 0]
    ds.ImageOrientationPatient = [1, 0, 0, 0, 1, 0]
    ds.InstanceNumber = 1
    ds.StudyInstanceUID = pydicom.uid.generate_uid() if StudyInstanceUID is None else StudyInstanceUID
    ds.SeriesInstanceUID = pydicom.uid.generate_uid() if SeriesInstanceUID is None else SeriesInstanceUID
    ds.FrameOfReferenceUID = pydicom.uid.generate_uid() if FrameOfReferenceUID is None else FrameOfReferenceUID
    ds.SOPInstanceUID = pydicom.uid.generate_uid()
    ds.ImageType = ['ORIGINAL', 'PRIMARY', 'AXIAL']
    ds.Modality = ''
    ds.SOPClassUID = CTIMAGE_SOP_CLASS_UID
    ds.SamplesPerPixel = 1
    ds.PhotometricInterpretation = 'MONOCHROME2'
    ds.BitsAllocated = 16
    ds.BitsStored = 16
    ds.HighBit = 15
    ds.RescaleIntercept = 0
    ds.RescaleSlope = 1.0
    ds.KVP = ''
    ds.AcquisitionNumber = 1
    ds.PixelRepresentation = 0
    ds.SliceLocation = 0.0
github pymedphys / pymedphys / packages / pymedphys_pinnacle / src / pymedphys_pinnacle / export / pinnacle_plan.py View on Github external
entropy_srcs = []
            entropy_srcs.append(self._pinnacle.patient_info["MedicalRecordNumber"])
            entropy_srcs.append(self.plan_info["PlanName"])
            entropy_srcs.append(self.trial_info["Name"])
            entropy_srcs.append(self.trial_info["ObjectVersion"]["WriteTimeStamp"])

        RTPLAN_prefix = self._uid_prefix + "1."
        self._plan_inst_uid = pydicom.uid.generate_uid(
            prefix=RTPLAN_prefix, entropy_srcs=entropy_srcs
        )
        RTDOSE_prefix = self._uid_prefix + "2."
        self._dose_inst_uid = pydicom.uid.generate_uid(
            prefix=RTDOSE_prefix, entropy_srcs=entropy_srcs
        )
        RTSTRUCT_prefix = self._uid_prefix + "3."
        self._struct_inst_uid = pydicom.uid.generate_uid(
            prefix=RTSTRUCT_prefix, entropy_srcs=entropy_srcs
        )

        self.logger.debug("Plan Instance UID: " + self._plan_inst_uid)
        self.logger.debug("Dose Instance UID: " + self._dose_inst_uid)
        self.logger.debug("Struct Instance UID: " + self._struct_inst_uid)