Skip to content

Commit

Permalink
Merge pull request #828 from jan-stanek/active-nonregistered
Browse files Browse the repository at this point in the history
Odebrání expirace a počtu dávek, očkování pro neregistrované
  • Loading branch information
msusicky authored Apr 22, 2024
2 parents 25b66bc + c8b7413 commit 2f619af
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 45 deletions.
9 changes: 4 additions & 5 deletions app/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def praktici_admin_edit():
telefon = request.form.get('telefon')
user.telefon = telefon if telefon else None

user.neregistrovani = request.form.get('neregistrovani') is not None

db.session.merge(user)

for i in range(len(request.form.getlist('typ_vakciny[]'))):
Expand All @@ -126,18 +128,15 @@ def praktici_admin_edit():
vaccine.nemoc = nemoc
vaccine.typ_vakciny = typ_vakciny

pocet_davek = request.form.getlist('pocet_davek[]')[i]
vaccine.pocet_davek = pocet_davek if pocet_davek.isnumeric() else 0
aktivni = [int(v) - 1 for v in request.form.getlist('aktivni[]')]
vaccine.aktivni = i in aktivni

dospeli = [int(v) - 1 for v in request.form.getlist('dospeli[]')]
vaccine.dospeli = i in dospeli

deti = [int(v) - 1 for v in request.form.getlist('deti[]')]
vaccine.deti = i in deti

expirace = request.form.getlist('expirace[]')[i]
vaccine.expirace = expirace if len(expirace) > 0 else None

vaccine.datum_aktualizace = datetime.now()

vaccine.poznamka = request.form.getlist('poznamka[]')[i]
Expand Down
2 changes: 2 additions & 0 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,7 @@ class PrakticiLogin(db.Model):
heslo = Column(Unicode, nullable=False)
email = Column(Unicode)
telefon = Column(Unicode)
neregistrovani = Column(Boolean, nullable=False)

def __init__(self, id, passwd):
self.zdravotnicke_zarizeni_kod = id
Expand All @@ -1050,6 +1051,7 @@ class PrakticiKapacity(db.Model):
dospeli = Column(Boolean, nullable=False)
expirace = Column(Date)
nemoc = Column(Unicode, nullable=False)
aktivni = Column(Boolean, nullable=False)

def __repr__(self):
return f"<PrakticiKapacity(zdravotnicke_zarizeni_kod='{self.zdravotnicke_zarizeni_kod}')>"
Expand Down
28 changes: 11 additions & 17 deletions app/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,16 @@ def find_doctor_offices(nrpzs_kod):
f"""
select coalesce(z.zarizeni_nazev, min(s.nazev_cely)) zarizeni_nazev, o.nazev okres, k.nazev kraj,
k.nazev_kratky kraj_kratky, s.druh_zarizeni, s.obec, s.psc, s.ulice, s.cislo_domu,
coalesce(p.telefon, s.telefon) telefon_c, coalesce(p.email, s.email) email_c, s.web, s.latitude, s.longitude
coalesce(p.telefon, s.telefon) telefon_c, coalesce(p.email, s.email) email_c, s.web, s.latitude, s.longitude,
p.neregistrovani
from ockovaci_zarizeni z
full join zdravotnicke_stredisko s on s.nrpzs_kod = z.id
left join praktici_login p on substring(p.zdravotnicke_zarizeni_kod from 1 for 11) = s.nrpzs_kod
left join okresy o on o.id = coalesce(z.okres_id, s.okres_kod)
join kraje k on k.id = o.kraj_id
where z.id = '{nrpzs_kod}' or s.nrpzs_kod = '{nrpzs_kod}'
group by z.zarizeni_nazev, o.nazev, k.nazev, k.nazev_kratky, s.druh_zarizeni, s.obec, s.psc, s.ulice,
s.cislo_domu, telefon_c, email_c, s.web, s.latitude, s.longitude
s.cislo_domu, telefon_c, email_c, s.web, s.latitude, s.longitude, p.neregistrovani
""",
db.engine)

Expand All @@ -121,9 +122,7 @@ def find_doctors(okres_id=None, kraj_id=None):
join kraje k on k.id = o.kraj_id
left join zarizeni_metriky m on m.zarizeni_id = z.id and m.datum = '{get_import_date()}'
left join (
select left(zdravotnicke_zarizeni_kod, 11) nrpzs_kod
from praktici_kapacity n
where n.pocet_davek > 0 and (n.expirace is null or n.expirace >= '{get_import_date()}')
select left(zdravotnicke_zarizeni_kod, 11) nrpzs_kod from praktici_kapacity n where n.aktivni
) n on n.nrpzs_kod = z.id
where prakticky_lekar = True
and (z.okres_id = {okres_id_sql} or {okres_id_sql} is null)
Expand Down Expand Up @@ -155,9 +154,7 @@ def find_doctors_map():
left join zdravotnicke_stredisko s on s.nrpzs_kod = z.id
left join zarizeni_metriky m on m.zarizeni_id = z.id and m.datum = '{get_import_date()}'
left join (
select left(zdravotnicke_zarizeni_kod, 11) nrpzs_kod
from praktici_kapacity n
where n.pocet_davek > 0 and (n.expirace is null or n.expirace >= '{get_import_date()}')
select left(zdravotnicke_zarizeni_kod, 11) nrpzs_kod from praktici_kapacity n where n.aktivni
) n on n.nrpzs_kod = z.id
where prakticky_lekar = True
group by z.id, z.zarizeni_nazev, z.provoz_ukoncen, s.latitude, s.longitude, m.ockovani_pocet_davek,
Expand Down Expand Up @@ -188,10 +185,10 @@ def find_doctors_vaccine_options():


def find_free_vaccines_available(nrpzs_kod=None, okres_id=None, kraj_id=None):
return db.session.query(PrakticiKapacity.datum_aktualizace, PrakticiKapacity.pocet_davek, PrakticiKapacity.nemoc,
return db.session.query(PrakticiKapacity.datum_aktualizace, PrakticiKapacity.aktivni, PrakticiKapacity.nemoc,
PrakticiKapacity.typ_vakciny, PrakticiKapacity.deti, PrakticiKapacity.dospeli,
PrakticiKapacity.expirace, PrakticiKapacity.poznamka, PrakticiLogin.email,
PrakticiLogin.telefon, ZdravotnickeStredisko.nazev_cely, ZdravotnickeStredisko.obec,
PrakticiKapacity.poznamka, PrakticiLogin.email, PrakticiLogin.telefon,
PrakticiLogin.neregistrovani, ZdravotnickeStredisko.nazev_cely, ZdravotnickeStredisko.obec,
ZdravotnickeStredisko.kraj, ZdravotnickeStredisko.nrpzs_kod, ZdravotnickeStredisko.latitude,
ZdravotnickeStredisko.longitude, ZdravotnickeStredisko.email.label('email_nrpzs'),
ZdravotnickeStredisko.telefon.label('telefon_nrpzs')) \
Expand All @@ -201,26 +198,23 @@ def find_free_vaccines_available(nrpzs_kod=None, okres_id=None, kraj_id=None):
.filter(or_(func.left(PrakticiKapacity.zdravotnicke_zarizeni_kod, 11) == nrpzs_kod, nrpzs_kod is None)) \
.filter(or_(ZdravotnickeStredisko.okres_kod == okres_id, okres_id is None)) \
.filter(or_(ZdravotnickeStredisko.kraj_kod == kraj_id, kraj_id is None)) \
.filter(PrakticiKapacity.pocet_davek > 0) \
.filter(or_(PrakticiKapacity.expirace == None, PrakticiKapacity.expirace >= get_import_date())) \
.filter(PrakticiKapacity.aktivni) \
.order_by(ZdravotnickeStredisko.kraj, ZdravotnickeStredisko.obec, ZdravotnickeStredisko.nazev_cely,
PrakticiKapacity.typ_vakciny) \
.all()


def find_free_vaccines_vaccine_options():
return db.session.query(PrakticiKapacity.typ_vakciny) \
.filter(PrakticiKapacity.pocet_davek > 0) \
.filter(or_(PrakticiKapacity.expirace == None, PrakticiKapacity.expirace >= get_import_date())) \
.filter(PrakticiKapacity.aktivni) \
.distinct(PrakticiKapacity.typ_vakciny) \
.order_by(PrakticiKapacity.typ_vakciny) \
.all()


def find_free_vaccines_illness_options():
return db.session.query(PrakticiKapacity.nemoc) \
.filter(PrakticiKapacity.pocet_davek > 0) \
.filter(or_(PrakticiKapacity.expirace == None, PrakticiKapacity.expirace >= get_import_date())) \
.filter(PrakticiKapacity.aktivni) \
.distinct(PrakticiKapacity.nemoc) \
.order_by(PrakticiKapacity.nemoc) \
.all()
Expand Down
24 changes: 13 additions & 11 deletions app/templates/macros/tables/volne_vakciny.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

{% if not detail_mode %}
<div class="form-row mb-1">
<div class="col-12 col-lg-6 mb-2">
<div class="col-12 col-lg-4 mb-2">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fa fa-search fa-fw"></i></span>
Expand Down Expand Up @@ -50,10 +50,14 @@
<input id="free-vaccines-adults" type="checkbox" class="custom-control-input" checked>
<label class="custom-control-label" for="free-vaccines-adults">dospělí</label>
</div>
<div class="custom-control custom-switch" style="display: inline-block">
<div class="custom-control custom-switch mr-2" style="display: inline-block">
<input id="free-vaccines-children" type="checkbox" class="custom-control-input" checked>
<label class="custom-control-label" for="free-vaccines-children">děti</label>
</div>
<div class="custom-control custom-switch" style="display: inline-block">
<input id="free-vaccines-nonregistered" type="checkbox" class="custom-control-input">
<label class="custom-control-label" for="free-vaccines-nonregistered">i pro neregistrované</label>
</div>
</div>
</div>
{% endif %}
Expand All @@ -71,16 +75,14 @@
{% if detail_mode %}
<th scope="col" class="text-center">Věkové skupiny</th>
{% endif %}
<th scope="col" class="text-center col-sortable">Dávek</th>
<th scope="col" class="text-center col-sortable">Expirace</th>
<th scope="col" class="text-center">Poznámka</th>
<th scope="col" class="text-center">Aktualizace</th>
</tr>
</thead>
<tbody>
{% for item in free_vaccines %}
<tr data-kraj="{{ item.kraj }}" data-illness="{{ item.nemoc }}" data-vaccine="{{ item.typ_vakciny }}"
data-adults="{{ item.dospeli }}" data-children="{{ item.deti }}">
data-adults="{{ item.dospeli }}" data-children="{{ item.deti }}" data-nonregistered="{{ item.neregistrovani }}">
<td data-value="{{ item.nemoc }}">
{{ item.nemoc }}
</td>
Expand All @@ -106,12 +108,6 @@
{{ 'dospělí, děti' if item.dospeli and item.deti else 'děti' if item.deti else 'dospělí' if item.dospeli else '' }}
</td>
{% endif %}
<td class="text-right" data-value="{{ item.pocet_davek }}">
{{ item.pocet_davek | format_number }}
</td>
<td class="text-right" data-value="{{ item.expirace }}">
{{ item.expirace | format_date if item.expirace else "" }}
</td>
<td>
{{ item.poznamka }}
</td>
Expand All @@ -133,19 +129,22 @@
const illnessValue = $("#free-vaccines-illness").val();
const adultsValue = $("#free-vaccines-adults")[0].checked;
const childrenValue = $("#free-vaccines-children")[0].checked;
const nonregisteredValue = $("#free-vaccines-nonregistered")[0].checked;

$("#free-vaccines-table tbody tr").filter(function () {
const normalized = stripAccents($(this).text().toLowerCase());
const kraj = $(this)[0].dataset.kraj;
const illness = $(this)[0].dataset.illness;
const adults = $(this)[0].dataset.adults;
const children = $(this)[0].dataset.children;
const nonregistered = $(this)[0].dataset.nonregistered;

$(this).toggle(
normalized.indexOf(searchValue) > -1
&& (!krajValue || kraj === krajValue)
&& (!illnessValue || illness === illnessValue)
&& ((adultsValue && adults === 'True') || (childrenValue && children === 'True'))
&& (!nonregisteredValue || nonregistered === 'True')
)
});

Expand Down Expand Up @@ -176,6 +175,9 @@
}
offersFilterChanged();
});
$("#free-vaccines-nonregistered").change(function () {
offersFilterChanged();
});
offersFilterChanged();
});
</script>
Expand Down
17 changes: 9 additions & 8 deletions app/templates/praktici_admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,20 @@ <h5>Kontakt</h5>
</div>

<h5>Nabídky</h5>
<div class="custom-control custom-switch mb-2" style="display: inline-block">
<input id="neregistrovani" type="checkbox" name="neregistrovani" value="1" class="custom-control-input" {{ "checked" if user.neregistrovani else "" }}/>
<label class="custom-control-label" for="neregistrovani" >očkujeme i neregistrované pacienty</label>
</div>

<div class="table-responsive mb-3">
<table id="centers-table" class="table table-bordered table-striped table-sm mb-0">
<thead class="thead-dark">
<tr>
<th scope="col" class="text-center">Nemoc</th>
<th scope="col" class="text-center">Vakcína</th>
<th scope="col" class="text-center">Dávek</th>
<th scope="col" class="text-center">Nabízíme</th>
<th scope="col" class="text-center">Dospělí</th>
<th scope="col" class="text-center">Děti</th>
<th scope="col" class="text-center">Expirace</th>
<th scope="col" class="text-center">Poznámka</th>
</tr>
</thead>
Expand All @@ -85,8 +89,8 @@ <h5>Nabídky</h5>
<input type="hidden" name="typ_vakciny[]" value="{{ vaccine.vyrobce }}"/>
{{ vaccine.vyrobce }}
</td>
<td>
<input type="number" name="pocet_davek[]" value="{{ 0 if vaccine.pocet_davek is none else vaccine.pocet_davek }}" min="0" max="10000"/>
<td class="text-center">
<input type="checkbox" name="aktivni[]" value="{{ loop.index }}" {{ "checked" if vaccine.aktivni else "" }}/>
</td>
<td class="text-center">
<input type="checkbox" name="dospeli[]" value="{{ loop.index }}" {{ "checked" if (vaccine.dospeli is none and vaccine.druh_zarizeni_kod != 321) or vaccine.dospeli else "" }}/>
Expand All @@ -95,10 +99,7 @@ <h5>Nabídky</h5>
<input type="checkbox" name="deti[]" value="{{ loop.index }}" {{ "checked" if (vaccine.deti is none and vaccine.druh_zarizeni_kod == 321) or vaccine.deti else "" }}/>
</td>
<td>
<input type="date" name="expirace[]" value="{{ vaccine.expirace }}"/>
</td>
<td>
<input type="text" name="poznamka[]" value="{{ '' if vaccine.poznamka is none else vaccine.poznamka }}"/>
<input type="text" name="poznamka[]" value="{{ '' if vaccine.poznamka is none else vaccine.poznamka }}" style="width: 100%"/>
</td>
</tr>
{% endfor %}
Expand Down
5 changes: 5 additions & 0 deletions app/templates/praktik.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ <h5 class="card-title">Mapa</h5>
<div class="card">
<div class="card-body">
<h5 class="card-title">Nabídky očkování</h5>
{% if first_office.neregistrovani %}
<div class="alert alert-info" role="alert">
Očkujeme i neregistrované pacienty.
</div>
{% endif %}
{{ volne_vakciny(free_vaccines, detail_mode=True) }}
</div>
</div>
Expand Down
7 changes: 3 additions & 4 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def report():
@bp.route("/praktici_admin")
def praktici_admin():
if session.get('user_id') is not None and session.get('user_passwd') is not None:
user = db.session.query(PrakticiLogin.zdravotnicke_zarizeni_kod, PrakticiLogin.heslo,
user = db.session.query(PrakticiLogin.zdravotnicke_zarizeni_kod, PrakticiLogin.heslo, PrakticiLogin.neregistrovani,
coalesce(PrakticiLogin.telefon, ZdravotnickeStredisko.telefon).label('telefon'),
coalesce(PrakticiLogin.email, ZdravotnickeStredisko.email).label('email'),
ZdravotnickeStredisko.nazev_cely, ZdravotnickeStredisko.druh_zarizeni_kod) \
Expand All @@ -520,9 +520,8 @@ def praktici_admin():
.filter(PrakticiLogin.zdravotnicke_zarizeni_kod == session['user_id']) \
.filter(PrakticiLogin.heslo == session['user_passwd']) \
.one_or_none()
user_vaccines = db.session.query(Vakcina.nemoc, Vakcina.vyrobce, PrakticiKapacity.pocet_davek,
PrakticiKapacity.dospeli, PrakticiKapacity.deti, PrakticiKapacity.expirace,
PrakticiKapacity.poznamka) \
user_vaccines = db.session.query(Vakcina.nemoc, Vakcina.vyrobce, PrakticiKapacity.aktivni,
PrakticiKapacity.dospeli, PrakticiKapacity.deti, PrakticiKapacity.poznamka) \
.outerjoin(PrakticiKapacity, and_(PrakticiKapacity.nemoc == Vakcina.nemoc,
PrakticiKapacity.typ_vakciny == Vakcina.vyrobce,
PrakticiKapacity.zdravotnicke_zarizeni_kod == session['user_id'])) \
Expand Down

0 comments on commit 2f619af

Please sign in to comment.