Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case amb #3087

Merged
merged 42 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b348c32
.
urchinpro Sep 22, 2023
7379597
случай
urchinpro Sep 22, 2023
4c03c71
конструктор случай
urchinpro Sep 22, 2023
eaefd3f
fix
urchinpro Sep 22, 2023
b167f46
fix
urchinpro Sep 22, 2023
99e6b06
fix
urchinpro Sep 22, 2023
2046432
fix
urchinpro Sep 22, 2023
1667c99
fix
urchinpro Sep 22, 2023
e18ba81
fix
urchinpro Sep 23, 2023
7768dc5
Update directory/models.py
urchinpro Sep 23, 2023
b3b10d9
Update api/views.py
urchinpro Sep 23, 2023
7f393f4
fix
urchinpro Sep 23, 2023
0326357
Merge remote-tracking branch 'origin/caseAmb' into caseAmb
urchinpro Sep 23, 2023
1b0b7b2
Случаи в истории
urchinpro Sep 26, 2023
390a27d
.
urchinpro Sep 26, 2023
5a2412f
.
urchinpro Sep 26, 2023
f7f9ddc
Исключено требование создавать случай внутри истории болезни
urchinpro Sep 27, 2023
5486c79
fix
urchinpro Sep 27, 2023
e65f035
Update api/directions/views.py
urchinpro Sep 27, 2023
4d67e31
Update api/directions/views.py
urchinpro Sep 27, 2023
94c9bbb
fix
urchinpro Sep 27, 2023
5188f4e
Merge remote-tracking branch 'origin/caseAmb' into caseAmb
urchinpro Sep 27, 2023
07e1bd5
fix date in xlsx
urchinpro Sep 27, 2023
b132d1d
add fielt to Napravleniya "paren_case"
urchinpro Sep 28, 2023
5efedc2
fix
urchinpro Sep 28, 2023
62387f1
fix cda gen lab
urchinpro Sep 29, 2023
581414c
автосоздание случая
urchinpro Sep 30, 2023
d087a08
fix
urchinpro Sep 30, 2023
cd2b61b
fix
urchinpro Sep 30, 2023
2e86003
fix
urchinpro Sep 30, 2023
ae39ed9
вывод услуг случая в "Истории" случая
urchinpro Oct 1, 2023
ddafb37
fix
urchinpro Oct 1, 2023
6c60cd7
fix
urchinpro Oct 1, 2023
4745778
fix
urchinpro Oct 1, 2023
5014c6a
Роль для редактирвоания случая
urchinpro Oct 1, 2023
aa3cd89
получить случай не скрытый
urchinpro Oct 1, 2023
84c7594
initial case ui
Oct 6, 2023
7b5b773
Merge branch 'caseAmb' into case-ui
Oct 6, 2023
288c71a
History case link
mikhailprivalov Oct 7, 2023
80d83e4
case directions ui
mikhailprivalov Oct 8, 2023
44c2d2b
aggregate base
mikhailprivalov Oct 8, 2023
de5e490
Merge pull request #3110 from moodpulse/case-ui
mikhailprivalov Oct 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added api/cases/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions api/cases/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from utils import tree_directions_case as tree_directions
from anytree import Node, RenderTree


def get_case_direction_tree(num_dir):
root_dir = tree_directions.root_direction(num_dir)
if not root_dir or not root_dir[-1]:
return {}
num_root_dir = root_dir[-1][-3]
result = tree_directions.get_research_by_dir(num_root_dir)
num_iss = result[0][0]

# отсортировать по подчинениям - построить бинарное дерево
tree_dir = tree_directions.hosp_tree_direction(num_iss)
final_tree = {}

node_dir = Node({'order': '-1', 'direction': '', 'research_title': '', 'correct_level': True, 'color': '', 'cancel': False, 'issledovaniye': '', 'parent_iss': ''})
for j in tree_dir:
research_title = j[12] if j[12] else j[9]
temp_s = {'order': '-1', 'direction': j[0], 'research_title': research_title, 'correct_level': True, 'color': '', 'cancel': j[14], 'issledovaniye': j[5], 'parent_iss': j[3]}
if not j[3]:
final_tree[j[5]] = Node(temp_s, parent=node_dir)
else:
final_tree[j[5]] = Node(temp_s, parent=final_tree.get(j[3]))

data_sort = []
count_level_second = 0
correct_level = True
for row in RenderTree(node_dir):
order = int(len(row.pre) / 4)
if order == 2:
count_level_second += 1
if count_level_second > 1:
correct_level = False
row.node.name['correct_level'] = correct_level
row.node.name['color'] = 'red'
if not correct_level and order > 2:
row.node.name['color'] = '#d35400'
row.node.name['correct_level'] = correct_level

row.node.name['order'] = order
data_sort.append(row.node.name)

data_sort.pop(0)
return data_sort
241 changes: 241 additions & 0 deletions api/cases/sql_func.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
from django.db import connection

from laboratory.settings import TIME_ZONE
from utils.db import namedtuplefetchall


def get_research(title_podr, vertical_result_display):
"""
Возврат: id услуги, title-услуги

"""

with connection.cursor() as cursor:
cursor.execute(
"""WITH
t_podr AS (
SELECT id as podr_id, title as podr_title FROM public.podrazdeleniya_podrazdeleniya),

t_research AS (
SELECT id as research_id, title as research_title, vertical_result_display, podrazdeleniye_id
FROM public.directory_researches)

SELECT research_id, research_title FROM t_research
LEFT JOIN t_podr
ON t_research.podrazdeleniye_id=t_podr.podr_id
WHERE podr_title = %(title_podr)s and vertical_result_display = %(vertical)s
ORDER BY research_id
""",
params={'title_podr': title_podr, 'vertical': vertical_result_display},
)

row = cursor.fetchall()
return row


def get_iss(list_research_id, list_dirs):
"""
Возврат: id-iss
добавить:
"""
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT id, research_id FROM public.directions_issledovaniya
WHERE napravleniye_id = ANY(ARRAY[%(num_dirs)s]) AND research_id = ANY(ARRAY[%(id_researches)s])
AND time_confirmation IS NOT NULL
""",
params={'id_researches': list_research_id, 'num_dirs': list_dirs},
)
row = cursor.fetchall()
return row


def get_distinct_research(list_research_id, list_dirs, is_text_research=False):
"""
Возврат: уникальных research
добавить:
"""
with connection.cursor() as cursor:
cursor.execute(
"""WITH
t_iss AS (SELECT id, research_id FROM public.directions_issledovaniya
WHERE CASE
WHEN %(is_text_research)s = TRUE THEN
napravleniye_id = ANY(ARRAY[%(num_dirs)s]) AND time_confirmation IS NOT NULL
WHEN %(is_text_research)s = FALSE THEN
napravleniye_id = ANY(ARRAY[%(num_dirs)s]) AND research_id = ANY(ARRAY[%(id_researches)s]) AND time_confirmation IS NOT NULL
END)

SELECT DISTINCT ON (research_id) research_id FROM t_iss

""",
params={'id_researches': list_research_id, 'num_dirs': list_dirs, 'is_text_research': is_text_research},
)
row = cursor.fetchall()
return row


def get_distinct_fraction(list_iss):
"""
Возвращает уникальные фракци(id, title, units), которые присутствуют во всех исследованиях
"""
with connection.cursor() as cursor:
cursor.execute(
"""WITH
t_fraction AS (SELECT id as id_frac, title as title_frac FROM public.directory_fractions ORDER BY id)

SELECT DISTINCT ON (fraction_id) fraction_id, title_frac, units FROM directions_result
LEFT JOIN t_fraction ON directions_result.fraction_id = t_fraction.id_frac
WHERE issledovaniye_id = ANY(ARRAY[%(id_iss)s])
ORDER by fraction_id
""",
params={'id_iss': list_iss},
)
row = cursor.fetchall()
return row


def get_result_fraction(list_iss):
"""
Возвращает результат: дата, фракция, значение(value)
"""
with connection.cursor() as cursor:
cursor.execute(
"""WITH
t_fraction AS (SELECT id as id_frac, title as title_frac FROM public.directory_fractions ORDER BY id),

t_iss AS (SELECT id as iss_id, napravleniye_id, to_char(time_confirmation AT TIME ZONE %(tz)s, 'DD.MM.YY') as date_confirm
FROM public.directions_issledovaniya
WHERE id = ANY(ARRAY[%(id_iss)s]) AND time_confirmation IS NOT NULL)

SELECT fraction_id, issledovaniye_id, title_frac, value, date_confirm, napravleniye_id FROM directions_result
LEFT JOIN t_fraction ON directions_result.fraction_id = t_fraction.id_frac
LEFT JOIN t_iss ON directions_result.issledovaniye_id = t_iss.iss_id
WHERE issledovaniye_id = ANY(ARRAY[%(id_iss)s])
ORDER by napravleniye_id, date_confirm
""",
params={'id_iss': list_iss, 'tz': TIME_ZONE},
)
row = cursor.fetchall()
return row


def get_result_text_research(research_pk, listdirs, force_all_fields=False):
with connection.cursor() as cursor:
cursor.execute(
"""
WITH
t_research AS (SELECT id as research_id, title as research_title FROM directory_researches
WHERE id = %(id_research)s),

t_groups AS (SELECT id as group_id, title as group_title, "order" as group_order
FROM public.directory_paraclinicinputgroups
WHERE research_id = %(id_research)s),

t_fields AS (SELECT id as field_id, title, "order" as field_order,
directory_paraclinicinputfield.group_id, group_title, group_order
FROM public.directory_paraclinicinputfield
LEFT JOIN t_groups on directory_paraclinicinputfield.group_id = t_groups.group_id
WHERE (directory_paraclinicinputfield.group_id in (SELECT group_id from t_groups) and
(
for_extract_card = true or
(%(force_all_fields)s = true and NOT (field_type = ANY(ARRAY[16,17]))))
) or
(directory_paraclinicinputfield.group_id in (SELECT group_id from t_groups) and title ILIKE 'Заключение')),

t_iss AS (SELECT directions_issledovaniya.id as iss_id, time_confirmation,
to_char(time_confirmation AT TIME ZONE %(tz)s, 'DD.MM.YY') as date_confirm,
napravleniye_id, t_research.research_title, ud.fio FROM directions_issledovaniya
LEFT JOIN t_research on t_research.research_id = directions_issledovaniya.research_id
LEFT JOIN users_doctorprofile ud ON
ud.id=directions_issledovaniya.doc_confirmation_id
WHERE directions_issledovaniya.research_id=%(id_research)s and napravleniye_id = ANY(ARRAY[%(id_dirs)s]) and time_confirmation is not Null)

SELECT research_title, date_confirm, napravleniye_id, group_title, title, "value", t_iss.iss_id, t_iss.fio, field_type FROM directions_paraclinicresult
LEFT JOIN t_iss on directions_paraclinicresult.issledovaniye_id = t_iss.iss_id
LEFT JOIN t_fields on directions_paraclinicresult.field_id = t_fields.field_id
WHERE issledovaniye_id in (SELECT iss_id from t_iss) and
directions_paraclinicresult.field_id in (SELECT field_id from t_fields)
order by time_confirmation, group_order, field_order

""",
params={'id_research': research_pk, 'id_dirs': listdirs, 'force_all_fields': force_all_fields, 'tz': TIME_ZONE},
)
row = cursor.fetchall()
return row


def get_result_value_iss(iss_pk, research_pk, titles_field):
with connection.cursor() as cursor:
cursor.execute(
"""
WITH
t_field AS (SELECT "id", title FROM directory_paraclinicinputfield
WHERE group_id in (SELECT "id" FROM directory_paraclinicinputgroups WHERE research_id=%(id_research)s)
AND title = ANY(ARRAY[%(titles_field)s]))

SELECT field_id, issledovaniye_id, "value", title FROM public.directions_paraclinicresult
LEFT JOIN t_field ON directions_paraclinicresult.field_id = t_field.id
where field_id in (SELECT "id" FROM t_field) and issledovaniye_id = %(id_iss)s


""",
params={'id_iss': iss_pk, 'id_research': research_pk, 'titles_field': titles_field},
)
row = cursor.fetchall()
return row


def get_result_temperature_list(iss_pk_list, research_pk, titles_field):
with connection.cursor() as cursor:
cursor.execute(
"""
WITH
t_field AS (SELECT "id", title FROM directory_paraclinicinputfield
WHERE group_id in (SELECT "id" FROM directory_paraclinicinputgroups WHERE research_id=%(id_research)s)
AND title = ANY(ARRAY[%(titles_field)s]))

SELECT field_id, issledovaniye_id, "value", title FROM public.directions_paraclinicresult
LEFT JOIN t_field ON directions_paraclinicresult.field_id = t_field.id
where field_id in (SELECT "id" FROM t_field) and issledovaniye_id = ANY(ARRAY[%(id_iss)s])
ORDER by issledovaniye_id


""",
params={'id_iss': iss_pk_list, 'id_research': research_pk, 'titles_field': titles_field},
)
row = cursor.fetchall()
return row


def get_assignments_by_history(history_id: int):
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT public.directions_napravleniya.id as napravlenie_id, public.directions_napravleniya.data_sozdaniya,
public.users_doctorprofile.fio as who_assigned, doc_list.fio as who_confirm, public.directions_napravleniya.total_confirmed,
public.directions_issledovaniya.time_confirmation, public.directory_researches.id as research_id, public.directory_researches.title as research_title

FROM public.directions_issledovaniya
INNER JOIN public.directions_napravleniya
ON public.directions_issledovaniya.napravleniye_id = public.directions_napravleniya.id
INNER JOIN public.directory_researches
ON public.directions_issledovaniya.research_id = public.directory_researches.id
INNER JOIN public.users_doctorprofile
ON public.directions_napravleniya.doc_id = public.users_doctorprofile.id
LEFT JOIN (SELECT id, fio FROM public.users_doctorprofile) as doc_list
ON public.directions_issledovaniya.doc_confirmation_id = doc_list.id

WHERE public.directions_napravleniya.parent_case_id = %(history_id)s
AND (is_paraclinic = true OR is_doc_refferal = true OR is_microbiology = true OR is_citology = true OR is_gistology = true OR
(is_paraclinic = False AND is_doc_refferal = False AND is_microbiology = False AND is_citology = False AND is_gistology = False
AND is_slave_hospital = False AND is_hospital = False AND is_case = False))
AND public.directions_napravleniya.cancel != true

ORDER BY public.directions_napravleniya.data_sozdaniya
""",
params={"history_id": history_id},
)
rows = namedtuplefetchall(cursor)
return rows
Loading