Skip to content

Commit

Permalink
intv: add outcome header
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloarocha committed Sep 13, 2024
1 parent e59c21f commit df9d952
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion services/intervention_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,38 @@ def _get_outcome_data_query():


def get_outcome_data(id_intervention, user: User, edit=False):
InterventionReasonParent = db.aliased(InterventionReason)
reason_column = case(
(
InterventionReasonParent.description != None,
func.concat(
InterventionReasonParent.description,
" - ",
InterventionReason.description,
),
),
else_=InterventionReason.description,
)

reason = (
db.session.query(reason_column)
.select_from(InterventionReason)
.outerjoin(
InterventionReasonParent,
InterventionReasonParent.id == InterventionReason.mamy,
)
.filter(InterventionReason.id == func.any(Intervention.idInterventionReason))
.as_scalar()
)

record = (
db.session.query(Intervention, PrescriptionDrug, Drug, User)
db.session.query(
Intervention,
PrescriptionDrug,
Drug,
User,
func.array(reason).label("reason"),
)
.outerjoin(PrescriptionDrug, PrescriptionDrug.id == Intervention.id)
.outerjoin(Drug, PrescriptionDrug.idDrug == Drug.id)
.outerjoin(User, Intervention.outcome_by == User.id)
Expand Down Expand Up @@ -867,6 +897,7 @@ def get_outcome_data(id_intervention, user: User, edit=False):
"status": intervention.status,
"readonly": readonly,
"date": intervention.date.isoformat(),
"interventionReason": record.reason,
},
}

Expand Down Expand Up @@ -978,6 +1009,7 @@ def _get_outcome_dict(
if intervention.date_end_economy != None
else None
),
"interventionReason": outcome_data.reason,
},
}

Expand Down

0 comments on commit df9d952

Please sign in to comment.