Skip to content

Commit

Permalink
Merge pull request #69 from UMCU-Digital-Health/store_active_phone_nu…
Browse files Browse the repository at this point in the history
…mber

Added option to save which phone number was used to call
  • Loading branch information
WoltersEric authored Mar 11, 2024
2 parents 732feb3 + 2c9aca1 commit 06c9b2b
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.0.7] - 2024-03-11
### Changed
- phone number that was used to call patient is now stored


## [1.0.6] - 2024-02-07

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "noshow"
version = "1.0.6"
version = "1.0.7"
authors = [
{ name="Ruben Peters", email="[email protected]" }
]
Expand Down
54 changes: 40 additions & 14 deletions run/calling_dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from noshow.database.models import (
ApiCallResponse,
ApiPatient,
ApiPrediction,
ApiRequest,
ApiSensitiveInfo,
Expand Down Expand Up @@ -111,11 +112,33 @@ def main():
all_predictions_df.loc[
all_predictions_df["call_status"] == "Gebeld", "call_status"
] = "🟢"
all_predictions_df.loc[
all_predictions_df["call_status"] != "🟢", "call_status"
] = "🔴"
all_predictions_df.loc[all_predictions_df["call_status"] != "🟢", "call_status"] = (
"🔴"
)
pred_id = all_predictions_df.iat[st.session_state["pred_idx"], 0]

# load information related to call history
with Session() as session:
current_response = session.get(ApiPrediction, pred_id).callresponse_relation
current_patient_nmbr = session.get(
ApiPatient, patient_ids[st.session_state["name_idx"]]
)
if not current_response:
current_response = ApiCallResponse(
call_status="Niet gebeld",
call_outcome="Geen",
remarks="",
prediction_id=pred_id,
)
status_list = ["Niet gebeld", "Gebeld", "Onbereikbaar"]
res_list = ["Herinnerd", "Verzet/Geannuleerd", "Geen"]
call_number_list = [
"Niet van toepassing",
"Mobielnummer",
"Thuis telefoonnummer",
"Overig telefoonnummer",
]

# Main content of streamlit app
col1, col2, col3 = st.columns(3)
with col1:
Expand All @@ -140,6 +163,11 @@ def main():
st.write(f"- Mobiel: {current_patient.mobile_phone or 'Onbekend'}")
st.write(f"- Thuis: {current_patient.home_phone or 'Onbekend'}")
st.write(f"- Overig nummer: {current_patient.other_phone or 'Onbekend'}")
st.write("")
if not current_patient_nmbr.call_number:
current_patient_nmbr.call_number = 0
call_number_type = call_number_list[current_patient_nmbr.call_number]
st.write(f"- Eerder contact ging via: {call_number_type or 'Onbekend'}")
else:
st.write("Patientgegevens zijn verwijderd.")

Expand All @@ -152,18 +180,7 @@ def main():
hide_index=True,
)

with Session() as session:
current_response = session.get(ApiPrediction, pred_id).callresponse_relation
if not current_response:
current_response = ApiCallResponse(
call_status="Niet gebeld",
call_outcome="Geen",
remarks="",
prediction_id=pred_id,
)
with st.form("patient_form", clear_on_submit=True):
status_list = ["Niet gebeld", "Gebeld", "Onbereikbaar"]
res_list = ["Herinnerd", "Verzet/Geannuleerd", "Geen"]
st.selectbox(
"Status gesprek:",
options=status_list,
Expand All @@ -176,6 +193,14 @@ def main():
index=res_list.index(current_response.call_outcome),
key="res_input",
)
options_idx = [0, 1, 2, 3]
st.selectbox(
"Contact gemaakt via: ",
options=options_idx,
format_func=lambda x: call_number_list[x],
index=options_idx.index(current_patient_nmbr.call_number),
key="number_input",
)
st.text_input("Opmerkingen: ", value=current_response.remarks, key="opm_input")
st.form_submit_button(
"Volgende",
Expand All @@ -184,6 +209,7 @@ def main():
len(all_predictions_df),
Session,
current_response,
current_patient_nmbr,
),
type="primary",
)
Expand Down
12 changes: 11 additions & 1 deletion src/noshow/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
fix_outdated_appointments,
load_model,
)
from noshow.database.models import ApiPrediction, ApiRequest, ApiSensitiveInfo, Base
from noshow.database.models import (
ApiPatient,
ApiPrediction,
ApiRequest,
ApiSensitiveInfo,
Base,
)
from noshow.model.predict import create_prediction
from noshow.preprocessing.load_data import (
load_appointment_json,
Expand Down Expand Up @@ -150,6 +156,8 @@ async def predict(
apisensitive.home_phone = row["telecom2_value"]
apisensitive.other_phone = row["telecom3_value"]

apipatient = ApiPatient(id=row["pseudo_id"])

apiprediction = db.get(ApiPrediction, row["APP_ID"])
if not apiprediction:
apiprediction = ApiPrediction(
Expand All @@ -158,6 +166,7 @@ async def predict(
prediction=row["prediction"],
start_time=row["start"],
request_relation=apirequest,
patient_relation=apipatient,
clinic_name=row["hoofdagenda"],
clinic_reception=row["description"],
clinic_phone_number=add_clinic_phone(row["hoofdagenda"]),
Expand All @@ -175,6 +184,7 @@ async def predict(

db.merge(apisensitive)
db.merge(apiprediction)
db.merge(apipatient)
db.commit()

fix_outdated_appointments(db, prediction_df["APP_ID"], start_date)
Expand Down
7 changes: 6 additions & 1 deletion src/noshow/dashboard/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import streamlit as st
from sqlalchemy.orm import sessionmaker

from noshow.database.models import ApiCallResponse
from noshow.database.models import ApiCallResponse, ApiPatient


def highlight_row(row: pd.Series) -> List[str]:
Expand Down Expand Up @@ -38,6 +38,7 @@ def next_preds(
list_len: int,
Session: sessionmaker,
call_response: ApiCallResponse,
current_patient: ApiPatient,
) -> None:
"""Go to the next prediction and save results
Expand All @@ -49,13 +50,17 @@ def next_preds(
Session used to save the current call response
call_response : ApiCallResponse
call response object that needs to be edited
current_patient : ApiPatient
current patient object
"""
call_response.call_status = st.session_state.status_input
call_response.call_outcome = st.session_state.res_input
call_response.remarks = st.session_state.opm_input
current_patient.call_number = st.session_state.number_input

with Session() as session:
session.merge(call_response)
session.merge(current_patient)
session.commit()
if st.session_state["pred_idx"] + 1 < list_len:
st.session_state["pred_idx"] += 1
Expand Down
19 changes: 18 additions & 1 deletion src/noshow/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ class ApiRequest(Base):
api_version: Mapped[str]


class ApiPatient(Base):
__tablename__ = "apipatient"
__table_args__ = {"schema": "noshow"}

id: Mapped[str] = mapped_column(
String(64),
primary_key=True,
index=True,
)
call_number: Mapped[int] = mapped_column(Integer, init=False, nullable=True)


class ApiPrediction(Base):
__tablename__ = "apiprediction"
__table_args__ = {"schema": "noshow"}

id: Mapped[str] = mapped_column(String(50), primary_key=True, index=True)
patient_id: Mapped[str] = mapped_column(String(64), index=True)
prediction: Mapped[float] = mapped_column(Float, nullable=True)
start_time: Mapped[datetime] = mapped_column(DateTime, index=True)
clinic_name: Mapped[str]
Expand All @@ -41,10 +52,16 @@ class ApiPrediction(Base):
request_id: Mapped[int] = mapped_column(
Integer, ForeignKey(ApiRequest.id), init=False
)
patient_id: Mapped[str] = mapped_column(
String(64),
ForeignKey(ApiPatient.id),
index=True,
)
active: Mapped[bool]

request_relation: Mapped["ApiRequest"] = relationship()
callresponse_relation: Mapped["ApiCallResponse"] = relationship(init=False)
patient_relation: Mapped["ApiPatient"] = relationship()


class ApiSensitiveInfo(Base):
Expand Down

0 comments on commit 06c9b2b

Please sign in to comment.