Skip to content

Commit

Permalink
Merge pull request #3494 from mikhailprivalov/cancelTimeSlot
Browse files Browse the repository at this point in the history
отмена записи на слот
  • Loading branch information
Wellheor1 authored Feb 12, 2024
2 parents 7983651 + 29ecdcf commit b8e6f60
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/schedule/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
path('days', views.days),
path('details', views.details),
path('save', views.save),
path('cancel', views.cancel),
path('save-resource', views.save_resource),
path('search-resource', views.search_resource),
path('get-first-user-resource', views.get_first_user_resource),
Expand Down
24 changes: 23 additions & 1 deletion api/schedule/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from datetime import timedelta

from directory.models import Researches
from doctor_schedule.models import ScheduleResource, SlotFact, SlotPlan
from doctor_schedule.models import ScheduleResource, SlotFact, SlotPlan, SlotFactCancel
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from django.db import transaction
Expand Down Expand Up @@ -304,6 +304,28 @@ def save(request):
return status_response(False, 'Слот не найден')


@login_required
@group_required("Отмена записи")
def cancel(request):
data = data_parse(
request.body,
{'id': int, 'cardId': int, 'status': str, 'planId': int, 'serviceId': int, 'date': str, 'resource': str, 'disabled': bool, 'finSourceId': int},
{'planId': None, 'cardId': None, 'serviceId': None, 'status': 'reserved', 'date': None, 'resource': None, 'disabled': False, 'finSourceId': None},
)
pk: int = data[0]
card_pk: int = data[1]
service_id: int = data[4]

s: SlotPlan = SlotPlan.objects.filter(pk=pk).first()
if s:
save_slot = SlotFactCancel.cancel_slot(pk, card_pk, service_id, request.user.doctorprofile)
return status_response(
save_slot,
)

return status_response(False, 'Не получилось отменить')


def save_slot_fact(s, card_pk, status, service_id, is_cito, fin_source, plan_id, disabled):
if card_pk:
status = {
Expand Down
9 changes: 8 additions & 1 deletion doctor_schedule/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from .models import ScheduleResource, SlotPlan, SlotFact, UserResourceModifyRights
from .models import ScheduleResource, SlotPlan, SlotFact, UserResourceModifyRights, ReasonCancelSlot, SlotFactCancel


class ScheduleResourceAdmin(admin.ModelAdmin):
Expand Down Expand Up @@ -33,7 +33,14 @@ class UserResourceModifyRightsAdmin(admin.ModelAdmin):
filter_horizontal = ('resources', 'departments', 'services')


class SlotFactCancelAdmin(admin.ModelAdmin):
list_display = ('pk', 'plan', 'patient')
search_fields = ('plan',)


admin.site.register(ScheduleResource, ScheduleResourceAdmin)
admin.site.register(SlotPlan, SlotPlanAdmin)
admin.site.register(SlotFact, SlotFactAdmin)
admin.site.register(UserResourceModifyRights, UserResourceModifyRightsAdmin)
admin.site.register(ReasonCancelSlot)
admin.site.register(SlotFactCancel, SlotFactCancelAdmin)
36 changes: 36 additions & 0 deletions doctor_schedule/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,39 @@ class UserResourceModifyRights(models.Model):
class Meta:
verbose_name = 'Права доступа к управлению расписанием'
verbose_name_plural = 'Права доступа к управлению расписанием'


class ReasonCancelSlot(models.Model):
title = models.CharField(max_length=255, default="", help_text='Причина отмены', db_index=True)

def __str__(self):
return f"{self.title}"

class Meta:
verbose_name = 'Причина отмены записи'
verbose_name_plural = 'Причины отмены записи'


class SlotFactCancel(models.Model):
plan = models.ForeignKey(SlotPlan, db_index=True, verbose_name='Слот-план', on_delete=models.CASCADE)
patient = models.ForeignKey(Card, verbose_name='Карта пациента', db_index=True, null=True, on_delete=models.SET_NULL)
external_slot_id = models.CharField(max_length=255, default='', blank=True, verbose_name='Внешний ИД')
service = models.ForeignKey(Researches, verbose_name='Услуга', db_index=True, null=True, blank=True, on_delete=models.CASCADE)
user = models.ForeignKey(DoctorProfile, verbose_name='Отмена записи', default=None, blank=True, null=True, on_delete=models.SET_NULL)
reason_cancel_slot = models.ForeignKey(ReasonCancelSlot, verbose_name='причина записи', default=None, blank=True, null=True, on_delete=models.SET_NULL)

def __str__(self):
return f"{self.pk}{self.patient} {self.plan}"

class Meta:
verbose_name = 'Отмена записи на слот'
verbose_name_plural = 'Отмена записей на слоты'

@staticmethod
def cancel_slot(plan_id, card_id, service_id, user):
s = SlotFactCancel(plan_id=plan_id, patient_id=card_id, service_id=service_id, user=user)
s.save()
if s:
slot_fact = SlotFact.objects.filter(plan_id=plan_id).first()
slot_fact.delete()
return True
36 changes: 36 additions & 0 deletions l2-frontend/src/pages/Schedule/TimeSlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
>
Закрыть
</button>
<button
v-if="details && details.factId && details.status === 'reserved' && canCancelSlot"
class="btn btn-blue-nb"
type="button"
@click="cancelSlot"
>
Отменить запись
</button>
</div>
<div class="col-xs-6">
<button
Expand Down Expand Up @@ -259,6 +267,14 @@ export default class TimeSlot extends Vue {
return `${this.data.duration * 2}px`;
}
get userGroups() {
return this.$store.getters.user_data.groups || [];
}
get canCancelSlot() {
return this.userGroups.includes('Отмена записи посещения');
}
async loadData() {
this.details = null;
await this.$store.dispatch(actions.INC_LOADING);
Expand Down Expand Up @@ -356,6 +372,26 @@ export default class TimeSlot extends Vue {
await this.$store.dispatch(actions.DEC_LOADING);
}
async cancelSlot() {
await this.$store.dispatch(actions.INC_LOADING);
const { ok, message } = await this.$api('/schedule/cancel', {
...this.data,
...this.details,
serviceId: this.details.service.id,
});
if (ok) {
this.$root.$emit('msg', 'ok', 'Сохранено');
this.close();
} else {
this.$root.$emit('msg', 'error', message);
}
this.$root.$emit('reload-slots');
await this.$store.dispatch(actions.DEC_LOADING);
}
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion medical_certificates/forms/forms380.py
Original file line number Diff line number Diff line change
Expand Up @@ -1849,7 +1849,7 @@ def form_13(request_data):
elif i["title"] == "Председатель врачебной комиссии":
chairman = i["value"]

fwb.append(Paragraph('Медицинское заключение по результатам предварительного', styleCenterBold))
fwb.append(Paragraph(f'Медицинское заключение по результатам {type_med_examination_padeg}', styleCenterBold))
fwb.append(Paragraph(f'медицинского осмотра (обследования) № {direction}', styleCenterBold))
fwb.append(Spacer(1, 8 * mm))
fwb.append(Paragraph(f'1. Ф.И.О: {fio} ', style))
Expand Down

0 comments on commit b8e6f60

Please sign in to comment.