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

Api by ext order #3084

Merged
merged 6 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 5 additions & 1 deletion api/directions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4141,7 +4141,11 @@ def file_log(request):
def get_userdata(doc: DoctorProfile):
if doc is None:
return ""
return "%s (%s) - %s" % (doc.fio, doc.user.username, doc.podrazdeleniye.title)
# return "%s (%s) - %s" % (doc.fio, doc.user.username, doc.podrazdeleniye.title)
podr = ""
if doc.podrazdeleniye:
podr = doc.podrazdeleniye.title
return f"{doc.fio}, {doc.user.username}, {podr}"


@login_required
Expand Down
1 change: 1 addition & 0 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Application(models.Model):
can_access_schedule = models.BooleanField(default=False, help_text="У приложения есть доступ к расписанию")
csv_header = models.CharField(max_length=255, blank=True, null=True, help_text="Заголовок CSV файла")
is_background_worker = models.BooleanField(default=False)
unlimited_access = models.BooleanField(default=False, help_text="Доступ без ограничений")

def auto_set_places(self, rel: "RelationFractionASTM", value: Union[str, float, int]) -> str:
if rel.full_round:
Expand Down
21 changes: 12 additions & 9 deletions ftp_orders/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ftp_orders.sql_func import get_tubesregistration_id_by_iss
from hospitals.models import Hospitals
from directory.models import Researches, Fractions
from laboratory.settings import BASE_DIR
from laboratory.settings import BASE_DIR, NEED_RECIEVE_TUBE_TO_PUSH_ORDER
from laboratory.utils import current_time
from slog.models import Log
from users.models import DoctorProfile
Expand Down Expand Up @@ -661,14 +661,17 @@ def process_push_orders():
if dir_external not in directions:
directions.append(dir_external)

for direction in directions:
is_recieve = False
for tube in TubesRegistration.objects.filter(issledovaniya__napravleniye=direction).distinct():
is_recieve = True
if tube.time_recive is None:
is_recieve = False
if is_recieve:
directions_to_sync.append(direction)
if NEED_RECIEVE_TUBE_TO_PUSH_ORDER:
for direction in directions:
is_recieve = False
for tube in TubesRegistration.objects.filter(issledovaniya__napravleniye=direction).distinct():
is_recieve = True
if tube.time_recive is None:
is_recieve = False
if is_recieve:
directions_to_sync.append(direction)
else:
directions_to_sync.extend(directions)

ftp_connection.log(f"Directions to sync: {[d.pk for d in directions_to_sync]}")

Expand Down
49 changes: 36 additions & 13 deletions integration_framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from api.dicom import check_dicom_study
from api.directions.sql_func import direction_by_card, get_lab_podr, get_confirm_direction_patient_year, get_type_confirm_direction, get_confirm_direction_patient_year_is_extract
from api.models import Application
from api.patients.views import patients_search_card
from api.stationar.stationar_func import desc_to_data
from api.views import mkb10_dict
Expand Down Expand Up @@ -2505,6 +2506,8 @@ def directions_by_category_result_year(request):
@api_view(['POST'])
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 '')
Expand All @@ -2518,31 +2521,51 @@ def results_by_direction(request):
is_doc_refferal = request_data.get('isDocReferral', mode == 'docReferral')
is_user_forms = request_data.get('isUserFroms', mode == 'forms')
direction = request_data.get('pk')
directions = request_data.get('directions', [])
if is_lab and not directions:
directions = [direction]
external_add_order = request_data.get('externalOrder')
directions_data = request_data.get('directions')
if is_lab and not directions_data:
if external_add_order:
ext_add_order_obj = directions.ExternalAdditionalOrder.objects.filter(external_add_order=external_add_order).first()
iss_data = directions.Issledovaniya.objects.filter(external_add_order=ext_add_order_obj).first()
direction = iss_data.napravleniye_id
directions_data = [direction]
else:
directions = [direction]
for d in directions:
direction_obj = Napravleniya.objects.filter(hospital=hospital, pk=d).first()
if not direction_obj:
return Response({"ok": False, 'message': 'Номер направления не принадлежит организации'})
directions_data = [direction]
if not token_obj.unlimited_access:
for d in directions_data:
direction_obj = Napravleniya.objects.filter(hospital=hospital, pk=d).first()
if not direction_obj:
return Response({"ok": False, 'message': 'Номер направления не принадлежит организации'})

objs_result = {}
if is_lab:
direction_result = get_laboratory_results_by_directions(directions)

direction_result = get_laboratory_results_by_directions(tuple(directions_data))
for r in direction_result:
if r.direction not in objs_result:
objs_result[r.direction] = {'pk': r.direction, 'confirmedAt': r.date_confirm, 'services': {}}

if r.iss_id not in objs_result[r.direction]['services']:
objs_result[r.direction]['services'][r.iss_id] = {'title': r.research_title, 'fio': short_fio_dots(r.fio), 'confirmedAt': r.date_confirm, 'fractions': []}
objs_result[r.direction]['services'][r.iss_id] = {
'title': r.research_title,
'internalCode': r.research_internal_code,
'fio': short_fio_dots(r.fio) if r.fio else r.doc_confirmation_string,
'confirmedAt': r.date_confirm,
'fractions': [],
}

objs_result[r.direction]['services'][r.iss_id]['fractions'].append({'title': r.fraction_title, 'value': r.value, 'units': r.units})
objs_result[r.direction]['services'][r.iss_id]['fractions'].append(
{
'title': r.fraction_title,
'value': r.value,
'units': r.units,
'fsli': r.fraction_fsli,
'ref_m': r.ref_m,
'ref_f': r.ref_f,
}
)

if is_paraclinic or is_doc_refferal or is_user_forms:
results = desc_to_data(directions, force_all_fields=True)
results = desc_to_data(directions_data, force_all_fields=True)
for i in results:
direction_data = i['result'][0]["date"].split(' ')
if direction_data[1] not in objs_result:
Expand Down
1 change: 1 addition & 0 deletions laboratory/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ def __getitem__(self, item):
DAYS_AGO_SEARCH_RESULT = {} # {"isLab: 90", "isInstrument: 365"}
NEED_ORDER_DIRECTION_FOR_DEFAULT_HOSPITAL = False
USE_TFOMS_DISTRICT = False
NEED_RECIEVE_TUBE_TO_PUSH_ORDER = False

try:
from laboratory.local_settings import * # noqa: F403,F401
Expand Down
7 changes: 6 additions & 1 deletion results/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ def get_laboratory_results_by_directions(list_dirs):
directions_issledovaniya.napravleniye_id as direction,
directions_issledovaniya.research_id,
directions_issledovaniya.doc_confirmation_id as doctor_id,
directions_issledovaniya.doc_confirmation_string as doc_confirmation_string,
directory_researches.title as research_title,
directory_researches.internal_code as research_internal_code,
directions_result.value as value,
directions_result.fraction_id,
directions_result.id as result_is,
directory_fractions.title as fraction_title,
directory_fractions.fsli as fraction_fsli,
directions_result.units as units,
directions_result.ref_m as ref_m,
directions_result.ref_f as ref_f,
users_doctorprofile.fio as fio,
to_char(directions_issledovaniya.time_confirmation AT TIME ZONE %(tz)s, 'DD.MM.YYYY') as date_confirm
from directions_issledovaniya
Expand All @@ -70,7 +75,7 @@ def get_laboratory_results_by_directions(list_dirs):
directions_result.fraction_id=directory_fractions.id
LEFT JOIN users_doctorprofile ON
users_doctorprofile.id=directions_issledovaniya.doc_confirmation_id
WHERE directions_issledovaniya.napravleniye_id = ANY(ARRAY[%(num_dirs)s])
WHERE directions_issledovaniya.napravleniye_id in %(num_dirs)s
ORDER BY directions_issledovaniya.napravleniye_id

""",
Expand Down