Skip to content

Commit

Permalink
автосоздание случая
Browse files Browse the repository at this point in the history
  • Loading branch information
urchinpro committed Sep 30, 2023
1 parent 62387f1 commit 581414c
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 18 deletions.
7 changes: 4 additions & 3 deletions api/directions/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def get_directions_meta_info(directions):
return rows


def get_patient_open_case_data(card_pk):
def get_patient_open_case_data(card_pk, start_date, end_date):
with connection.cursor() as cursor:
cursor.execute(
"""
Expand All @@ -523,10 +523,11 @@ def get_patient_open_case_data(card_pk):
FROM directions_issledovaniya
LEFT JOIN directory_researches dr on directions_issledovaniya.research_id = dr.id
LEFT JOIN directions_napravleniya dn on directions_issledovaniya.napravleniye_id = dn.id
WHERE dn.client_id = %(card_pk)s and dr.is_case = true and directions_issledovaniya.time_confirmation is Null
WHERE dn.client_id = %(card_pk)s and dr.is_case = true and directions_issledovaniya.time_confirmation is Null and
dn.data_sozdaniya AT TIME ZONE %(tz)s BETWEEN %(d_start)s AND %(d_end)s
ORDER BY directions_issledovaniya.napravleniye_id
""",
params={'card_pk': card_pk, 'tz': TIME_ZONE},
params={'card_pk': card_pk, 'tz': TIME_ZONE, 'd_start': start_date, 'd_end': end_date},
)
rows = namedtuplefetchall(cursor)
return rows
24 changes: 17 additions & 7 deletions api/directions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def directions_generate(request):
hospital_department_override=p.get("hospital_department_override", -1),
hospital_override=p.get("hospital_override", -1),
price_category=p.get("priceCategory", -1),
case_id = p.get("caseId", -2),
)
for _ in range(p.get("directions_count", 1)):
rc = Napravleniya.gen_napravleniya_by_issledovaniya(*args, **kwargs)
Expand Down Expand Up @@ -4438,14 +4439,23 @@ def meta_info(request):
def patient_open_case(request):
request_data = json.loads(request.body)
card_pk = request_data.get("card_pk", None)
data_case = {}
data_case = []
date_start = datetime.now() - timedelta(days=60)
date_end = datetime.now()

if card_pk:
open_case = get_patient_open_case_data(card_pk)
open_case = get_patient_open_case_data(card_pk, date_start, date_end)
data_case = []
for o_case in open_case:
data_case[o_case.iss_id] = ""
child_direction = tree_direction(o_case.iss_id)
for child in child_direction:
print(child)
n = Napravleniya.objects.filter(parent_case_id=o_case.iss_id).first()
iss = Issledovaniya.objects.filter(napravleniye=n).first()
if iss:
title = iss.research.short_title if iss.research.short_title else iss.research.title
else:
title = "Случай пустой"
data_case.append({"id": o_case.iss_id, "label": f"{title} от {o_case.date_create}"})


data = {"data": ""}
data = {"data": data_case}
print(data)
return JsonResponse(data)
41 changes: 41 additions & 0 deletions directions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ def gen_napravleniye(
parent_id=None,
parent_auto_gen_id=None,
parent_slave_hosp_id=None,
parent_case_id=None,
rmis_slot=None,
direction_purpose="NONE",
external_organization="NONE",
Expand Down Expand Up @@ -1091,6 +1092,7 @@ def gen_napravleniye(
parent_id=parent_id,
parent_auto_gen_id=parent_auto_gen_id,
parent_slave_hosp_id=parent_slave_hosp_id,
parent_case_id=parent_case_id,
rmis_slot_id=rmis_slot,
hospital=doc.hospital or Hospitals.get_default_hospital(),
external_order=external_order,
Expand Down Expand Up @@ -1282,12 +1284,14 @@ def gen_napravleniya_by_issledovaniya(
external_order: Optional[RegisteredOrders] = None,
services_by_additional_order_num=None,
price_name=None,
case_id=-2,
):
result = {"r": False, "list_id": [], "list_stationar_id": [], "messageLimit": ""}
if not Clients.Card.objects.filter(pk=client_id).exists():
result["message"] = "Карта в базе не зарегистрирована, попробуйте выполнить поиск заново"
return result
pk_reseerches = []
issledovaniye_case_id = None
for v in researches.values():
pk_reseerches.extend(v)
card = Clients.Card.objects.get(pk=client_id)
Expand Down Expand Up @@ -1515,6 +1519,41 @@ def gen_napravleniya_by_issledovaniya(
result["message"] = "Данный мониторинг уже создан"
return result

if case_id > -2:
if case_id == -1:
napravleniye_case = Napravleniya.gen_napravleniye(
client_id,
doc_current if not for_rmis else None,
finsource,
diagnos,
history_num,
doc_current,
ofname_id,
ofname,
for_rmis=for_rmis,
rmis_data=rmis_data,
parent_id=parent_iss,
parent_auto_gen_id=parent_auto_gen,
parent_slave_hosp_id=parent_slave_hosp,
rmis_slot=rmis_slot,
direction_purpose=direction_purpose,
external_organization=external_organization,
price_category=price_category,
hospital=hospital_override,
external_order=external_order,
price_name_id=price_name,
)
research_case = directory.Researches.objects.filter(is_case=True).first()
issledovaniye_case = Issledovaniya(
napravleniye=napravleniye_case,
research=research_case,
deferred=False
)
issledovaniye_case.save()
issledovaniye_case_id = issledovaniye_case.pk
elif case_id > 0:
issledovaniye_case_id = case_id

if (dir_group > -1 and dir_group not in directions_for_researches.keys()) or (dir_group == dir_group_onlylab and dir_group not in directions_for_researches.keys()):
directions_for_researches[dir_group] = Napravleniya.gen_napravleniye(
client_id,
Expand All @@ -1530,6 +1569,7 @@ def gen_napravleniya_by_issledovaniya(
parent_id=parent_iss,
parent_auto_gen_id=parent_auto_gen,
parent_slave_hosp_id=parent_slave_hosp,
parent_case_id=issledovaniye_case_id,
rmis_slot=rmis_slot,
direction_purpose=direction_purpose,
external_organization=external_organization,
Expand Down Expand Up @@ -1560,6 +1600,7 @@ def gen_napravleniya_by_issledovaniya(
parent_id=parent_iss,
parent_auto_gen_id=parent_auto_gen,
parent_slave_hosp_id=parent_slave_hosp,
parent_case_id=issledovaniye_case_id,
rmis_slot=rmis_slot,
direction_purpose=direction_purpose,
external_organization=external_organization,
Expand Down
12 changes: 4 additions & 8 deletions l2-frontend/src/ui-cards/SelectedResearches.vue
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ export default {
card_pk: {
async handler() {
this.clear_fin();
const patientOpenCase = await this.$api('directions/patient-open-case', { card_pk: this.card_pk });
this.load_patient_open_case();
this.selectedCardLocal = null;
if (this.card_pk === null || this.card_pk === -1 || this.selected_card) {
Expand Down Expand Up @@ -1165,7 +1165,6 @@ export default {
}
this.load_direction_params();
this.load_stationar_deparments();
this.load_patient_open_case();
this.$root.$on('table-field:errors:set', (fieldPk, hasInvalid) => {
this.tableFieldsErrors = {
...this.tableFieldsErrors,
Expand Down Expand Up @@ -1435,13 +1434,10 @@ export default {
this.hospital_overrides = [{ id: -1, label: 'По умолчанию' }, ...hospitals];
},
async load_patient_open_case() {
const patienCases = [
{ id: -11, label: ' Терапевт-212121' },
{ id: -12, label: ' Травматолог -23232' },
{ id: -13, label: ' Нвролог-4343434' },
];
const patientOpenCase = await this.$api('directions/patient-open-case', { card_pk: this.card_pk });
this.patient_case = [{ id: -2, label: ' Не выбрано ' }, { id: -1, label: ' Создать новый случай' }, ...patienCases];
this.patient_case = [
{ id: -2, label: ' Не выбрано ' },
{ id: -1, label: ' Создать новый случай' }, ...patientOpenCase.data];
},
},
};
Expand Down

0 comments on commit 581414c

Please sign in to comment.