|
1 | | -from enum import Enum |
2 | | -from typing import Optional, Dict |
3 | | - |
4 | | - |
5 | | -class LocationType(Enum): |
6 | | - """ |
7 | | - Enum representing anatomical locations for datasets, |
8 | | - with valid value IDs and descriptions. |
9 | | - """ |
10 | | - |
11 | | - ANUS = (17231, "Anus") |
12 | | - RECTUM = (17232, "Rectum") |
13 | | - RECTO_SIGMOID = (17243, "Recto/Sigmoid") # Used in CADS |
14 | | - SIGMOID_COLON = (17233, "Sigmoid Colon") |
15 | | - DESCENDING_COLON = (17234, "Descending Colon") |
16 | | - SPLENIC_FLEXURE = (17235, "Splenic Flexure") |
17 | | - TRANSVERSE_COLON = (17236, "Transverse Colon") |
18 | | - HEPATIC_FLEXURE = (17237, "Hepatic Flexure") |
19 | | - ASCENDING_COLON = (17238, "Ascending Colon") |
20 | | - CAECUM = (17239, "Caecum") |
21 | | - ILEUM = (17240, "Ileum") |
22 | | - ANASTOMOSIS = (17241, "Anastomosis") |
23 | | - APPENDIX = (17242, "Appendix") |
24 | | - LEFT_COLON = (17244, "Left colon") # Used in investigation datasets, other findings |
25 | | - ENTIRE_COLON = ( |
26 | | - 17245, |
27 | | - "Entire colon", |
28 | | - ) # Used in investigation datasets, other findings |
29 | | - RIGHT_COLON = ( |
30 | | - 200619, |
31 | | - "Right colon", |
32 | | - ) # Used in investigation datasets, other findings |
33 | | - PATCHY_AREAS = ( |
34 | | - 200618, |
35 | | - "Patchy areas", |
36 | | - ) # Used in investigation datasets, other findings |
37 | | - |
38 | | - def __init__(self, valid_value_id: int, description: str): |
39 | | - self._valid_value_id: int = valid_value_id |
40 | | - self._description: str = description |
41 | | - |
42 | | - @property |
43 | | - def valid_value_id(self) -> int: |
44 | | - """Returns the valid value ID for the location.""" |
45 | | - return self._valid_value_id |
46 | | - |
47 | | - @property |
48 | | - def description(self) -> str: |
49 | | - """Returns the description for the location.""" |
50 | | - return self._description |
51 | | - |
52 | | - @classmethod |
53 | | - def _build_maps(cls) -> None: |
54 | | - if not hasattr(cls, "_descriptions"): |
55 | | - cls._descriptions: Dict[str, LocationType] = {} |
56 | | - cls._lowercase_descriptions: Dict[str, LocationType] = {} |
57 | | - cls._valid_value_ids: Dict[int, LocationType] = {} |
58 | | - for item in cls: |
59 | | - cls._descriptions[item.description] = item |
60 | | - cls._lowercase_descriptions[item.description.lower()] = item |
61 | | - cls._valid_value_ids[item.valid_value_id] = item |
62 | | - |
63 | | - @classmethod |
64 | | - def by_description(cls, description: str) -> Optional["LocationType"]: |
65 | | - """ |
66 | | - Returns the LocationType matching the given description. |
67 | | - """ |
68 | | - cls._build_maps() |
69 | | - return cls._descriptions.get(description) |
70 | | - |
71 | | - @classmethod |
72 | | - def by_description_case_insensitive( |
73 | | - cls, description: str |
74 | | - ) -> Optional["LocationType"]: |
75 | | - """ |
76 | | - Returns the LocationType matching the given description (case-insensitive). |
77 | | - """ |
78 | | - cls._build_maps() |
79 | | - return cls._lowercase_descriptions.get(description.lower()) |
80 | | - |
81 | | - @classmethod |
82 | | - def by_valid_value_id(cls, valid_value_id: int) -> Optional["LocationType"]: |
83 | | - """ |
84 | | - Returns the LocationType matching the given valid value ID. |
85 | | - """ |
86 | | - cls._build_maps() |
87 | | - return cls._valid_value_ids.get(valid_value_id) |
88 | | - |
89 | | - def get_id(self) -> int: |
90 | | - """Returns the valid value ID for the location.""" |
91 | | - return self._valid_value_id |
92 | | - |
93 | | - def get_description(self) -> str: |
94 | | - """Returns the description for the location.""" |
95 | | - return self._description |
| 1 | +from enum import Enum |
| 2 | +from typing import Optional, Dict |
| 3 | + |
| 4 | + |
| 5 | +class LocationType(Enum): |
| 6 | + """ |
| 7 | + Enum representing anatomical locations for datasets, |
| 8 | + with valid value IDs and descriptions. |
| 9 | + """ |
| 10 | + |
| 11 | + ANUS = (17231, "Anus") |
| 12 | + RECTUM = (17232, "Rectum") |
| 13 | + RECTO_SIGMOID = (17243, "Recto/Sigmoid") # Used in CADS |
| 14 | + SIGMOID_COLON = (17233, "Sigmoid Colon") |
| 15 | + DESCENDING_COLON = (17234, "Descending Colon") |
| 16 | + SPLENIC_FLEXURE = (17235, "Splenic Flexure") |
| 17 | + TRANSVERSE_COLON = (17236, "Transverse Colon") |
| 18 | + HEPATIC_FLEXURE = (17237, "Hepatic Flexure") |
| 19 | + ASCENDING_COLON = (17238, "Ascending Colon") |
| 20 | + CAECUM = (17239, "Caecum") |
| 21 | + ILEUM = (17240, "Ileum") |
| 22 | + ANASTOMOSIS = (17241, "Anastomosis") |
| 23 | + APPENDIX = (17242, "Appendix") |
| 24 | + LEFT_COLON = (17244, "Left colon") # Used in investigation datasets, other findings |
| 25 | + ENTIRE_COLON = ( |
| 26 | + 17245, |
| 27 | + "Entire colon", |
| 28 | + ) # Used in investigation datasets, other findings |
| 29 | + RIGHT_COLON = ( |
| 30 | + 200619, |
| 31 | + "Right colon", |
| 32 | + ) # Used in investigation datasets, other findings |
| 33 | + PATCHY_AREAS = ( |
| 34 | + 200618, |
| 35 | + "Patchy areas", |
| 36 | + ) # Used in investigation datasets, other findings |
| 37 | + |
| 38 | + def __init__(self, valid_value_id: int, description: str): |
| 39 | + self._valid_value_id: int = valid_value_id |
| 40 | + self._description: str = description |
| 41 | + |
| 42 | + @property |
| 43 | + def valid_value_id(self) -> int: |
| 44 | + """Returns the valid value ID for the location.""" |
| 45 | + return self._valid_value_id |
| 46 | + |
| 47 | + @property |
| 48 | + def description(self) -> str: |
| 49 | + """Returns the description for the location.""" |
| 50 | + return self._description |
| 51 | + |
| 52 | + @classmethod |
| 53 | + def _build_maps(cls) -> None: |
| 54 | + if not hasattr(cls, "_descriptions"): |
| 55 | + cls._descriptions: Dict[str, LocationType] = {} |
| 56 | + cls._lowercase_descriptions: Dict[str, LocationType] = {} |
| 57 | + cls._valid_value_ids: Dict[int, LocationType] = {} |
| 58 | + for item in cls: |
| 59 | + cls._descriptions[item.description] = item |
| 60 | + cls._lowercase_descriptions[item.description.lower()] = item |
| 61 | + cls._valid_value_ids[item.valid_value_id] = item |
| 62 | + |
| 63 | + @classmethod |
| 64 | + def by_description(cls, description: str) -> Optional["LocationType"]: |
| 65 | + """ |
| 66 | + Returns the LocationType matching the given description. |
| 67 | + """ |
| 68 | + cls._build_maps() |
| 69 | + return cls._descriptions.get(description) |
| 70 | + |
| 71 | + @classmethod |
| 72 | + def by_description_case_insensitive( |
| 73 | + cls, description: str |
| 74 | + ) -> Optional["LocationType"]: |
| 75 | + """ |
| 76 | + Returns the LocationType matching the given description (case-insensitive). |
| 77 | + """ |
| 78 | + cls._build_maps() |
| 79 | + return cls._lowercase_descriptions.get(description.lower()) |
| 80 | + |
| 81 | + @classmethod |
| 82 | + def by_valid_value_id(cls, valid_value_id: int) -> Optional["LocationType"]: |
| 83 | + """ |
| 84 | + Returns the LocationType matching the given valid value ID. |
| 85 | + """ |
| 86 | + cls._build_maps() |
| 87 | + return cls._valid_value_ids.get(valid_value_id) |
| 88 | + |
| 89 | + def get_id(self) -> int: |
| 90 | + """Returns the valid value ID for the location.""" |
| 91 | + return self._valid_value_id |
| 92 | + |
| 93 | + def get_description(self) -> str: |
| 94 | + """Returns the description for the location.""" |
| 95 | + return self._description |
0 commit comments