Beispiel #1
0
def jitter_timestamp(dicom, field, value):
    """if present, jitter a timestamp in dicom
       field "field" by number of days specified by "value"
       The value can be positive or negative.
 
       Parameters
       ==========
       dicom: the pydicom Dataset
       field: the field with the timestamp
       value: number of days to jitter by. Jitter bug!

    """
    if not isinstance(value, int):
        value = int(value)

    original = dicom.get(field)

    if original is not None:

        # Create default for new value
        new_value = None

        # If we have a string, we need to create a DataElement
        if isinstance(field, str):
            dcmvr = dicom.data_element(field).VR
        else:
            dcmvr = dicom.get(field).VR
            original = dicom.get(field).value

        # DICOM Value Representation can be either DA (Date) DT (Timestamp),
        # or something else, which is not supported.

        if dcmvr == "DA":
            # NEMA-compliant format for DICOM date is YYYYMMDD
            new_value = get_timestamp(original,
                                      jitter_days=value,
                                      format="%Y%m%d")

        elif dcmvr == "DT":
            # NEMA-compliant format for DICOM timestamp is
            # YYYYMMDDHHMMSS.FFFFFF&ZZXX
            new_value = get_timestamp(original,
                                      jitter_days=value,
                                      format="%Y%m%d%H%M%S.%f%z")
        else:
            # Do nothing and issue a warning.
            bot.warning("JITTER not supported for %s with VR=%s" %
                        (field, dcmvr))

        if new_value is not None and new_value != original:
            # Only update if there's something to update AND there's been change
            dicom = update_tag(dicom, field=field, value=new_value)

    return dicom
Beispiel #2
0
def jitter_timestamp(dicom, field, value):
    '''if present, jitter a timestamp in dicom
       field "field" by number of days specified by "value"
       The value can be positive or negative.
 
       Parameters
       ==========
       dicom: the pydicom Dataset
       field: the field with the timestamp
       value: number of days to jitter by. Jitter bug!

    '''
    if not isinstance(value, int):
        value = int(value)

    original = dicom.get(field, None)

    if original is not None:
        dcmvr = dicom.data_element(field).VR
        '''
        DICOM Value Representation can be either DA (Date) DT (Timestamp),
        or something else, which is not supported.
        '''
        if (dcmvr == 'DA'):
            '''
            NEMA-compliant format for DICOM date is YYYYMMDD
            '''
            new_value = get_timestamp(original,
                                      jitter_days=value,
                                      format='%Y%m%d')

        elif (dcmvr == 'DT'):
            '''
            NEMA-compliant format for DICOM timestamp is
            YYYYMMDDHHMMSS.FFFFFF&ZZXX
            '''
            new_value = get_timestamp(original,
                                      jitter_days=value,
                                      format='%Y%m%d%H%M%S.%f%z')
        else:
            # Do nothing and issue a warning.
            new_value = None
            bot.warning("JITTER not supported for %s with VR=%s" %
                        (field, dcmvr))
        if (new_value is not None and new_value != original):
            # Only update if there's something to update AND there's been change
            dicom = update_tag(dicom, field=field, value=new_value)
    return dicom