Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve positive had injury description #181

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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(

Check warning on line 1077 in src/ctk_functions/routers/intake/intake_processing/writer.py

View check run for this annotation

Codecov / codecov/patch

src/ctk_functions/routers/intake/intake_processing/writer.py#L1077

Added line #L1077 was not covered by tests
parser_models.PriorDisease(
name="head injury",
was_positive=False,
),
)
head_injury_text = ""

Check warning on line 1083 in src/ctk_functions/routers/intake/intake_processing/writer.py

View check run for this annotation

Codecov / codecov/patch

src/ctk_functions/routers/intake/intake_processing/writer.py#L1083

Added line #L1083 was not covered by tests
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
Loading