Skip to content

Commit

Permalink
send gistology to egisz
Browse files Browse the repository at this point in the history
  • Loading branch information
urchinpro committed Sep 26, 2024
1 parent dba843a commit 599afec
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
1 change: 1 addition & 0 deletions api/stationar/stationar_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ def desc_to_data(num_dirs: List[int], force_all_fields: bool = False):
new_date_data['date'] = date
new_date_data['link_dicom'] = link_dicom if link_dicom else ''
new_date_data['iss_id'] = i[6]
new_date_data['direction_id'] = i[2]
new_date_data['docConfirm'] = i[7]
new_date_data['data'] = [{'group_title': group, 'fields': [fields.copy()]}]
last_date = date
Expand Down
7 changes: 7 additions & 0 deletions appconf/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ def inc_dynamic_directory_version():
current_version = SettingManager.get_dynamic_directory_version()
SettingManager.set_value("dynamic_directory_version", str(current_version + 1), default_type='i')

@staticmethod
def rmis_upload_hours_interval():
return SettingManager.get("rmis_upload_hours_interval", default='1', default_type='i')

@staticmethod
def l2_modules() -> dict:
k = SettingManager.FULL_CACHE_L2_KEY
cv = cache.get(k)
if cv:
print("return")
return simplejson.loads(cv)
print("new set params")
result = {
**{
'l2_{}'.format(x): SettingManager.l2(x)
Expand Down Expand Up @@ -213,6 +219,7 @@ def l2_modules() -> dict:
"forms_url": SettingManager.forms_url(),
}
cache.set(k, simplejson.dumps(result), 60 * 60 * 8)
print(result)
return result

@staticmethod
Expand Down
37 changes: 37 additions & 0 deletions directions/management/commands/gistology_result_send_ecp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from dateutil.relativedelta import relativedelta

from directions.sql_func import get_directions_for_send_ecp_by_researches
from laboratory.settings import REMD_ONLY_RESEARCH
from laboratory.utils import current_time
from django.core.management.base import BaseCommand

from api.dicom import check_server_port
from appconf.manager import SettingManager
from directions.models import Napravleniya
from l2vi.integration import send_lab_direction_to_ecp, send_gistology_direction_to_ecp


class Command(BaseCommand):
help = "Отправить гистологические результаты в ЕЦП"

def handle(self, *args, **kwargs):
base = SettingManager.get_api_ecp_base_url()
if base != 'empty':
available = check_server_port(base.split(":")[1].replace("//", ""), int(base.split(":")[2]))
if not available:
self.stdout.write({"error": True, "message": "Cервер отправки в ЕЦП не доступен"})
date_start = current_time() + relativedelta(days=-100)
current_time_ecp_upload = SettingManager.rmis_upload_hours_interval()
date_end = current_time() + relativedelta(hours=-current_time_ecp_upload)

d_qs = get_directions_for_send_ecp_by_researches(tuple(REMD_ONLY_RESEARCH), date_start, date_end)
directions = [i.napravleniye_id for i in d_qs]
directions_iss = [{"directionId": i.napravleniye_id, "issId": i.iss_id} for i in d_qs]
res = send_gistology_direction_to_ecp(directions_iss)
self.stdout.write(f"{res}\n")
count = 0
for n in Napravleniya.objects.filter(pk__in=directions):
n.rmis_resend_services = True
n.save()
count += 1
self.stdout.write(f"{count}\n")
21 changes: 21 additions & 0 deletions directions/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,24 @@ def get_directions_by_who_create(doctor_pks, d_s, d_e):
)
rows = namedtuplefetchall(cursor)
return rows


def get_directions_for_send_ecp_by_researches(researches, d_s, d_e):
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT
directions_napravleniya.id as napravleniye_id,
di.id as iss_id
FROM directions_napravleniya
LEFT JOIN directions_issledovaniya di on directions_napravleniya.id = di.napravleniye_id
WHERE
directions_napravleniya.total_confirmed = true
AND directions_napravleniya.last_confirmed_at AT TIME ZONE %(tz)s BETWEEN %(d_start)s AND %(d_end)s
AND directions_napravleniya.rmis_resend_services = false
AND di.research_id in %(researches)s
""",
params={'researches': researches, 'd_start': d_s, 'd_end': d_e, 'tz': TIME_ZONE},
)
rows = namedtuplefetchall(cursor)
return rows
29 changes: 22 additions & 7 deletions integration_framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2669,13 +2669,14 @@ def results_by_direction(request):
request_data = json.loads(request.body)
token = request.headers.get("Authorization").split(" ")[1]
token_obj = Application.objects.filter(key=token).first()
if not hasattr(request.user, "hospitals"):
return Response({"ok": False, "message": "Некорректный auth токен"})
oid_org = request_data.get(("oid") or "")
check_result = check_correct_hosp(request, oid_org)
if not check_result["OK"]:
return Response({"ok": False, "message": check_result["message"]})
hospital = check_result["hospital"]
if not token_obj.unlimited_access:
if not hasattr(request.user, "hospitals"):
return Response({"ok": False, "message": "Некорректный auth токен"})
oid_org = request_data.get(("oid") or "")
check_result = check_correct_hosp(request, oid_org)
if not check_result["OK"]:
return Response({"ok": False, "message": check_result["message"]})
hospital = check_result["hospital"]
mode = request_data.get("mode")
is_lab = request_data.get("isLab", mode == "laboratory")
is_paraclinic = request_data.get("isParaclinic", mode == "paraclinic")
Expand Down Expand Up @@ -2728,15 +2729,29 @@ def results_by_direction(request):
if is_paraclinic or is_doc_refferal or is_user_forms:
results = desc_to_data(directions_data, force_all_fields=True)
for i in results:
additional_data_confirm_direction = None
direction_data = i["result"][0]["date"].split(" ")
if direction_data[1] not in objs_result:
objs_result[direction_data[1]] = {"pk": direction_data[1], "confirmedAt": direction_data[0], "services": {}}
if i["result"][0]["iss_id"] not in objs_result[direction_data[1]]["services"]:
iss = Issledovaniya.objects.filter(pk=i["result"][0]["iss_id"]).first()
doctor_additional_info = iss.doc_confirmation.additional_info
if doctor_additional_info:
if "{" in doctor_additional_info and "}" in doctor_additional_info:
try:
additional_data_confirm_direction = json.loads(doctor_additional_info)
if not additional_data_confirm_direction or not isinstance(additional_data_confirm_direction, dict):
additional_data_confirm_direction = {}
except Exception:
additional_data_confirm_direction = None

objs_result[direction_data[1]]["services"][i["result"][0]["iss_id"]] = {
"title": i["title_research"],
"fio": short_fio_dots(i["result"][0]["docConfirm"]),
"confirmedAt": direction_data[0],
"fractions": [],
"directionId": i["result"][0]["direction_id"],
"additionalDataConfirmDirection": additional_data_confirm_direction
}

values = values_as_structure_data(i["result"][0]["data"])
Expand Down
5 changes: 5 additions & 0 deletions l2vi/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def send_lab_direction_to_ecp(directions) -> dict:
return make_request(f"{url}/send-lab-result-ecp", data=json.dumps({"directions": directions}), gen_url=False, auth_token="a-super-secret-key")


def send_gistology_direction_to_ecp(directions) -> dict:
url = SettingManager.get_api_ecp_base_url()
return make_request(f"{url}/send-gistology-result", data=json.dumps({"directions": directions}), gen_url=False, auth_token="a-super-secret-key")


def send_medexam_to_ecp(directions) -> dict:
url = SettingManager.get_api_ecp_base_url()
return make_request(f"{url}/med-exam", data=json.dumps({"directions": directions}), gen_url=False, auth_token="a-super-secret-key")

0 comments on commit 599afec

Please sign in to comment.