Skip to content

Commit ebfc7e0

Browse files
Inital commit. Fixing subject selection query builder and started scenario
1 parent a9d1fa6 commit ebfc7e0

File tree

5 files changed

+380
-115
lines changed

5 files changed

+380
-115
lines changed

classes/diagnostic_test_type.py

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,104 @@
1-
class DiagnosticTestType:
2-
"""
3-
Utility class for mapping descriptive diagnostic test types to valid value IDs.
1+
from enum import Enum
2+
from typing import Optional, Dict
43

5-
This class provides:
6-
- A mapping between human-readable diagnostic test type descriptions (e.g., "pcr", "antigen", "lateral flow") and their corresponding internal valid value IDs.
7-
- A method to retrieve the valid value ID for a given description.
84

9-
Methods:
10-
get_valid_value_id(description: str) -> int:
11-
Returns the valid value ID for a given diagnostic test type description.
12-
Raises ValueError if the description is not recognized.
5+
class DiagnosticTestType(Enum):
6+
"""
7+
Enum representing diagnostic test types, with valid value IDs, descriptions, categories, and allowed status.
138
"""
149

15-
_mapping = {
16-
"pcr": 3001,
17-
"antigen": 3002,
18-
"lateral flow": 3003,
19-
# Add more mappings as needed
20-
}
10+
BARIUM_ENEMA = (16003, "Barium Enema", "RADIOLOGY", "DISALLOWED")
11+
CT_COLONOGRAPHY = (16087, "CT Colonography", "RADIOLOGY", "ALLOWED")
12+
COLONOSCOPY = (16002, "Colonoscopy", "COLONOSCOPY", "ALLOWED")
13+
FLEXIBLE_SIGMOIDOSCOPY = (16004, "Flexible Sigmoidoscopy", "COLONOSCOPY", "ALLOWED")
14+
LIMITED_COLONOSCOPY = (17996, "Limited Colonoscopy", "COLONOSCOPY", "ALLOWED")
15+
NHS_BOWEL_SCOPE = (200554, "NHS bowel scope", "COLONOSCOPY", "ALLOWED")
16+
SCAN_XRAY = (16005, "Scan (x-ray)", "RADIOLOGY", "DISALLOWED")
17+
STANDARD_ABDOMINO_PELVIC_CT_SCAN = (
18+
16088,
19+
"Standard Abdomino-pelvic CT Scan",
20+
"RADIOLOGY",
21+
"DISALLOWED",
22+
)
23+
ANY = (0, "Any", "", "")
24+
25+
def __init__(
26+
self, valid_value_id: int, description: str, category: str, allowed: str
27+
):
28+
self._valid_value_id: int = valid_value_id
29+
self._description: str = description
30+
self._category: str = category
31+
self._allowed: str = allowed
32+
33+
@property
34+
def valid_value_id(self) -> int:
35+
"""Returns the valid value ID for the diagnostic test type."""
36+
return self._valid_value_id
37+
38+
@property
39+
def description(self) -> str:
40+
"""Returns the description for the diagnostic test type."""
41+
return self._description
42+
43+
@property
44+
def category(self) -> str:
45+
"""Returns the category for the diagnostic test type."""
46+
return self._category
47+
48+
@property
49+
def allowed(self) -> str:
50+
"""Returns the allowed status for the diagnostic test type."""
51+
return self._allowed
2152

2253
@classmethod
23-
def get_valid_value_id(cls, description: str) -> int:
24-
"""
25-
Returns the valid value ID for a given diagnostic test type description.
54+
def _build_maps(cls) -> None:
55+
if not hasattr(cls, "_descriptions"):
56+
cls._descriptions: Dict[str, DiagnosticTestType] = {}
57+
cls._lowercase_descriptions: Dict[str, DiagnosticTestType] = {}
58+
cls._valid_value_ids: Dict[int, DiagnosticTestType] = {}
59+
for item in cls:
60+
cls._descriptions[item.description] = item
61+
cls._lowercase_descriptions[item.description.lower()] = item
62+
cls._valid_value_ids[item.valid_value_id] = item
2663

27-
Args:
28-
description (str): The diagnostic test type description (e.g., "pcr").
64+
@classmethod
65+
def by_description(cls, description: str) -> Optional["DiagnosticTestType"]:
66+
"""
67+
Returns the DiagnosticTestType matching the given description.
68+
"""
69+
cls._build_maps()
70+
return cls._descriptions.get(description)
2971

30-
Returns:
31-
int: The valid value ID corresponding to the description.
72+
@classmethod
73+
def by_description_case_insensitive(
74+
cls, description: str
75+
) -> Optional["DiagnosticTestType"]:
76+
"""
77+
Returns the DiagnosticTestType matching the given description (case-insensitive).
78+
"""
79+
cls._build_maps()
80+
return cls._lowercase_descriptions.get(description.lower())
3281

33-
Raises:
34-
ValueError: If the description is not recognized.
82+
@classmethod
83+
def by_valid_value_id(cls, valid_value_id: int) -> Optional["DiagnosticTestType"]:
3584
"""
36-
key = description.strip().lower()
37-
if key not in cls._mapping:
38-
raise ValueError(f"Unknown diagnostic test type: '{description}'")
39-
return cls._mapping[key]
85+
Returns the DiagnosticTestType matching the given valid value ID.
86+
"""
87+
cls._build_maps()
88+
return cls._valid_value_ids.get(valid_value_id)
89+
90+
def get_valid_value_id(self) -> int:
91+
"""Returns the valid value ID for the diagnostic test type."""
92+
return self._valid_value_id
93+
94+
def get_description(self) -> str:
95+
"""Returns the description for the diagnostic test type."""
96+
return self._description
97+
98+
def get_category(self) -> str:
99+
"""Returns the category for the diagnostic test type."""
100+
return self._category
101+
102+
def get_allowed(self) -> str:
103+
"""Returns the allowed status for the diagnostic test type."""
104+
return self._allowed

classes/event_status_type.py

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,130 @@ class EventStatusType(Enum):
10211021
U81 = (11283, "U81", "Kit Returned and Logged (Technical Fail; Weak Positive")
10221022
U97 = (11284, "U97", "Weak Positive, Waiting for Screening Centre Assistance")
10231023
U98 = (11285, "U98", "Weak Positive, Waiting for Programme Hub Assistance")
1024+
X2 = (20346, "X2", "Surveillance appointment rescheduled")
1025+
X372 = (11554, "X372", "Handover into Symptomatic Care - GP Letter Printed")
1026+
X374 = (20085, "X374", "Handover into Symptomatic Care - Patient Letter Printed")
1027+
X376 = (20086, "X376", "Discharged from Surveillance - GP Letter Printed")
1028+
X377 = (20087, "X377", "Discharged from Surveillance - GP Letter Printed")
1029+
X379 = (20088, "X379", "Discharged from Surveillance - GP Letter Printed")
1030+
X380 = (20089, "X380", "Discharge from Screening and Surveillance - Patient Choice")
1031+
X381 = (
1032+
20090,
1033+
"X381",
1034+
"Discharge from Screening and Surveillance - No Patient Contact",
1035+
)
1036+
X382 = (
1037+
20091,
1038+
"X382",
1039+
"Discharge from Screening and Surveillance - Clinical Decision",
1040+
)
1041+
X384 = (
1042+
20183,
1043+
"X384",
1044+
"Discharged from Screening & Surveillance - GP Letter Not Required",
1045+
)
1046+
X386 = (20092, "X386", "Discharged from Surveillance - Patient Letter Printed")
1047+
X387 = (20093, "X387", "Discharged from Surveillance - Patient Letter Printed")
1048+
X389 = (20184, "X389", "Discharge from Surveillance - Clinical Decision")
1049+
X390 = (20094, "X390", "Discharge from Surveillance - Clinical Decision")
1050+
X391 = (20095, "X391", "Handover into Symptomatic Care")
1051+
X392 = (20096, "X392", "Discharge from Surveillance - Patient Choice")
1052+
X394 = (20097, "X394", "Handover into Symptomatic Care - Patient Age")
1053+
X395 = (
1054+
20098,
1055+
"X395",
1056+
"Discharged from Surveillance - National Guidelines Return FOBT",
1057+
)
1058+
X398 = (20099, "X398", "Discharge from Surveillance - No Patient Contact")
1059+
X399 = (
1060+
200263,
1061+
"X399",
1062+
"Discharged from Surveillance - National Guidelines Cease Screening",
1063+
)
1064+
X500 = (20100, "X500", "Selected For Surveillance")
1065+
X501 = (20101, "X501", "No Response to HealthCheck Form")
1066+
X505 = (20102, "X505", "HealthCheck Form Printed")
1067+
X510 = (20103, "X510", "Surveillance Reminder Printed")
1068+
X512 = (20104, "X512", "Patient Contact Resulted in Discharge from Surveillance")
1069+
X513 = (20196, "X513", "No Patient Contact - Discharge from Surveillance")
1070+
X600 = (20107, "X600", "Surveillance Appointment Required")
1071+
X610 = (20114, "X610", "Surveillance Appointment Made")
1072+
X615 = (20116, "X615", "Surveillance Appointment Invitation Letter Printed")
1073+
X617 = (20117, "X617", "Surveillance Appointment Cancelled by SC")
1074+
X620 = (20118, "X620", "Surveillance Appointment Cancelled by Patient")
1075+
X622 = (20122, "X622", "Surveillance Appointment Cancellation Letter Printed")
1076+
X625 = (20119, "X625", "Practitioner did not attend Surveillance Appointment")
1077+
X641 = (20120, "X641", "Patient did not attend Surveillance Appointment")
1078+
X650 = (20108, "X650", "Patient Attended Surveillance Appointment")
1079+
X76 = (20109, "X76", "Discharged from Surveillance & Screening - GP Letter Printed")
1080+
X77 = (20110, "X77", "Discharged from Surveillance & Screening - GP Letter Printed")
1081+
X79 = (20111, "X79", "Discharge from Surveillance & Screening - GP Letter Printed")
1082+
X86 = (
1083+
20112,
1084+
"X86",
1085+
"Discharged from Surveillance & Screening - Patient Letter Printed",
1086+
)
1087+
X87 = (
1088+
20113,
1089+
"X87",
1090+
"Discharged from Surveillance & Screening - Patient Letter Printed",
1091+
)
1092+
X89 = (
1093+
20185,
1094+
"X89",
1095+
"Discharge from Screening and Surveillance - Clinical Decision",
1096+
)
1097+
X9 = (20115, "X9", "Surveillance Appointment Cancelled Letters not Prepared")
1098+
X900 = (20237, "X900", "Surveillance Episode reopened")
1099+
X92 = (20188, "X92", "Close Surveillance Episode via interrupt")
1100+
Z1 = (
1101+
11289,
1102+
"Z1",
1103+
"Appointment Cancellation Requested by SC prior to Letter Preparation",
1104+
)
1105+
Z10 = (20344, "Z10", "Colonoscopy assessment appointment rescheduled")
1106+
Z11 = (20345, "Z11", "Post-Investigation appointment rescheduled")
1107+
Z12 = (
1108+
205221,
1109+
"Z12",
1110+
"Redirected Colonoscopy Assessment Appointment Cancellation Requested by SC prior to Preparation of Letters",
1111+
)
1112+
Z2 = (
1113+
11290,
1114+
"Z2",
1115+
"Appointment Cancellation Requested by SC (follows a DNA) prior to Letter Preparation",
1116+
)
1117+
Z3 = (
1118+
15006,
1119+
"Z3",
1120+
"Appointment Cancellation Requested by SC prior to Letter Preparation",
1121+
)
1122+
Z4 = (
1123+
15007,
1124+
"Z4",
1125+
"Appointment Cancellation Requested by SC (follows a DNA) prior to Letter Preparation",
1126+
)
1127+
Z5 = (
1128+
15008,
1129+
"Z5",
1130+
"Appointment Cancellation Requested prior to Letter Preparation (Patient to Reschedule)",
1131+
)
1132+
Z6 = (
1133+
15009,
1134+
"Z6",
1135+
"Appointment Cancellation Requested (follows a DNA) prior to Letter Preparation (Patient to Reschedule)",
1136+
)
1137+
Z7 = (
1138+
15010,
1139+
"Z7",
1140+
"Appointment Cancellation Requested prior to Letter Preparation (SC Non-attendance)",
1141+
)
1142+
Z8 = (
1143+
15011,
1144+
"Z8",
1145+
"Appointment Cancellation Requested (follows a DNA) prior to Letter Preparation (SC Non-attendance)",
1146+
)
1147+
Z9 = (160174, "Z9", "Post-investigation Appointment Cancelled Letters not Prepared")
10241148

10251149
def __init__(self, valid_value_id: int, allowed_value: str, description: str):
10261150
"""

0 commit comments

Comments
 (0)