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

Auto create case #3238

Merged
merged 35 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0cc5ae3
проверка созданного случая
urchinpro Nov 17, 2023
978073c
автосоздание направлений и случая
urchinpro Nov 17, 2023
1bdadea
.
urchinpro Nov 19, 2023
1397dba
.
urchinpro Nov 19, 2023
03539c5
print set document for many people
urchinpro Nov 20, 2023
5888006
Merge branch 'develop' into autoCreateCase
urchinpro Nov 20, 2023
84ca305
print set document for many people
urchinpro Nov 20, 2023
2445ab8
Update utils/xh.py
urchinpro Nov 20, 2023
31f5da7
Update utils/xh.py
urchinpro Nov 20, 2023
dc19770
Update directions/models.py
urchinpro Nov 20, 2023
d5dfd19
Update directions/models.py
urchinpro Nov 20, 2023
7d5e25e
Update api/views.py
urchinpro Nov 20, 2023
2261f93
Update api/sql_func.py
urchinpro Nov 20, 2023
3adb63a
print set document for many people
urchinpro Nov 20, 2023
c6ca074
Merge remote-tracking branch 'origin/autoCreateCase' into autoCreateCase
urchinpro Nov 20, 2023
a376901
fix
urchinpro Nov 20, 2023
fade0f2
Update directions/models.py
urchinpro Nov 20, 2023
ba3be4a
Update api/views.py
urchinpro Nov 20, 2023
ced95a8
Update api/views.py
urchinpro Nov 20, 2023
19af03b
Update api/views.py
urchinpro Nov 20, 2023
1eba55f
планируемая дата начала оказания услуг
urchinpro Nov 20, 2023
a3acaaf
Merge remote-tracking branch 'origin/autoCreateCase' into autoCreateCase
urchinpro Nov 20, 2023
3817047
планируемая дата -fix
urchinpro Nov 20, 2023
d062dd3
fix: price_name =None
urchinpro Nov 20, 2023
3061b84
hash to file name - store in cashe
urchinpro Nov 21, 2023
c9c7cc8
hash to file name - store in cashe
urchinpro Nov 21, 2023
9058714
fix import pep
urchinpro Nov 21, 2023
eb0d8bc
Update utils/xh.py
urchinpro Nov 21, 2023
f1c5cba
Update directions/views.py
urchinpro Nov 21, 2023
14adc33
Update directions/views.py
urchinpro Nov 21, 2023
02902ad
Update directions/views.py
urchinpro Nov 21, 2023
ad10dd5
fix
urchinpro Nov 21, 2023
199632d
настройки хэш
urchinpro Nov 21, 2023
97c5b4a
pep
urchinpro Nov 21, 2023
3fca858
add slot_fact_id
urchinpro Nov 21, 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
1 change: 1 addition & 0 deletions api/directions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def directions_generate(request):
price_category=p.get("priceCategory", -1),
case_id=p.get("caseId", -2),
case_by_direction=p.get("caseByDirection", False),
plan_start_date=p.get("planStartDate", None),
slot_fact_id=p.get("slotFactId", None),
)
if type_generate == "calculate-cost":
Expand Down
22 changes: 22 additions & 0 deletions api/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,25 @@ def search_text_stationar(date_create_start, date_create_end, final_text):

rows = namedtuplefetchall(cursor)
return rows


def search_case_by_card_date(card_id, plan_date_start_case, research_case_id, limit):
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT
directions_napravleniya.id as case_direction_number,
directions_issledovaniya.id as case_issledovaniye_number
FROM directions_issledovaniya
LEFT JOIN directions_napravleniya ON directions_napravleniya.id = directions_issledovaniya.napravleniye_id
WHERE
directions_issledovaniya.research_id = %(research_case_id)s
and directions_issledovaniya.plan_start_date AT TIME ZONE %(tz)s = %(plan_date_start_case)s
and directions_napravleniya.client_id = %(card_id)s
LIMIT %(limit)s
""",
params={'card_id': card_id, 'plan_date_start_case': plan_date_start_case, 'research_case_id': research_case_id, 'tz': TIME_ZONE, 'limit': limit},
)

rows = namedtuplefetchall(cursor)
return rows
38 changes: 36 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pytz_deprecation_shim as pytz

from api.models import ManageDoctorProfileAnalyzer, Analyzer
from directions.views import create_case_by_cards
from directory.models import Researches, SetResearch, SetOrderResearch, PatientControlParam
from doctor_schedule.models import ScheduleResource
from ecp_integration.integration import get_reserves_ecp, get_slot_ecp
Expand All @@ -24,6 +25,7 @@
TITLE_REPORT_FILTER_HAS_ALL_FIN_SOURCE,
STATISTIC_TYPE_DEPARTMENT,
USE_TFOMS_DISTRICT,
TYPE_COMPANY_SET_DIRECTION_PDF,
)
from utils.response import status_response

Expand Down Expand Up @@ -76,12 +78,13 @@
from utils.common import non_selected_visible_type
from utils.dates import try_parse_range, try_strptime
from utils.nsi_directories import NSI
from utils.xh import get_all_hospitals
from utils.xh import get_all_hospitals, simple_join_two_pdf_files, simple_save_pdf_file, correspondence_set_file_hash
from .dicom import search_dicom_study
from .directions.sql_func import get_lab_podr
from .sql_func import users_by_group, users_all, get_diagnoses, get_resource_researches, search_data_by_param, search_text_stationar
from laboratory.settings import URL_RMIS_AUTH, URL_ELN_MADE, URL_SCHEDULE
import urllib.parse
from django.utils.module_loading import import_string

logger = logging.getLogger("API")

Expand Down Expand Up @@ -3305,7 +3308,38 @@ def get_examination_list(request):
@login_required
@group_required("Конструктор: Настройка организации")
def print_medical_examination_data(request):
return status_response(True)
request_data = json.loads(request.body)
cards = request_data.get("cards")
card_directions = create_case_by_cards(cards)
files_data = []
if TYPE_COMPANY_SET_DIRECTION_PDF:
additional_page = import_string('forms.forms112.' + TYPE_COMPANY_SET_DIRECTION_PDF.split(".")[0])
for card, directions_data in card_directions.items():
if len(directions_data) > 1:
directions_data = [str(i) for i in directions_data]
napr_id = ", ".join(directions_data)
else:
napr_id = directions_data[0]
napr_id = f"[{napr_id}]"
fc = additional_page(
request_data={
**dict(request.GET.items()),
"user": request.user,
"card_pk": card,
"hospital": request.user.doctorprofile.get_hospital() if hasattr(request.user, "doctorprofile") else Hospitals.get_default_hospital(),
"type_additional_pdf": TYPE_COMPANY_SET_DIRECTION_PDF.split(".")[1],
"fin_title": "профосмотр",
"napr_id": napr_id,
}
)
saved_file_pdf = simple_save_pdf_file(fc)
files_data.append(saved_file_pdf)

buffer = simple_join_two_pdf_files(files_data)

id_file = simple_save_pdf_file(buffer)
hash_file = correspondence_set_file_hash(id_file)
return JsonResponse({"id": hash_file})


@login_required
Expand Down
13 changes: 2 additions & 11 deletions directions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,6 @@ def gen_napravleniye(
hospital=-1,
external_order=None,
price_name_id=None,
slot_fact_id=None,
) -> 'Napravleniya':
"""
Генерация направления
Expand Down Expand Up @@ -1131,12 +1130,6 @@ def gen_napravleniye(
if save:
dir.save()
dir.set_polis()
if slot_fact_id:
from doctor_schedule.models import SlotFact

f = SlotFact.objects.get(pk=slot_fact_id)
Copy link
Owner

Choose a reason for hiding this comment

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

И тут странное

f.direction = dir
f.save(update_fields=['direction'])
return dir

@staticmethod
Expand Down Expand Up @@ -1298,6 +1291,7 @@ def gen_napravleniya_by_issledovaniya(
price_name=None,
case_id=-2,
case_by_direction=False,
plan_start_date=None,
slot_fact_id=None,
):
result = {"r": False, "list_id": [], "list_stationar_id": [], "messageLimit": ""}
Expand Down Expand Up @@ -1563,7 +1557,6 @@ def gen_napravleniya_by_issledovaniya(
hospital=hospital_override,
external_order=external_order,
price_name_id=price_name,
slot_fact_id=slot_fact_id,
Copy link
Owner

Choose a reason for hiding this comment

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

Тут что то странное происходит

)
research_case = directory.Researches.objects.filter(is_case=True, hide=False).first()
issledovaniye_case = Issledovaniya(napravleniye=napravleniye_case, research=research_case, deferred=False)
Expand Down Expand Up @@ -1595,7 +1588,6 @@ def gen_napravleniya_by_issledovaniya(
hospital=hospital_override,
external_order=external_order,
price_name_id=price_name,
slot_fact_id=slot_fact_id,
)
npk = directions_for_researches[dir_group].pk
result["list_id"].append(npk)
Expand Down Expand Up @@ -1627,7 +1619,6 @@ def gen_napravleniya_by_issledovaniya(
hospital=hospital_override,
external_order=external_order,
price_name_id=price_name,
slot_fact_id=slot_fact_id,
)
npk = directions_for_researches[dir_group].pk
result["list_id"].append(npk)
Expand Down Expand Up @@ -1848,7 +1839,6 @@ def gen_napravleniya_by_issledovaniya(
external_organization=external_organization,
price_category=price_category,
hospital=hospital_override,
slot_fact_id=slot_fact_id,
)
result["list_id"].append(new_direction.pk)
Issledovaniya(napravleniye=new_direction, research_id=research_dir, deferred=False).save()
Expand Down Expand Up @@ -2283,6 +2273,7 @@ class Issledovaniya(models.Model):
DoctorProfile, null=True, blank=True, related_name="doc_add_additional", db_index=True, help_text='Профиль-добавил исполнитель дополнительные услуги', on_delete=models.SET_NULL
)
external_add_order = models.ForeignKey(ExternalAdditionalOrder, db_index=True, blank=True, null=True, default=None, help_text="Внешний заказ", on_delete=models.SET_NULL)
plan_start_date = models.DateTimeField(null=True, blank=True, db_index=True, help_text='Планируемое время начала услуги')

urchinpro marked this conversation as resolved.
Show resolved Hide resolved
@property
def time_save_local(self):
Expand Down
15 changes: 15 additions & 0 deletions directions/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,18 @@ def check_create_direction_patient_by_research(client_id, researches, months_ago
)
rows = namedtuplefetchall(cursor)
return rows


def get_researches_by_number_directions(direction_numbers):
with connection.cursor() as cursor:
cursor.execute(
"""
SELECT
directions_issledovaniya.research_id
FROM directions_issledovaniya
WHERE directions_issledovaniya.napravleniye_id in %(direction_numbers)s
""",
params={'direction_numbers': direction_numbers},
)
rows = namedtuplefetchall(cursor)
return rows
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
return rows
return rows

96 changes: 94 additions & 2 deletions directions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@
from transliterate import translit

import directory.models as directory
from directions.sql_func import get_researches_by_number_directions
from users.models import DoctorProfile
from api.sql_func import search_case_by_card_date
from hospitals.models import Hospitals
import slog.models as slog
from appconf.manager import SettingManager
from directions.models import Napravleniya, Issledovaniya, TubesRegistration, DirectionParamsResult
from directions.models import Napravleniya, Issledovaniya, TubesRegistration, DirectionParamsResult, IstochnikiFinansirovaniya
from laboratory.decorators import logged_in_or_token
from laboratory.settings import FONTS_FOLDER, PRINT_ADDITIONAL_PAGE_DIRECTION_FIN_SOURCE, PRINT_APPENDIX_PAGE_DIRECTION
from laboratory.utils import strtime, strdate
from podrazdeleniya.models import Podrazdeleniya
from utils import xh
from utils.dates import try_parse_range
from utils.dates import try_parse_range, normalize_dots_date
from django.utils.module_loading import import_string

from utils.matrix import transpose
Expand Down Expand Up @@ -1040,3 +1043,92 @@ def px(x=0.0):
def pxr(x=0.0):
x *= mm
return w - x



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

def create_case_by_cards(cards):
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [flake8] <302> reported by reviewdog 🐶
expected 2 blank lines, found 1

urchinpro marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

🚫 [flake8] <303> reported by reviewdog 🐶
too many blank lines (3)

research_case = directory.Researches.objects.filter(is_case=True, hide=False).first()
doc = DoctorProfile.objects.filter(fio='Системный Пользователь', is_system_user=True).first()
card_directions = {}
number_directons = None
for card in cards:
card_id = card.get("card_id")
researches = card.get("research")
plan_start_date_case = normalize_dots_date(card.get("date"))
plan_start_date_case = f"{plan_start_date_case} 00:00:00"
result_search_case = search_case_by_card_date(card_id, plan_start_date_case, research_case.pk, 1)
case_issledovaniye_number, case_direction_number = None, None
for i in result_search_case:
case_issledovaniye_number = i.case_issledovaniye_number
case_direction_number = i.case_direction_number
break
financing_source = IstochnikiFinansirovaniya.objects.filter(title__in=["Профосмотр", "Юрлицо"]).first()

if case_issledovaniye_number:
number_directons = Napravleniya.objects.values_list("id", flat=True).filter(parent_case_id=case_issledovaniye_number)
researches_sql = get_researches_by_number_directions(tuple(number_directons))
current_researches_case = set([i.research_id for i in researches_sql])
api_researches = set(researches)
api_researches -= current_researches_case
researches = list(api_researches)
result = Napravleniya.gen_napravleniya_by_issledovaniya(
card_id,
"",
financing_source.pk,
"",
None,
doc,
{-1: researches},
{},
False,
{},
vich_code="",
count=1,
discount=0,
rmis_slot=None,
price_name=None,
case_id=case_direction_number,
case_by_direction=True,
plan_start_date=plan_start_date_case,
)
else:
napravleniye_case = Napravleniya.gen_napravleniye(
card_id,
doc,
financing_source,
"",
"",
doc,
-1,
doc,
)

issledovaniye_case = Issledovaniya(napravleniye=napravleniye_case, research=research_case, deferred=False, plan_start_date=plan_start_date_case)
issledovaniye_case.save()
result = Napravleniya.gen_napravleniya_by_issledovaniya(
card_id,
"",
financing_source.pk,
"",
None,
doc,
{-1: researches},
{},
False,
{},
vich_code="",
count=1,
discount=0,
rmis_slot=None,
price_name=None,
case_id=napravleniye_case.pk,
case_by_direction=True,
plan_start_date=plan_start_date_case,
)
if number_directons:
number_directons = [i for i in number_directons]
else:
number_directons = []
number_directons.extend(result.get("list_id"))
card_directions[card_id] = list(set(number_directons))
return card_directions
21 changes: 19 additions & 2 deletions forms/forms112.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
from directions.models import Napravleniya, Issledovaniya
from hospitals.models import Hospitals
from laboratory.settings import FONTS_FOLDER, BASE_DIR
from utils.xh import save_tmp_file
from utils.xh import save_tmp_file, correspondence_get_file_hash
from directions.views import gen_pdf_dir as f_print_direction
from django.http import HttpRequest
from django.utils.module_loading import import_string
from pdfrw import PdfReader, PdfWriter


def form_01(request_data):
Expand Down Expand Up @@ -342,7 +343,6 @@ def form_02(request_data):


def join_two_pdf_data(func_name, http_params, user_data, buffer, ind_card, type="post"):

if type == "get":
fc = func_name(request_data=http_params)
is_get = False
Expand Down Expand Up @@ -512,3 +512,20 @@ def add_appendix_direction_list(appendix_direction_list, dir_temp):
elif section.get('isHospital'):
direction_data.extend(list(types_direction["isHospital"]))
return direction_data


def form_03(request_data):
id_file = request_data.get("id").replace('"', "")
file_data = correspondence_get_file_hash(id_file)
if file_data:
dir_param = SettingManager.get("dir_param", default='/tmp', default_type='s')
file_dir = os.path.join(dir_param, file_data)
pdf_all = BytesIO()
inputs = [file_dir]
writer = PdfWriter()
for inpfn in inputs:
writer.addpages(PdfReader(inpfn).pages)
writer.write(pdf_all)
pdf_out = pdf_all.getvalue()
os.remove(file_dir)
return pdf_out
7 changes: 6 additions & 1 deletion l2-frontend/src/construct/ConstructCompany.vue
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,15 @@ export default {
const selectCard = this.selectedCards;
return selectCard.includes(card);
}).map((exam) => ({ card_id: exam.card_id, date: exam.date, research: exam.research_id }));
await this.$api('print-medical-examination-data', {
await this.$store.dispatch(actions.INC_LOADING);
const result = await this.$api('print-medical-examination-data', {
cards: printData,
exclude: this.excludedResearches,
});
await this.$store.dispatch(actions.DEC_LOADING);
if (result.id) {
window.open(`/forms/pdf?type=112.03&id=${encodeURIComponent(JSON.stringify(result.id))}`, '_blank');
}
},
},
};
Expand Down
1 change: 1 addition & 0 deletions laboratory/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ def __getitem__(self, item):
QR_CODE_ANKETA = ""
RESULT_LABORATORY_FORM = ""
SELF_WATERMARKS = ""
TYPE_COMPANY_SET_DIRECTION_PDF = ""

try:
from laboratory.local_settings import * # noqa: F403,F401
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ pdf2docx = "^0.5.6"
pyotp = "^2.8.0"
qrcode = "^7.4.2"
hl7apy = "^1.3.4"

[tool.poetry.extras]
caching = ["psycopg2"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Loading
Loading