Skip to content

Commit

Permalink
creat quick lookup function to determin if a patient has `withdrawn_f…
Browse files Browse the repository at this point in the history
…rom_research_study()`
  • Loading branch information
pbugni committed Mar 20, 2024
1 parent 89e13ae commit 1c1b21b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions portal/models/research_study.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from sqlalchemy.dialects.postgresql import ENUM

from ..cache import TWO_HOURS, cache
Expand Down Expand Up @@ -122,3 +123,17 @@ def add_static_research_studies():
rs = ResearchStudy.from_fhir(base)
if ResearchStudy.query.get(rs.id) is None:
db.session.add(rs)


def withdrawn_from_research_study(patient_id, research_study_id):
"""Check for withdrawn row in patients timeline
:returns: If withdrawn row found, returns withdrawal date, else None
"""
from .qb_timeline import QBT
from .overall_status import OverallStatus

withdrawn = QBT.query.filter(QBT.user_id == patient_id).filter(
QBT.research_study_id == research_study_id).filter(
QBT.status == OverallStatus.withdrawn).first()
return withdrawn.at if withdrawn else None

0 comments on commit 1c1b21b

Please sign in to comment.