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

Ref book #3146

Merged
merged 4 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
33 changes: 33 additions & 0 deletions directory/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,36 @@ def is_lab_filter_research(reserches_id):
)
rows = namedtuplefetchall(cursor)
return rows


def get_lab_research_reference_books():
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT
directory_fractions.id as fraction_id,
directory_fractions.title as fraction_title,
directory_fractions.fsli as fraction_fsli,
directory_fractions.ref_m as fraction_ref_m,
directory_fractions.ref_f as fraction_ref_f,

du.title as unit_title,
du.code as unit_code,
du.ucum as unit_ucum,

dr.id as research_id,
dr.title as research_title,
dr.internal_code as research_internal_code,
dr.code as research_nmu_code

FROM directory_fractions
LEFT JOIN directory_researches dr on dr.id = directory_fractions.research_id
LEFT JOIN directory_unit du on du.id = directory_fractions.unit_id
LEFT JOIN podrazdeleniya_podrazdeleniya pp on dr.podrazdeleniye_id = pp.id
WHERE pp.p_type = 2
order by dr.id
""",
params={},
)
rows = namedtuplefetchall(cursor)
return rows
1 change: 1 addition & 0 deletions integration_framework/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@
path('get-value-field', views.get_value_field),
path('get-price-data', views.get_price_data),
path('get-prices-by-date', views.get_prices_by_date),
path('get-reference-books', views.get_reference_books),
]
55 changes: 55 additions & 0 deletions integration_framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
from laboratory.settings import COVID_RESEARCHES_PK
from .utils import get_json_protocol_data, get_json_labortory_data, check_type_file, legal_auth_get, author_doctor
from django.contrib.auth.models import User
from directory.sql_func import get_lab_research_reference_books

logger = logging.getLogger("IF")

Expand Down Expand Up @@ -3088,3 +3089,57 @@ def get_prices_by_date(request):
} for i in prices]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black-format] reported by reviewdog 🐶

Suggested change
} for i in prices]
}
for i in prices
]


return Response({"data": result})


@api_view(['POST'])
def get_reference_books(request):
request_data = json.loads(request.body)
token = request.headers.get("Authorization").split(" ")[1]
token_obj = Application.objects.filter(key=token).first()
mode = request_data.get('mode')
is_lab = request_data.get('isLab', mode == 'laboratory')
if not token_obj.unlimited_access:
return Response({"ok": False, 'message': 'Некорректный auth токен'})
result = []
if is_lab:
lab_data = get_lab_research_reference_books()
service_result = {
"serviceId": "",
"serviceTitle": "",
"serviceInternalCode": "",
"serviceNMUCode": "",
"fractions": []
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black-format] reported by reviewdog 🐶

Suggested change
service_result = {
"serviceId": "",
"serviceTitle": "",
"serviceInternalCode": "",
"serviceNMUCode": "",
"fractions": []
}
service_result = {"serviceId": "", "serviceTitle": "", "serviceInternalCode": "", "serviceNMUCode": "", "fractions": []}


last_research_id = -1
step = 0
tmp_result = service_result.copy()
fractions = []
for i in lab_data:
if i.research_id != last_research_id:
if step != 0:
result.append(tmp_result.copy())
fractions = []
tmp_result = service_result.copy()
tmp_result["serviceId"] = i.research_id
tmp_result["serviceTitle"] = i.research_title
tmp_result["serviceInternalCode"] = i.research_internal_code
tmp_result["serviceNMUCode"] = i.research_nmu_code
tmp_result["fractions"] = fractions

fractions.append({
"id": i.fraction_id,
"title": i.fraction_title,
"fsli": i.fraction_fsli,
"ref_m": json.loads(i.fraction_ref_m),
"ref_f": json.loads(i.fraction_ref_f),
"unitTitle": i.unit_title,
"unitCode": i.unit_code,
"unitUcum": i.unit_ucum
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black-format] reported by reviewdog 🐶

Suggested change
fractions.append({
"id": i.fraction_id,
"title": i.fraction_title,
"fsli": i.fraction_fsli,
"ref_m": json.loads(i.fraction_ref_m),
"ref_f": json.loads(i.fraction_ref_f),
"unitTitle": i.unit_title,
"unitCode": i.unit_code,
"unitUcum": i.unit_ucum
})
fractions.append(
{
"id": i.fraction_id,
"title": i.fraction_title,
"fsli": i.fraction_fsli,
"ref_m": json.loads(i.fraction_ref_m),
"ref_f": json.loads(i.fraction_ref_f),
"unitTitle": i.unit_title,
"unitCode": i.unit_code,
"unitUcum": i.unit_ucum,
}
)


last_research_id = i.research_id
step += 1
tmp_result["fractions"] = fractions
result.append(tmp_result.copy())
return JsonResponse({"result": result})
Loading