Skip to content

Commit

Permalink
Merge pull request #3023 from moodpulse/hl7_sendProxyOrder
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailprivalov authored Aug 26, 2023
2 parents eac0e3b + 1fc01ce commit 0428181
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,5 @@ external_system/settings/phones_org.json
/forms/contract_forms/
/forms/additional_pages/
!/forms/additional_pages/default.json
/ftp_orders/hl7_rule
!/ftp_orders/hl7_rule/default.json
3 changes: 2 additions & 1 deletion api/directions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3343,7 +3343,8 @@ def tubes_for_get(request):
except:
return status_response(False, "Направление не найдено")

if direction.get_hospital() != request.user.doctorprofile.get_hospital():
user_groups = [str(x) for x in request.user.groups.all()]
if direction.get_hospital() != request.user.doctorprofile.get_hospital() and "Направления-все МО" not in user_groups:
return status_response(False, "Направление для другой организации")

data = {}
Expand Down
23 changes: 15 additions & 8 deletions api/laboratory/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -709,15 +709,19 @@ def receive_one_by_one(request):
resp_json = json.loads(resp.content)
if isinstance(resp_json, dict) and "message" in resp_json:
message = resp_json["message"]
user_groups = [str(x) for x in request.user.groups.all()]
if "Направления-все МО" not in user_groups:
pks = [
x.number
for x in (
TubesRegistration.objects.filter(issledovaniya__napravleniye__pk=pk)
.filter(Q(issledovaniya__napravleniye__hospital=request.user.doctorprofile.hospital) | Q(issledovaniya__napravleniye__hospital__isnull=True))
.distinct()
)
]
else:
pks = [x.number for x in (TubesRegistration.objects.filter(issledovaniya__napravleniye__pk=pk).distinct())]

pks = [
x.number
for x in (
TubesRegistration.objects.filter(issledovaniya__napravleniye__pk=pk)
.filter(Q(issledovaniya__napravleniye__hospital=request.user.doctorprofile.hospital) | Q(issledovaniya__napravleniye__hospital__isnull=True))
.distinct()
)
]
ok_objects = []
ok_researches = []
invalid_objects = []
Expand Down Expand Up @@ -840,6 +844,9 @@ def receive_history(request):
first_iss: Issledovaniya = row.issledovaniya_set.first()
if first_iss and first_iss.napravleniye and first_iss.napravleniye.external_executor_hospital:
podrs = [first_iss.napravleniye.external_executor_hospital.safe_short_title]
lab_titles = sorted(list(set([f"{x.research.get_podrazdeleniye_title_recieve_recieve()}" for x in row.issledovaniya_set.all()])))
lab_titles = ",".join(lab_titles)
podrs = [f"{podrs[0]}, {lab_titles}"]
is_external_executor = True
else:
podrs = sorted(list(set([f"{x.research.get_podrazdeleniye_title_recieve_recieve()}" for x in row.issledovaniya_set.all()])))
Expand Down
20 changes: 20 additions & 0 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2130,10 +2130,13 @@ def organization_data(request):
if SettingManager.l2('ftp') and request.user.doctorprofile.has_group('Конструктор: Настройка всех организаций'):
org['ordersPullFtpServerUrl'] = hospital.orders_pull_by_numbers or ''
org['ordersPushFtpServerUrl'] = hospital.orders_push_by_numbers or ''
org['resultPullFtpServerUrl'] = hospital.result_pull_by_numbers or ''
org['isExternalPerformingOrganization'] = hospital.is_external_performing_organization
org['strictTubeNumbers'] = hospital.strict_tube_numbers
org['strictDataOwnership'] = hospital.strict_data_ownership
org['strictExternalNumbers'] = hospital.strict_external_numbers
org['hl7SenderApplication'] = hospital.hl7_sender_application
org['hl7ReceiverAapplication'] = hospital.hl7_receiver_appplication

return JsonResponse({"org": org})

Expand All @@ -2159,6 +2162,9 @@ def organization_data_update(request):
'strictTubeNumbers': bool,
'strictDataOwnership': bool,
'strictExternalNumbers': bool,
'resultPullFtpServerUrl': str,
'hl7SenderApplication': str,
'hl7ReceiverAapplication': str,
}

data = data_parse(
Expand All @@ -2174,6 +2180,9 @@ def organization_data_update(request):
'strictTubeNumbers': False,
'strictDataOwnership': False,
'strictExternalNumbers': False,
'resultPullFtpServerUrl': None,
'hl7SenderApplication': None,
'hl7ReceiverAapplication': None,
},
)

Expand All @@ -2194,6 +2203,9 @@ def organization_data_update(request):
strict_tube_numbers: bool = data[14]
strict_data_ownership: bool = data[15]
strict_external_numbers: bool = data[16]
result_pull_by_numbers: Optional[str] = data[17] or None
hl7_sender_application: Optional[str] = data[18] or None
hl7_receiver_appplication: Optional[str] = data[19] or None

if not title:
return status_response(False, 'Название не может быть пустым')
Expand Down Expand Up @@ -2225,6 +2237,7 @@ def organization_data_update(request):
"strict_tube_numbers": hospital.strict_tube_numbers,
"strict_data_ownership": hospital.strict_data_ownership,
"strict_external_numbers": hospital.strict_external_numbers,
"result_pull_by_numbers": hospital.result_pull_by_numbers,
}
if has_full_ftp_access
else {}
Expand All @@ -2250,6 +2263,9 @@ def organization_data_update(request):
"strict_tube_numbers": strict_tube_numbers,
"strict_data_ownership": strict_data_ownership,
"strict_external_numbers": strict_external_numbers,
"result_pull_by_numbers": result_pull_by_numbers,
"hl7_sender_application": hl7_sender_application,
"hl7_receiver_appplication": hl7_receiver_appplication,
}
if has_full_ftp_access
else {}
Expand All @@ -2266,13 +2282,17 @@ def organization_data_update(request):
hospital.www = www
hospital.email = email
hospital.okpo = okpo
hospital.hl7_receiver_appplication = hl7_receiver_appplication
hospital.hl7_sender_application = hl7_sender_application

if has_full_ftp_access:
hospital.orders_pull_by_numbers = orders_pull_by_numbers
hospital.orders_push_by_numbers = orders_push_by_numbers
hospital.is_external_performing_organization = is_external_performing_organization
hospital.strict_tube_numbers = strict_tube_numbers
hospital.strict_data_ownership = strict_data_ownership
hospital.strict_external_numbers = strict_external_numbers
hospital.result_pull_by_numbers = result_pull_by_numbers
hospital.save()

Log.log(
Expand Down
13 changes: 11 additions & 2 deletions clients/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Individual(models.Model):
ecp_id = models.CharField(max_length=64, default=None, null=True, blank=True, db_index=True, help_text="ID в ЕЦП")
time_add = models.DateTimeField(default=timezone.now, null=True, blank=True)
owner = models.ForeignKey('hospitals.Hospitals', default=None, blank=True, null=True, help_text="Организация-владелец данных", db_index=True, on_delete=models.PROTECT)
owner_patient_id = models.CharField(max_length=128, default=None, null=True, blank=True, db_index=True, help_text="Код в организации-владелеце")

def first(self):
return self
Expand Down Expand Up @@ -753,12 +754,13 @@ def import_from_tfoms(data: Union[dict, List], individual: Union['Individual', N
return updated_data

@staticmethod
def import_from_simple_data(data: dict, owner):
def import_from_simple_data(data: dict, owner, patient_id_company, email, phone):
family = data.get('family', '').title().strip()
name = data.get('name', '').title().strip()
patronymic = data.get('patronymic', '').title().strip()
sex = data.get('sex', '').lower().strip()
birthday = data.get('birthday', '').split(' ')[0]
snils = data.get('snils', '').split(' ')[0]

i = None
card = None
Expand All @@ -783,6 +785,7 @@ def import_from_simple_data(data: dict, owner):
birthday=birthday,
sex=sex,
owner=owner,
owner_patient_id=patient_id_company,
)
i.save()
else:
Expand Down Expand Up @@ -813,7 +816,9 @@ def import_from_simple_data(data: dict, owner):
i.save(update_fields=updated)

if i:
card = Card.add_l2_card(individual=i, force=True, owner=owner)
snils_type = DocumentType.objects.filter(title__startswith="СНИЛС").first()
document_snils = i.add_or_update_doc(snils_type, '', snils)
card = Card.add_l2_card(individual=i, force=True, owner=owner, snils=document_snils)

return card

Expand Down Expand Up @@ -1351,6 +1356,8 @@ def add_l2_card(
updated_data=None,
snils: Union['Document', None] = None,
owner=None,
email=email,
phone=phone,
):
f = {'owner': owner} if owner else {}
if distinct and card_orig and Card.objects.filter(individual=card_orig.individual if not force else (individual or card_orig.individual), base__internal_type=True, **f).exists():
Expand Down Expand Up @@ -1399,6 +1406,8 @@ def add_l2_card(
main_diagnosis='' if not card_orig else card_orig.main_diagnosis,
main_address=address or ('' if not card_orig else card_orig.main_address),
fact_address='' if not card_orig else card_orig.fact_address,
phone=phone,
email=email,
**f,
)
c.save()
Expand Down
5 changes: 5 additions & 0 deletions contracts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PriceName(models.Model):
hospital = models.ForeignKey('hospitals.Hospitals', blank=True, null=True, default=None, db_index=True, on_delete=models.SET_NULL)
external_performer = models.BooleanField(default=False, blank=True, help_text='Прайс внешний исполнитель', db_index=True)
subcontract = models.BooleanField(default=False, blank=True, help_text='Прайс субподряд', db_index=True)
symbol_code = models.CharField(max_length=55, unique=True, blank=True, null=True, default=None, help_text='Код прайса', db_index=True)

def __str__(self):
return "{}".format(self.title)
Expand All @@ -43,6 +44,10 @@ def status(self):
def get_company_price_by_date(company_id, date_start, date_end):
return PriceName.objects.filter(company_id=company_id, date_start__lte=date_start, date_end__gte=date_end).first()

@staticmethod
def get_hospital_price_by_date(hospital_id, date_start, date_end, is_subcontract=False):
return PriceName.objects.filter(hospital_id=hospital_id, date_start__lte=date_start, date_end__gte=date_end, subcontract=is_subcontract).first()

class Meta:
verbose_name = 'Название прайса'
verbose_name_plural = 'Названия прайса'
Expand Down
12 changes: 12 additions & 0 deletions directions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
MicrobiologyResultPhenotype,
RegisteredOrders,
ExternalAdditionalOrder,
NapravleniyaHL7LinkFiles,
)

admin.site.register(IstochnikiFinansirovaniya)
Expand Down Expand Up @@ -277,6 +278,16 @@ class ExternalAdditionalOrderAdmin(admin.ModelAdmin):
list_display = ('external_add_order',)


class NapravleniyaHL7FilesAdmin(admin.ModelAdmin):
raw_id_fields = ('napravleniye',)
list_display = (
'napravleniye_id',
'file_type',
'upload_file',
'created_at',
)


admin.site.register(TubesRegistration)
admin.site.register(Result)
admin.site.register(FrequencyOfUseResearches)
Expand All @@ -296,6 +307,7 @@ class ExternalAdditionalOrderAdmin(admin.ModelAdmin):
admin.site.register(DashboardChartFields, ResDashboardChartFields)
admin.site.register(MonitoringSumFieldByDay)
admin.site.register(MonitoringSumFieldTotal)
admin.site.register(NapravleniyaHL7LinkFiles, NapravleniyaHL7FilesAdmin)
admin.site.register(AdditionNapravleniya, ResAdditionNapravleniya)
admin.site.register(IssledovaniyaFiles, ResIssledovaniyaFiles)
admin.site.register(IssledovaniyaResultLaborant, ResIssledovaniyaResultLaborant)
Expand Down
Loading

0 comments on commit 0428181

Please sign in to comment.