Skip to content

Commit

Permalink
Merge pull request #4386 from mikhailprivalov/researched-constructor-…
Browse files Browse the repository at this point in the history
…permissions

Доступ к настройке услуги - фронт
  • Loading branch information
urchinpro authored Oct 14, 2024
2 parents e46b9ae + 59ee719 commit 6dc6da9
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 62 deletions.
2 changes: 2 additions & 0 deletions api/researches/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@
path('tube-related-data/update', views.tube_related_data_update),
path('research-performer-save', views.research_performer_save),
path('get-research-performer', views.get_research_performer),
path('get-research-permissions', views.get_research_permissions),
path('save-research-permissions', views.save_research_permissions),
]
22 changes: 21 additions & 1 deletion api/researches/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
ReleationsFT,
ParaclinicTemplateNameDepartment,
ParaclinicFieldTemplateDepartment,
ConstructorEditAccesResearch,
ConstructorEditAccessResearch,
)
from directory.sql_func import get_constructor_edit_access_by_research_id, get_constructor_edit_access_by_department_or_doctor
from directory.utils import get_researches_details
Expand Down Expand Up @@ -1233,3 +1233,23 @@ def research_performer_save(request):
def get_research_performer(request):
rows = DResearches.get_plan_performer()
return JsonResponse(rows, safe=False)


@login_required
@group_required("Оператор", "Конструктор: Параклинические (описательные) исследования")
def get_research_permissions(request):
request_data = json.loads(request.body)
research_id = request_data.get('researchId')
result = ConstructorEditAccessResearch.get_by_research(research_id)
return JsonResponse(result)


@login_required
@group_required("Оператор", "Конструктор: Параклинические (описательные) исследования")
def save_research_permissions(request):
request_data = json.loads(request.body)
research_id = request_data.get('researchId')
department_id = request_data.get('departmentId')
user_ids = request_data.get('userIds')
result = ConstructorEditAccessResearch.save_permissions(research_id, department_id, user_ids)
return JsonResponse(result)
2 changes: 1 addition & 1 deletion directory/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,4 @@ def master_research_hospital(self, obj):
admin.site.register(models.LaboratoryMaterial)
admin.site.register(models.SubGroupDirectory)
admin.site.register(models.SubGroupPadrazdeleniye)
admin.site.register(models.ConstructorEditAccesResearch, ResConstructorResearchAccessDepartment)
admin.site.register(models.ConstructorEditAccessResearch, ResConstructorResearchAccessDepartment)
26 changes: 24 additions & 2 deletions directory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.db.models import Q
from jsonfield import JSONField

from directory.sql_func import get_constructor_edit_access_by_research_id
from laboratory.settings import DEATH_RESEARCH_PK, EXCLUDE_TYPE_RESEARCH
from podrazdeleniya.models import Podrazdeleniya
from researches.models import Tubes
Expand Down Expand Up @@ -385,7 +386,7 @@ class Researches(models.Model):
laboratory_duration = models.CharField(max_length=3, default="", blank=True, verbose_name="Срок выполнения")
is_need_send_egisz = models.BooleanField(blank=True, default=False, help_text="Требуется отправка документав ЕГИСЗ")
count_volume_material_for_tube = models.FloatField(default=0, verbose_name="Количество материала для емкости в долях", blank=True)
templates_by_department = models.BooleanField(default=False, help_text="Искать шаблоны заполнения по подразделению")
templates_by_department = models.BooleanField(default=None, help_text="Искать шаблоны заполнения по подразделению", null=True, blank=True)

@staticmethod
def save_plan_performer(tb_data):
Expand Down Expand Up @@ -1259,7 +1260,7 @@ class Meta:
verbose_name_plural = "Поля описательного протокола"


class ConstructorEditAccesResearch(models.Model):
class ConstructorEditAccessResearch(models.Model):
research = models.ForeignKey(Researches, verbose_name="Услуга", on_delete=models.CASCADE)
department = models.ForeignKey(Podrazdeleniya, default=None, null=True, blank=True, verbose_name="Подразделение", on_delete=models.CASCADE, db_index=True)
doctor = models.ForeignKey(DoctorProfile, default=None, null=True, blank=True, verbose_name="Пользователь", on_delete=models.CASCADE, db_index=True)
Expand All @@ -1271,6 +1272,27 @@ class Meta:
verbose_name = "Доступ подразделений к изменению услуги(не создание)"
verbose_name_plural = "Доступы подразделений к изменению услуги(не создание)"

@staticmethod
def get_by_research(research_id):
access = get_constructor_edit_access_by_research_id(research_id)
user_ids = [i.doctor_id for i in access if i.doctor_id if i.doctor_id]
department_ids = [i.department_id for i in access if i.department_id]
result = {"departmentIds": department_ids, "userIds": user_ids}
return result

@staticmethod
def save_permissions(research_id, department_ids, user_ids):
access = ConstructorEditAccessResearch.objects.filter(research_id=research_id)
if access.exists():
access.delete()
for department_id in department_ids:
new_access_department = ConstructorEditAccessResearch(research_id=research_id, department_id=department_id)
new_access_department.save()
for user_id in user_ids:
new_access_user = ConstructorEditAccessResearch(research_id=research_id, doctor_id=user_id)
new_access_user.save()
return {"ok": True, "message": ""}


class ParaclinicFieldTemplateDepartment(models.Model):
"""
Expand Down
10 changes: 5 additions & 5 deletions directory/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def get_constructor_edit_access_by_research_id(research_id):
SELECT
department_id,
doctor_id
FROM directory_constructoreditaccesresearch
WHERE directory_constructoreditaccesresearch.research_id = %(research_id)s
FROM directory_constructoreditaccessresearch
WHERE directory_constructoreditaccessresearch.research_id = %(research_id)s
""",
params={'research_id': research_id},
)
Expand All @@ -150,9 +150,9 @@ def get_constructor_edit_access_by_department_or_doctor(department_id, doctor_id
department_id,
research_id,
doctor_id
FROM directory_constructoreditaccesresearch
WHERE directory_constructoreditaccesresearch.doctor_id = %(doctor_ids)s OR
directory_constructoreditaccesresearch.department_id = %(department_id)s
FROM directory_constructoreditaccessresearch
WHERE directory_constructoreditaccessresearch.doctor_id = %(doctor_ids)s OR
directory_constructoreditaccessresearch.department_id = %(department_id)s
""",
params={'doctor_ids': doctor_id, 'department_id': department_id},
)
Expand Down
4 changes: 0 additions & 4 deletions l2-frontend/src/construct/FastTemplatesEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,6 @@ export default {
type: Boolean,
required: false,
},
userDepartmentId: {
type: Number,
required: false,
},
},
data() {
return {
Expand Down
93 changes: 44 additions & 49 deletions l2-frontend/src/construct/ParaclinicResearchEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,20 @@
Шаблоны быстрого ввода
</button>
</span>
<label
<span
v-if="(ex_dep === 12 || simple) && fte && ex_dep !== 14"
class="input-group-addon"
class="input-group-btn"
>
<input
v-model="templatesByDepartment"
type="checkbox"
:disabled="!showAllDepartmentForTemplateField"
<button
class="btn btn-blue-nb no-margin-left"
type="button"
style="border-radius: 0;width: 100%;"
:disabled="has_unsaved || loaded_pk < 0"
@click="openPermissionsModal"
>
По подразделению
</label>
Права
</button>
</span>
</div>
<div
v-if="ex_dep !== 12 && ex_dep !== 13 && ex_dep !== 14 && ex_dep !== 15"
Expand All @@ -93,20 +96,6 @@
</option>
</select>
</div>
<div
v-if="templatesByDepartment && loaded_pk > 0"
class="input-group"
>
<span class="input-group-addon">Подразделения для шаблонов</span>
<Treeselect
v-model="departmentForTemplatesField"
class="treeselect-nbr treeselect-wide"
:options="departmentsForTemplatesField"
:clearable="showAllDepartmentForTemplateField"
placeholder="Выберите подразделение"
@input="changeTemplateField"
/>
</div>
</div>
<div
v-if="!simple && ex_dep !== 12 && ex_dep !== 13 && ex_dep !== 15"
Expand Down Expand Up @@ -278,17 +267,19 @@
Шаблоны быстрого ввода
</button>
</span>
<label
v-if="fte"
class="input-group-addon"
<span
class="input-group-btn"
>
<input
v-model="templatesByDepartment"
type="checkbox"
:disabled="!showAllDepartmentForTemplateField"
<button
class="btn btn-blue-nb no-margin-left"
type="button"
style="border-radius: 0;width: 100%;"
:disabled="has_unsaved || loaded_pk < 0"
@click="openPermissionsModal"
>
По подразделению
</label>
Права
</button>
</span>
</div>
</div>
<div
Expand Down Expand Up @@ -1128,17 +1119,19 @@
:title="title"
:research_pk="loaded_pk"
:groups="groups"
:by-department="templatesByDepartment"
:departments="departmentsForTemplatesField"
:show-all-departments="showAllDepartmentForTemplateField"
:user-department-id="userDepartmentId"
/>
<Localizations
v-if="show_localization"
:title="title"
:research_pk="loaded_pk"
@hide="hide_localization"
/>
<ResearchPermissionsModal
v-if="showPermissionsModal"
:research-id="loaded_pk"
:departments="departmentsForPermissions"
@hide="closePermissionsModal"
/>
</div>
</template>

Expand All @@ -1157,6 +1150,7 @@ import FieldHelper from '@/ui-cards/FieldHelper.vue';
import Localizations from '@/construct/Localizations.vue';
import PermanentDirectories from '@/construct/PermanentDirectories.vue';
import LoadFile from '@/ui-cards/LoadFile.vue';
import ResearchPermissionsModal from '@/construct/ResearchPermissionsModal.vue';
import FastTemplatesEditor from './FastTemplatesEditor.vue';
Expand All @@ -1165,6 +1159,7 @@ Vue.use(Vue2Filters);
export default {
name: 'ParaclinicResearchEditor',
components: {
ResearchPermissionsModal,
LoadFile,
PermanentDirectories,
FieldHelper,
Expand Down Expand Up @@ -1284,9 +1279,10 @@ export default {
dynamicDirectories: [],
autoRegisterRmisLocation: '',
departmentForTemplatesField: null,
departmentsForTemplatesField: [],
departmentsForPermissions: [],
showAllDepartmentForTemplateField: false,
userDepartmentId: null,
showPermissionsModal: false,
};
},
computed: {
Expand Down Expand Up @@ -1376,11 +1372,7 @@ export default {
async created() {
this.checkShowAllTemplates();
await this.load();
if (this.templatesByDepartment) {
await this.loadDepartmentsForTemplate();
} else {
this.departmentsForTemplatesField = [];
}
await this.loadDepartmentsForPermissions();
await this.load_deparments();
await this.loadDynamicDirectories();
},
Expand Down Expand Up @@ -1756,17 +1748,11 @@ export default {
const { rows } = await this.$api('external-system/fsidi-by-method', { method: this.currentMethod });
this.collectNsiResearchCode = rows;
},
async loadDepartmentsForTemplate() {
async loadDepartmentsForPermissions() {
await this.$store.dispatch(actions.INC_LOADING);
const { data } = await this.$api('get-departments-with-exclude', { exclude_type: [2] });
await this.$store.dispatch(actions.DEC_LOADING);
if (this.showAllDepartmentForTemplateField) {
this.departmentsForTemplatesField.push(...data);
} else {
const userDepartment = data.find((department) => department.id === this.userDepartmentId);
this.departmentsForTemplatesField.push(userDepartment);
this.departmentForTemplatesField = userDepartment.id;
}
this.departmentsForPermissions = data;
},
checkShowAllTemplates() {
this.userDepartmentId = this.$store.getters.user_data.department.pk;
Expand All @@ -1779,6 +1765,12 @@ export default {
async changeTemplateField() {
await this.load();
},
openPermissionsModal() {
this.showPermissionsModal = true;
},
closePermissionsModal() {
this.showPermissionsModal = false;
},
},
};
</script>
Expand Down Expand Up @@ -1989,4 +1981,7 @@ export default {
flex-direction: row;
gap: 10px;
}
.no-margin-left {
margin-left: 0 !important;
}
</style>
Loading

0 comments on commit 6dc6da9

Please sign in to comment.