Skip to content

Commit

Permalink
feat: Improve positive had injury description (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
ReinderVosDeWael authored Jan 16, 2025
1 parent 29a9339 commit fad738d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
9 changes: 0 additions & 9 deletions src/ctk_functions/microservices/redcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
13 changes: 3 additions & 10 deletions src/ctk_functions/routers/intake/intake_processing/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,23 +646,16 @@ 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"),
treatment=getattr(patient_data, f"{disease}_treatment"),
)
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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 24 additions & 1 deletion src/ctk_functions/routers/intake/intake_processing/writer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Contains report writing functionality for intake information."""

import asyncio
import copy
import enum
import itertools
import re
Expand All @@ -17,6 +18,7 @@
from ctk_functions.microservices import redcap
from ctk_functions.routers.intake.intake_processing import (
parser,
parser_models,
transformers,
writer_llm,
)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fad738d

Please sign in to comment.