|
32 | 32 | get_typed_attr,
|
33 | 33 | load_json,
|
34 | 34 | set_readonly,
|
35 |
| - strptime_micr, |
| 35 | + strptime_dcm_da_tm, |
| 36 | + strptime_dcm_dt, |
36 | 37 | )
|
37 | 38 |
|
38 | 39 | if TYPE_CHECKING:
|
@@ -94,15 +95,19 @@ def create_seqinfo(
|
94 | 95 | series_desc = get_typed_attr(dcminfo, "SeriesDescription", str, "")
|
95 | 96 | protocol_name = get_typed_attr(dcminfo, "ProtocolName", str, "")
|
96 | 97 |
|
97 |
| - if dcminfo.get([0x18, 0x24]): |
98 |
| - # GE and Philips |
99 |
| - sequence_name = dcminfo[0x18, 0x24].value |
100 |
| - elif dcminfo.get([0x19, 0x109C]): |
101 |
| - # Siemens |
102 |
| - sequence_name = dcminfo[0x19, 0x109C].value |
103 |
| - elif dcminfo.get([0x18, 0x9005]): |
104 |
| - # Siemens XA |
105 |
| - sequence_name = dcminfo[0x18, 0x9005].value |
| 98 | + for k, m in ( |
| 99 | + ([0x18, 0x24], "GE and Philips"), |
| 100 | + ([0x19, 0x109C], "Siemens"), |
| 101 | + ([0x18, 0x9005], "Siemens XA"), |
| 102 | + ): |
| 103 | + if v := dcminfo.get(k): |
| 104 | + sequence_name = v.value |
| 105 | + lgr.debug( |
| 106 | + "Identified sequence name as %s coming from the %r family of MR scanners", |
| 107 | + sequence_name, |
| 108 | + m, |
| 109 | + ) |
| 110 | + break |
106 | 111 | else:
|
107 | 112 | sequence_name = ""
|
108 | 113 |
|
@@ -544,19 +549,16 @@ def get_datetime_from_dcm(dcm_data: dcm.FileDataset) -> Optional[datetime.dateti
|
544 | 549 | 3. SeriesDate & SeriesTime (0008,0021); (0008,0031)
|
545 | 550 |
|
546 | 551 | """
|
547 |
| - acq_date = dcm_data.get("AcquisitionDate", "").strip() |
548 |
| - acq_time = dcm_data.get("AcquisitionTime", "").strip() |
549 |
| - if acq_date and acq_time: |
550 |
| - return strptime_micr(acq_date + acq_time, "%Y%m%d%H%M%S[.%f]") |
551 |
| - |
552 |
| - acq_dt = dcm_data.get("AcquisitionDateTime", "").strip() |
553 |
| - if acq_dt: |
554 |
| - return strptime_micr(acq_dt, "%Y%m%d%H%M%S[.%f]") |
555 |
| - |
556 |
| - series_date = dcm_data.get("SeriesDate", "").strip() |
557 |
| - series_time = dcm_data.get("SeriesTime", "").strip() |
558 |
| - if series_date and series_time: |
559 |
| - return strptime_micr(series_date + series_time, "%Y%m%d%H%M%S[.%f]") |
| 552 | + |
| 553 | + def check_tag(x: str) -> bool: |
| 554 | + return x in dcm_data and dcm_data[x].value.strip() |
| 555 | + |
| 556 | + if check_tag("AcquisitionDate") and check_tag("AcquisitionTime"): |
| 557 | + return strptime_dcm_da_tm(dcm_data, "AcquisitionDate", "AcquisitionTime") |
| 558 | + if check_tag("AcquisitionDateTime"): |
| 559 | + return strptime_dcm_dt(dcm_data, "AcquisitionDateTime") |
| 560 | + if check_tag("SeriesDate") and check_tag("SeriesTime"): |
| 561 | + return strptime_dcm_da_tm(dcm_data, "SeriesDate", "SeriesTime") |
560 | 562 | return None
|
561 | 563 |
|
562 | 564 |
|
|
0 commit comments