Skip to content

Commit

Permalink
Merge pull request #429 from noharm-ai/develop
Browse files Browse the repository at this point in the history
v4.24-beta
  • Loading branch information
marceloarocha authored Jan 13, 2025
2 parents 8a92af8 + ff8181b commit ee83a36
Show file tree
Hide file tree
Showing 23 changed files with 872 additions and 227 deletions.
4 changes: 2 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class Config:
VERSION = "v4.23-beta"
FRONTEND_VERSION = "4.0.14"
VERSION = "v4.24-beta"
FRONTEND_VERSION = "4.0.18"
ENV = getenv("ENV") or NoHarmENV.DEVELOPMENT.value
SECRET_KEY = getenv("SECRET_KEY") or "secret_key"
API_KEY = getenv("API_KEY") or ""
Expand Down
2 changes: 2 additions & 0 deletions mobile.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from routes.admin.admin_unit_conversion import app_admin_unit_conversion
from routes.admin.admin_substance import app_admin_subs
from routes.admin.admin_relation import app_admin_relation
from routes.admin.admin_unit import app_admin_unit
from routes.reports.reports_general import app_rpt_general
from routes.reports.reports_config_rpt import app_rpt_config
from routes.reports.reports_culture import app_rpt_culture
Expand Down Expand Up @@ -109,6 +110,7 @@
app.register_blueprint(app_admin_unit_conversion)
app.register_blueprint(app_admin_subs)
app.register_blueprint(app_admin_relation)
app.register_blueprint(app_admin_unit)

app.register_blueprint(app_rpt_general)
app.register_blueprint(app_rpt_culture)
Expand Down
7 changes: 3 additions & 4 deletions models/appendix.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from .main import db
from sqlalchemy import text
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm import deferred
from flask_sqlalchemy.session import Session

from .main import db


class Department(db.Model):
Expand All @@ -27,6 +25,7 @@ class MeasureUnit(db.Model):
id = db.Column("fkunidademedida", db.String, primary_key=True)
idHospital = db.Column("fkhospital", db.BigInteger, nullable=False)
description = db.Column("nome", db.String, nullable=False)
measureunit_nh = db.Column("unidademedida_nh", db.String, nullable=True)


class MeasureUnitConvert(db.Model):
Expand Down
5 changes: 5 additions & 0 deletions models/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,8 @@ class RegulationAction(Enum):
UPDATE_RISK = 6
UNDO_SCHEDULE = 7
UNDO_TRANSPORTATION_SCHEDULE = 8


class SegmentTypeEnum(Enum):
ADULT = 1
PEDIATRIC = 2
11 changes: 10 additions & 1 deletion models/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import redis
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import func, or_, asc
from sqlalchemy import or_, asc
from datetime import date
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm import deferred
Expand Down Expand Up @@ -96,6 +96,13 @@ class Substance(db.Model):
link = db.Column("link", db.String(255), nullable=False)
idclass = db.Column("idclasse", db.String(255), nullable=False)
active = db.Column("ativo", db.Boolean, nullable=False)
maxdose_adult = db.Column("dosemax_adulto", db.Float, nullable=True)
maxdose_pediatric = db.Column("dosemax_pediatrico", db.Float, nullable=True)
maxdose_adult_weight = db.Column("dosemax_peso_adulto", db.Float, nullable=True)
maxdose_pediatric_weight = db.Column(
"dosemax_peso_pediatrico", db.Float, nullable=True
)
default_measureunit = db.Column("unidadepadrao", db.String, nullable=True)
handling = deferred(
db.Column("manejo", postgresql.JSONB(none_as_null=True), nullable=True)
)
Expand Down Expand Up @@ -207,6 +214,8 @@ class DrugAttributesBase:
fasting = db.Column("jejum", db.Boolean, nullable=True)
update = db.Column("update_at", db.DateTime, nullable=True)
user = db.Column("update_by", db.BigInteger, nullable=True)
ref_maxdose = db.Column("ref_dosemaxima", db.Float, nullable=True)
ref_maxdose_weight = db.Column("ref_dosemaxima_peso", db.Float, nullable=True)


class DrugAttributes(db.Model, DrugAttributesBase):
Expand Down
7 changes: 7 additions & 0 deletions models/requests/admin/admin_unit_conversion_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import BaseModel


class SetFactorRequest(BaseModel):
idDrug: int
idSegment: int
factor: float
1 change: 1 addition & 0 deletions models/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Segment(db.Model):
id = db.Column("idsegmento", db.BigInteger, primary_key=True)
description = db.Column("nome", db.String, nullable=False)
status = db.Column("status", db.Integer, nullable=False)
type = db.Column("tp_segmento", db.Integer, nullable=True)


class SegmentExam(db.Model):
Expand Down
68 changes: 68 additions & 0 deletions repository/drug_attributes_repository.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from sqlalchemy import text

from models.main import db


def update_dose_max(update_list: list[dict], schema: str):
update_table = []

for item in update_list:
update_table.append(
f"""({item.get("idDrug")}, {item.get("idSegment")}, {item.get("dosemax", "null")}, {item.get("dosemaxWeight", "null")})"""
)

query = text(
f"""
with update_table as (
select * from (values {",".join(update_table)}) AS t (fkmedicamento, idsegmento, ref_dosemaxima, ref_dosemaxima_peso)
)
update
{schema}.medatributos
set
ref_dosemaxima = update_table.ref_dosemaxima::float,
ref_dosemaxima_peso = update_table.ref_dosemaxima_peso::float
from
update_table
where
update_table.fkmedicamento = {schema}.medatributos.fkmedicamento
and update_table.idsegmento = {schema}.medatributos.idsegmento
"""
)

db.session.execute(query)


def copy_dose_max_from_ref(schema: str):
query = text(
f"""
with update_table as (
select
m.fkmedicamento,
m.idsegmento,
case
when m.usapeso then m.ref_dosemaxima_peso
else m.ref_dosemaxima
end as dosemaxima
from
{schema}.medatributos m
where
m.dosemaxima is null
and (
(m.usapeso = true and m.ref_dosemaxima_peso is not null)
or
((m.usapeso = false or m.usapeso is null) and m.ref_dosemaxima is not null)
)
)
update
{schema}.medatributos
set
dosemaxima = update_table.dosemaxima::float
from
update_table
where
update_table.fkmedicamento = {schema}.medatributos.fkmedicamento
and update_table.idsegmento = {schema}.medatributos.idsegmento
"""
)

return db.session.execute(query)
Loading

0 comments on commit ee83a36

Please sign in to comment.