Spaces:
Running
Running
File size: 7,211 Bytes
7bc5fde | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | class FeatureMapper:
def __init__(self):
# Mapping between patient-facing questions and the trained inference schema.
self.feature_mapping = {
"basic_info": {
"age": {
"question": "What is your age?",
"type": "numeric",
"dataset_feature": "age",
},
"sex": {
"question": "What is your biological sex?",
"type": "categorical",
"options": ["Male", "Female"],
"dataset_feature": "SEX",
"mapping": {"Male": 1, "Female": 0},
},
"education": {
"question": "Years of education completed?",
"type": "numeric",
"dataset_feature": "EDUCYRS",
},
"race": {
"question": "What is your race?",
"type": "categorical",
"options": ["White", "Black/African American", "Asian", "Other"],
"dataset_feature": "race",
"mapping": {
"White": 1,
"Black/African American": 2,
"Asian": 3,
"Other": 4,
},
},
"bmi": {
"question": "What is your BMI?",
"type": "numeric",
"dataset_feature": "BMI",
},
},
"family_history": {
"family_pd": {
"question": "Do you have any family members with Parkinson's disease?",
"type": "categorical",
"options": [
"No family history",
"First degree relative",
"Other relative",
],
"dataset_feature": "fampd",
"mapping": {
"No family history": 3,
"First degree relative": 1,
"Other relative": 2,
},
}
},
"motor_symptoms": {
"tremor": {
"question": "Tremor severity (0-4)",
"type": "numeric",
"dataset_feature": "sym_tremor",
"scale": "0-4",
},
"rigidity": {
"question": "Rigidity severity (0-4)",
"type": "numeric",
"dataset_feature": "sym_rigid",
"scale": "0-4",
},
"bradykinesia": {
"question": "Bradykinesia severity (0-4)",
"type": "numeric",
"dataset_feature": "sym_brady",
"scale": "0-4",
},
"balance": {
"question": "Postural instability severity (0-4)",
"type": "numeric",
"dataset_feature": "sym_posins",
"scale": "0-4",
},
},
"non_motor_symptoms": {
"rem_sleep": {
"question": "Do you act out dreams or have REM sleep behaviour symptoms?",
"type": "categorical",
"options": ["No", "Yes"],
"dataset_feature": "rem",
"mapping": {"No": 0, "Yes": 1},
},
"daytime_sleepiness": {
"question": "Epworth Sleepiness Scale score?",
"type": "numeric",
"dataset_feature": "ess",
"scale": "0-24",
},
"depression": {
"question": "Geriatric Depression Scale score?",
"type": "numeric",
"dataset_feature": "gds",
"scale": "0-15",
},
"anxiety": {
"question": "State-Trait Anxiety Inventory score?",
"type": "numeric",
"dataset_feature": "stai",
"scale": "20-80",
},
},
"cognitive_symptoms": {
"memory": {
"question": "MoCA score?",
"type": "numeric",
"dataset_feature": "moca",
"scale": "0-30",
},
"clock_draw": {
"question": "Clock drawing test score?",
"type": "numeric",
"dataset_feature": "clockdraw",
"scale": "0-4",
},
"bjlot": {
"question": "Benton line orientation score?",
"type": "numeric",
"dataset_feature": "bjlot",
"scale": "0-30",
},
},
}
def get_patient_questionnaire(self):
"""Generate a list of questions for patients."""
questions = []
for category in self.feature_mapping.values():
for feature in category.values():
questions.append(
{
"question": feature["question"],
"type": feature["type"],
"options": feature.get("options"),
"scale": feature.get("scale"),
}
)
return questions
def map_patient_response_to_features(self, responses):
"""Map patient responses to dataset features."""
feature_values = {}
for category in self.feature_mapping.values():
for feature_name, feature_info in category.items():
if feature_name not in responses:
continue
response = responses[feature_name]
dataset_feature = feature_info["dataset_feature"]
if "mapping" in feature_info:
mapped_value = feature_info["mapping"].get(response)
else:
mapped_value = response
if mapped_value is None:
continue
feature_values[dataset_feature] = mapped_value
if dataset_feature == "fampd":
feature_values["fampd_bin"] = 2 if mapped_value == 3 else 1
return feature_values
def main():
mapper = FeatureMapper()
questions = mapper.get_patient_questionnaire()
print("Patient Questionnaire:")
for i, q in enumerate(questions, 1):
print(f"\n{i}. {q['question']}")
if q["options"]:
print(f"Options: {', '.join(q['options'])}")
if q["scale"]:
print(f"Scale: {q['scale']}")
if __name__ == "__main__":
main()
|