Skip to content

Commit

Permalink
format prevnotes
Browse files Browse the repository at this point in the history
  • Loading branch information
marceloarocha committed Jan 11, 2024
1 parent 6687432 commit d39377a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
23 changes: 15 additions & 8 deletions models/prescription.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,21 +822,28 @@ def getPrevNotes(admissionNumber):

return (
db.session.query(
func.concat(
prevNotes.notes,
" (",
prevUser.name,
" em ",
func.to_char(prevNotes.update, "DD/MM/YYYY HH24:MI"),
")",
case(
[
(
and_(prevNotes.notes != None, prevNotes.notes != ""),
func.concat(
prevNotes.notes,
" ##@",
prevUser.name,
" em ",
func.to_char(prevNotes.update, "DD/MM/YYYY HH24:MI"),
"@##",
),
),
],
else_=None,
)
)
.select_from(prevNotes)
.outerjoin(prevUser, prevNotes.user == prevUser.id)
.filter(prevNotes.admissionNumber == admissionNumber)
.filter(prevNotes.idDrug == PrescriptionDrug.idDrug)
.filter(prevNotes.idPrescriptionDrug < PrescriptionDrug.id)
.filter(and_(prevNotes.notes != None, prevNotes.notes != ""))
.order_by(desc(prevNotes.update))
.limit(1)
.as_scalar()
Expand Down
10 changes: 9 additions & 1 deletion routes/drugList.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from .utils import *
from models.appendix import *

Expand Down Expand Up @@ -365,6 +366,12 @@ def getDrugType(self, pDrugs, source):
period = (str(pd[0].period) + "D" if pd[0].period else "",)
total_period = none2zero(pd[0].period)

prevNotes = None
prevNotesUser = None
if pd[8]:
prevNotesUser = str(pd[8]).replace("##@", "(").replace("@##", ")")
prevNotes = re.sub(r"##@(.*)@##", "", str(pd[8]))

pDrugs.append(
{
"idPrescription": str(pd[0].idPrescription),
Expand Down Expand Up @@ -441,7 +448,8 @@ def getDrugType(self, pDrugs, source):
"alerts": alerts,
"tubeAlert": tubeAlert,
"notes": pd[7],
"prevNotes": pd[8],
"prevNotes": prevNotes,
"prevNotesUser": prevNotesUser,
"drugInfoLink": pd[11].link if pd[11] != None else None,
"idSubstance": pd[11].id if pd[11] != None else None,
"idSubstanceClass": pd[11].idclass if pd[11] != None else None,
Expand Down

0 comments on commit d39377a

Please sign in to comment.