Skip to content

Commit

Permalink
Merge pull request #4376 from mikhailprivalov/fix-chambers-v4.1
Browse files Browse the repository at this point in the history
Палаты и койки - v2.4
  • Loading branch information
urchinpro authored Oct 9, 2024
2 parents 3df6c85 + 3161742 commit f8e9514
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 47 deletions.
18 changes: 11 additions & 7 deletions api/chambers/sql_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,25 @@ def load_patient_without_bed_by_department(department_id):
cursor.execute(
"""
SELECT
family,
name,
patronymic,
date_part('year', age(birthday))::int AS age,
sex,
direction_id
clients_individual.family as patient_family,
clients_individual.name as patient_name,
clients_individual.patronymic as patient_patronymic,
date_part('year', age(clients_individual.birthday))::int AS patient_age,
clients_individual.sex as patient_sex,
direction_id,
users_doctorprofile.id as doctor_id
FROM podrazdeleniya_patientstationarwithoutbeds
LEFT JOIN directions_napravleniya ON podrazdeleniya_patientstationarwithoutbeds.direction_id = directions_napravleniya.id
LEFT JOIN clients_card ON directions_napravleniya.client_id = clients_card.id
LEFT JOIN clients_individual ON clients_card.individual_id = clients_individual.id
LEFT JOIN users_doctorprofile ON podrazdeleniya_patientstationarwithoutbeds.doctor_id = users_doctorprofile.id
WHERE
podrazdeleniya_patientstationarwithoutbeds.department_id = %(department_id)s
ORDER BY family
ORDER BY clients_individual.family
""",
params={"department_id": department_id},
)
Expand Down
21 changes: 13 additions & 8 deletions api/chambers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def get_unallocated_patients(request):
all_histories = load_patients_stationar_unallocated_sql(department_pk)
all_issledovaniya_ids = [history.issledovanie_id for history in all_histories]
all_issledovaniya_ids = tuple(all_issledovaniya_ids)
closed_histories = get_closing_protocols(all_issledovaniya_ids, transferable_epicrisis_titles)
closed_issledovaniya_ids = [extract.parent_id for extract in closed_histories]
closed_issledovaniya_ids = set(closed_issledovaniya_ids)
if all_issledovaniya_ids:
closed_histories = get_closing_protocols(all_issledovaniya_ids, transferable_epicrisis_titles)
closed_issledovaniya_ids = [extract.parent_id for extract in closed_histories]
closed_issledovaniya_ids = set(closed_issledovaniya_ids)

patients = [
{
Expand Down Expand Up @@ -197,6 +198,7 @@ def update_doctor_to_bed(request):
"direction_id": direction_id,
"bed_id": patient_to_bed.bed_id,
"department_id": bed_department_id,
"doctor_id": doctor_id,
},
)
return JsonResponse({"ok": result, "message": ""})
Expand All @@ -211,11 +213,12 @@ def get_patients_without_bed(request):

patients = [
{
"fio": f"{patient.family} {patient.name} {patient.patronymic if patient.patronymic else ''}",
"short_fio": f"{patient.family} {patient.name[0]}. {patient.patronymic[0] if patient.patronymic else ''}.",
"age": patient.age,
"sex": patient.sex,
"fio": f"{patient.patient_family} {patient.patient_name} {patient.patient_patronymic if patient.patient_patronymic else ''}",
"short_fio": f"{patient.patient_family} {patient.patient_name[0]}. {patient.patient_patronymic[0] if patient.patient_patronymic else ''}.",
"age": patient.patient_age,
"sex": patient.patient_sex,
"direction_pk": patient.direction_id,
"doctor_pk": patient.doctor_id,
}
for patient in patient_to_bed
]
Expand All @@ -228,11 +231,12 @@ def save_patient_without_bed(request):
request_data = json.loads(request.body)
department_pk = request_data.get('department_pk')
patient_obj = request_data.get('patient_obj')
doctor_id = request_data.get('doctor_id')
user = request.user
user_can_edit = Chamber.check_user(user, department_pk)
if not user_can_edit:
return status_response(False, "Пользователь не принадлежит к данному подразделению")
patient_without_bed = PatientStationarWithoutBeds(direction_id=patient_obj["direction_pk"], department_id=department_pk)
patient_without_bed = PatientStationarWithoutBeds(direction_id=patient_obj["direction_pk"], department_id=department_pk, doctor_id=doctor_id)
patient_without_bed.save()
Log.log(
patient_obj["direction_pk"],
Expand All @@ -241,6 +245,7 @@ def save_patient_without_bed(request):
{
"direction_id": patient_obj["direction_pk"],
"department_id": department_pk,
"doctor_id": doctor_id,
},
)
return status_response(True)
Expand Down
34 changes: 30 additions & 4 deletions l2-frontend/src/pages/ManageChambers/components/VueTippyDiv.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
<template>
<div
<component
:is="tag"
v-tippy="{
maxWidth: props.tippyMaxWidth,
}"
:title="show ? props.text : null"
@mouseenter="showTitle"
>
{{ props.text }}
</div>
<a
v-if="props.historyId && showLink"
class="a-under"
target="_blank"
:href="stationarLink(props.historyId)"
>
{{ props.text }}
</a>
<p v-else>
{{ props.text }}
</p>
</component>
</template>

<script setup lang="ts">
Expand All @@ -16,13 +27,26 @@ import { ref } from 'vue';
const props = defineProps({
text: {
type: String,
type: [String, undefined, null],
required: true,
},
tippyMaxWidth: {
type: String,
required: false,
},
tag: {
type: String,
required: false,
default: 'div',
},
historyId: {
type: Number,
required: false,
},
showLink: {
type: Boolean,
required: false,
},
});
const show = ref(false);
Expand All @@ -36,6 +60,8 @@ const showTitle = (event) => {
}
};
// eslint-disable-next-line max-len
const stationarLink = (historyId) => `/ui/stationar#{%22pk%22:${historyId},%22opened_list_key%22:null,%22opened_form_pk%22:null,%22every%22:false}`;
</script>

<style scoped lang="scss">
Expand Down
80 changes: 52 additions & 28 deletions l2-frontend/src/pages/ManageChambers/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,23 @@
Палата
</th>
<th>
Управление койками
(Кол.коек: {{ bedInformationCounter.bed }},
Занятых: {{ bedInformationCounter.occupied }},
М: {{ bedInformationCounter.man }},
Ж: {{ bedInformationCounter.women }})
<input
id="onlyUserPatient"
v-model="onlyUserPatient"
type="checkbox"
>
<label for="onlyUserPatient">Только мои</label>
<div class="flex-space">
<div>
Управление койками
(Кол.коек: {{ bedInformationCounter.bed }},
Занятых: {{ bedInformationCounter.occupied }},
М: {{ bedInformationCounter.man }},
Ж: {{ bedInformationCounter.women }})
</div>
<div>
<input
id="onlyUserPatient"
v-model="onlyUserPatient"
type="checkbox"
>
<label for="onlyUserPatient">Только мои</label>
</div>
</div>
</th>
</tr>
</thead>
Expand Down Expand Up @@ -162,6 +168,8 @@
<VueTippyDiv
v-if="bed.patient.length > 0"
:text="bed.patient[0].short_fio"
:history-id="bed.patient[0].direction_pk"
:show-link="userCanGoHistory"
class="text-size"
/>
<hr
Expand Down Expand Up @@ -209,6 +217,7 @@
ghost-class="ghost-patient-without-bed"
animation="500"
:disabled="!userCanEdit"
@start="copyWaitDoctor"
@change="PatientWaitBed"
>
<div
Expand Down Expand Up @@ -324,29 +333,32 @@ const departmentDocPk = ref(null);
const store = useStore();
const root = getCurrentInstance().proxy.$root;
const user = store.getters.user_data;
const userGroup = user.groups;
const userDepartmentId = user.department.pk;
const userCanGoHistory = ref(false);
const patientSearch = ref('');
const doctorSearch = ref('');
const onlyUserPatient = ref(false);
const transferDoctor = ref<doctorData>({
fio: '',
highlight: false,
pk: null,
short_fio: '',
});
const transferDoctor = ref(null);
const copyBedDoctor = (bed) => {
if (bed.doctor.length > 0) {
[transferDoctor.value] = bed.doctor;
transferDoctor.value = bed.doctor[0].pk;
}
};
const userCanEdit = computed(() => {
const { groups } = store.getters.user_data;
if (departmentPatientPk.value === userDepartmentId) {
return true;
}
return groups.includes('Палаты: все подразделения') || groups.includes('Admin');
return userGroup.includes('Палаты: все подразделения') || userGroup.includes('Admin');
});
const checkUserCanGoHistory = () => {
if (userGroup.includes('Врач стационара') || userGroup.includes('t, ad, p') || userGroup.includes('Admin')) {
userCanGoHistory.value = true;
}
};
const bedInformationCounter = computed(() => {
let women = 0;
let man = 0;
Expand Down Expand Up @@ -463,17 +475,12 @@ const changePatientBed = async ({ added, removed }, bed) => {
const { ok, message } = await api('chambers/entrance-patient-to-bed', {
bed_id: bed.pk,
direction_id: bed.patient[0].direction_pk,
doctor_id: transferDoctor.value.pk,
doctor_id: transferDoctor.value,
});
await store.dispatch(actions.DEC_LOADING);
if (ok) {
root.$emit('msg', 'ok', `Записан на кровать №${bed.bed_number}`);
transferDoctor.value = {
fio: '',
highlight: false,
pk: null,
short_fio: '',
};
transferDoctor.value = null;
} else {
root.$emit('msg', 'error', message);
}
Expand All @@ -499,10 +506,12 @@ const PatientWaitBed = async ({ added, removed }) => {
const { ok, message } = await api('chambers/save-patient-without-bed', {
patient_obj: added.element,
department_pk: departmentPatientPk.value,
doctor_id: transferDoctor.value,
});
await store.dispatch(actions.DEC_LOADING);
if (ok) {
root.$emit('msg', 'ok', 'Пациент переводен в ожидающие');
transferDoctor.value = null;
} else {
root.$emit('msg', 'error', message);
}
Expand Down Expand Up @@ -635,6 +644,14 @@ const countPatientAtDoctor = (doctor) => {
return patient;
};
const copyWaitDoctor = (event) => {
const index = event.oldIndex;
const outBeds = withOutBeds.value[index];
if (outBeds.doctor_pk) {
transferDoctor.value = outBeds.doctor_pk;
}
};
watch(departmentPatientPk, () => {
getUnallocatedPatients();
loadChamberAndBed();
Expand All @@ -643,7 +660,10 @@ watch(departmentPatientPk, () => {
watch(departmentDocPk, () => {
getAttendingDoctors();
});
onMounted(init);
onMounted(() => {
init();
checkUserCanGoHistory();
});
</script>

Expand Down Expand Up @@ -898,4 +918,8 @@ onMounted(init);
.opacity {
opacity: 0;
}
.flex-space {
display: flex;
justify-content: space-between;
}
</style>
1 change: 1 addition & 0 deletions podrazdeleniya/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class Meta:
class PatientStationarWithoutBeds(models.Model):
direction = models.ForeignKey("directions.Napravleniya", db_index=True, on_delete=models.CASCADE)
department = models.ForeignKey(Podrazdeleniya, db_index=True, on_delete=models.CASCADE, null=True)
doctor = models.ForeignKey("users.DoctorProfile", db_index=True, on_delete=models.CASCADE, null=True)

def __str__(self):
return f'{self.direction.client.individual.fio()}'
Expand Down

0 comments on commit f8e9514

Please sign in to comment.