|
| 1 | +from enum import Enum |
| 2 | +from typing import Optional, Dict |
| 3 | + |
| 4 | +class DiagnosisDateReasonType(Enum): |
| 5 | + TWO_DNAS_OF_COLONOSCOPY_ASSESSMENT_APPT = ( |
| 6 | + 305521, |
| 7 | + "2 DNAs of colonoscopy assessment appt", |
| 8 | + ) |
| 9 | + INCORRECT_INFORMATION_PREVIOUSLY_ENTERED = ( |
| 10 | + 305501, |
| 11 | + "Incorrect information previously entered", |
| 12 | + ) |
| 13 | + OTHER = (305500, "Other") |
| 14 | + PATIENT_CHOICE = (305522, "Patient choice") |
| 15 | + PATIENT_COULD_NOT_BE_CONTACTED = (305505, "Patient could not be contacted") |
| 16 | + PATIENT_DECEASED = (305503, "Patient deceased") |
| 17 | + PATIENT_DECLINIED_ALL_APPOINTMENTS = (305520, "Patient declined all appointments") |
| 18 | + PATIENT_EMIGRATED = (305504, "Patient emigrated") |
| 19 | + REOPENED_OLD_EPISODE_DATE_UNKNOWN = (305502, "Reopened old episode, date unknown") |
| 20 | + SSPI_UPDATE_PATIENT_DECEASED = (305525, "SSPI update - patient deceased") |
| 21 | + SSPI_UPDATE_PATIENT_EMIGRATED = (305524, "SSPI update - patient emigrated") |
| 22 | + SYSTEM_CLOSURE_AFTER_NO_INPUT_OF_DIAGNOSIS_DATE = ( |
| 23 | + 305519, |
| 24 | + "System closure after no input of diagnosis date", |
| 25 | + ) |
| 26 | + NULL = (None, "NULL") |
| 27 | + NOT_NULL = (None, "NOT NULL") |
| 28 | + |
| 29 | + def __init__(self, valid_value_id: Optional[int], description: str): |
| 30 | + self._valid_value_id = valid_value_id |
| 31 | + self._description = description |
| 32 | + |
| 33 | + @property |
| 34 | + def valid_value_id(self) -> Optional[int]: |
| 35 | + return self._valid_value_id |
| 36 | + |
| 37 | + @property |
| 38 | + def description(self) -> str: |
| 39 | + return self._description |
| 40 | + |
| 41 | + @classmethod |
| 42 | + def _build_maps(cls): |
| 43 | + if not hasattr(cls, "_descriptions"): |
| 44 | + cls._descriptions: Dict[str, DiagnosisDateReasonType] = {} |
| 45 | + cls._lowercase_descriptions: Dict[str, DiagnosisDateReasonType] = {} |
| 46 | + cls._valid_value_ids: Dict[Optional[int], DiagnosisDateReasonType] = {} |
| 47 | + for item in cls: |
| 48 | + cls._descriptions[item.description] = item |
| 49 | + cls._lowercase_descriptions[item.description.lower()] = item |
| 50 | + cls._valid_value_ids[item.valid_value_id] = item |
| 51 | + |
| 52 | + @classmethod |
| 53 | + def by_description(cls, description: str) -> Optional["DiagnosisDateReasonType"]: |
| 54 | + cls._build_maps() |
| 55 | + return cls._descriptions.get(description) |
| 56 | + |
| 57 | + @classmethod |
| 58 | + def by_description_case_insensitive( |
| 59 | + cls, description: str |
| 60 | + ) -> Optional["DiagnosisDateReasonType"]: |
| 61 | + cls._build_maps() |
| 62 | + return cls._lowercase_descriptions.get(description.lower()) |
| 63 | + |
| 64 | + @classmethod |
| 65 | + def by_valid_value_id( |
| 66 | + cls, valid_value_id: Optional[int] |
| 67 | + ) -> Optional["DiagnosisDateReasonType"]: |
| 68 | + cls._build_maps() |
| 69 | + return cls._valid_value_ids.get(valid_value_id) |
| 70 | + |
| 71 | + def get_valid_value_id(self) -> Optional[int]: |
| 72 | + return self._valid_value_id |
| 73 | + |
| 74 | + def get_description(self) -> str: |
| 75 | + return self._description |
0 commit comments