diff --git a/src/ctk_functions/microservices/redcap.py b/src/ctk_functions/microservices/redcap.py index 7a10cbe..2ce8c54 100644 --- a/src/ctk_functions/microservices/redcap.py +++ b/src/ctk_functions/microservices/redcap.py @@ -429,15 +429,6 @@ def intake_name(self) -> str: return self.name.replace("_", " ") -class PriorDisease(pydantic.BaseModel): - """Class used for prior diseases in the Primary Care Information.""" - - name: str - was_positive: bool - age: str | None - treatment: str | None - - class Intervention(pydantic.BaseModel): """Information about Early Intervention and CPSE services.""" diff --git a/src/ctk_functions/routers/intake/intake_processing/parser.py b/src/ctk_functions/routers/intake/intake_processing/parser.py index 74d3c66..884e1ca 100644 --- a/src/ctk_functions/routers/intake/intake_processing/parser.py +++ b/src/ctk_functions/routers/intake/intake_processing/parser.py @@ -646,7 +646,7 @@ def __init__(self, patient_data: redcap.RedCapData) -> None: """) diseases = [ - redcap.PriorDisease( + parser_models.PriorDisease( name=disease, was_positive=getattr(patient_data, disease), age=getattr(patient_data, f"{disease}_age"), @@ -654,15 +654,8 @@ def __init__(self, patient_data: redcap.RedCapData) -> None: ) for disease in ("seizures", "migraines", "meningitis", "encephalitis") ] - diseases.append( - redcap.PriorDisease( - name="head injury", - was_positive=patient_data.head_injuries, - age=None, - treatment=None, - ), - ) - self.prior_diseases = transformers.PriorDiseases(diseases).transform() + self.head_injury = patient_data.head_injury_yes + self.prior_diseases = transformers.PriorDiseases(diseases) class SocialFunctioning: diff --git a/src/ctk_functions/routers/intake/intake_processing/parser_models.py b/src/ctk_functions/routers/intake/intake_processing/parser_models.py index 5e6dca6..6765236 100644 --- a/src/ctk_functions/routers/intake/intake_processing/parser_models.py +++ b/src/ctk_functions/routers/intake/intake_processing/parser_models.py @@ -121,3 +121,12 @@ def split_comma_separated_values(cls, value: str | list[str] | None) -> list[str if value is None: return [] return value.lower().split(",") + + +class PriorDisease(pydantic.BaseModel): + """Class used for prior diseases in the Primary Care Information.""" + + name: str + was_positive: bool + age: str | None = None + treatment: str | None = None diff --git a/src/ctk_functions/routers/intake/intake_processing/transformers.py b/src/ctk_functions/routers/intake/intake_processing/transformers.py index b2603f3..c993413 100644 --- a/src/ctk_functions/routers/intake/intake_processing/transformers.py +++ b/src/ctk_functions/routers/intake/intake_processing/transformers.py @@ -382,8 +382,10 @@ def transform(self) -> str: raise exceptions.TransformerError(msg) -class PriorDiseases(MultiTransformer[redcap.PriorDisease]): - """Transformer for the prior diseases information.""" +class PriorDiseases( + MultiTransformer[parser_models.PriorDisease], +): + """Transformer for the prior diseases' information.""" def transform(self) -> str: """Transforms the prior diseases information to a string. diff --git a/src/ctk_functions/routers/intake/intake_processing/writer.py b/src/ctk_functions/routers/intake/intake_processing/writer.py index 31a981c..2bf5e3b 100644 --- a/src/ctk_functions/routers/intake/intake_processing/writer.py +++ b/src/ctk_functions/routers/intake/intake_processing/writer.py @@ -1,6 +1,7 @@ """Contains report writing functionality for intake information.""" import asyncio +import copy import enum import itertools import re @@ -17,6 +18,7 @@ from ctk_functions.microservices import redcap from ctk_functions.routers.intake.intake_processing import ( parser, + parser_models, transformers, writer_llm, ) @@ -1067,9 +1069,30 @@ def write_medical_history(self) -> None: currently taking any medications for chronic medical conditions.""", f""" {primary_care.glasses_hearing_device}. - {primary_care.prior_diseases}. """, ] + + prior_diseases = copy.deepcopy(primary_care.prior_diseases) + if primary_care.head_injury is None: + prior_diseases.base.append( + parser_models.PriorDisease( + name="head injury", + was_positive=False, + ), + ) + head_injury_text = "" + else: + head_injury_text = self.llm.run_edit( + primary_care.head_injury, + additional_instruction=( + "The response should be a single sentence that rephrases this " + "parent's statement on their child's head injury" + ), + context=" ".join(texts), + comment=primary_care.head_injury, + ) + texts.append(head_injury_text) + texts.append(prior_diseases.transform()) texts = [string_utils.remove_excess_whitespace(text) for text in texts] self._insert("MEDICAL HISTORY", _StyleName.HEADING_1)