Skip to content

Util

pyorthanc.util

get_pydicom(orthanc, instance_identifier)

Get a pydicom.FileDataset from the instance's Orthanc identifier

Source code in pyorthanc/util.py
51
52
53
54
55
def get_pydicom(orthanc: Orthanc, instance_identifier: str) -> pydicom.FileDataset:
    """Get a pydicom.FileDataset from the instance's Orthanc identifier"""
    dicom_bytes = orthanc.get_instances_id_file(instance_identifier)

    return pydicom.dcmread(BytesIO(dicom_bytes))

make_datetime_from_dicom_date(date, time=None)

Attempt to decode date

Source code in pyorthanc/util.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def make_datetime_from_dicom_date(date: str, time: str = None) -> Optional[datetime]:
    """Attempt to decode date"""
    try:
        return datetime(
            year=int(date[:4]),
            month=int(date[4:6]),
            day=int(date[6:8]),
            hour=int(time[:2]),
            minute=int(time[2:4]),
            second=int(time[4:6])
        )
    except (ValueError, TypeError):
        try:
            return datetime(
                year=int(date[:4]),
                month=int(date[4:6]),
                day=int(date[6:8]),
            )
        except (ValueError, TypeError):
            return None