Skip to content

Commit

Permalink
aggregate base
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailprivalov committed Oct 8, 2023
1 parent 80d83e4 commit 505991c
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 118 deletions.
96 changes: 7 additions & 89 deletions api/cases/stationar_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,49 +182,8 @@ def hosp_get_curent_hosp_dir(current_iss):
return current_dir.parent.napravleniye_id


def hosp_get_lab_iss(current_iss, extract=False, *directions):
"""
агрегация результатов исследований
возврат: Если extract=True(выписка), то берем по всем hosp-dirs. Если эпикриз, то берем все исследования
до текущего hosp-dirs
Выход: {КДЛ:{vert:[{titile:'',fractions:[],results:[{date:"",values:[]}]}]},
{horizont:[{titile:'', results:[{date:'',value:''},{date:'',value:''}]}]}}
"""
if not directions:
obj_iss = Issledovaniya.objects.get(pk=current_iss)
num_dir = obj_iss.napravleniye_id

# получить все направления в истории по типу hosp
hosp_dirs = hosp_get_hosp_direction(num_dir)

# получить текущее направление типа hosp из текущего исследования
current_dir = hosp_get_curent_hosp_dir(current_iss)
# проверить - это переводной эпикриз
epicris = False
if obj_iss.research.is_slave_hospital:
obj_hospital_service = HospitalService.objects.filter(slave_research=obj_iss.research).first().site_type
if obj_hospital_service == 6:
epicris = True

if epicris:
hosp_dirs = [i for i in hosp_dirs if i["direction"] <= current_dir]

num_lab_dirs = set()
if (not extract) and (not epicris):
obj_hosp_dirs = hosp_get_data_direction(current_dir, site_type=-1, type_service='is_lab', level=2)
for k in obj_hosp_dirs:
lab_dir = k.get('direction')
num_lab_dirs.add(lab_dir)

# получить по каждому hosp_dirs Дочерние направления по типу лаборатория
if extract or epicris:
for h in hosp_dirs:
obj_hosp_dirs = hosp_get_data_direction(h["direction"], site_type=-1, type_service='is_lab', level=2)
for k in obj_hosp_dirs:
lab_dir = k.get('direction')
num_lab_dirs.add(lab_dir)
if directions:
num_lab_dirs = directions
def hosp_get_lab_iss(directions):
num_lab_dirs = directions

num_lab_dirs = list(num_lab_dirs)
if len(num_lab_dirs) == 0:
Expand Down Expand Up @@ -335,43 +294,11 @@ def hosp_get_lab_iss(current_iss, extract=False, *directions):
return result_filtered


def hosp_get_text(current_iss, extract=False, mode=None, directions=None):
# # Возврат стр-ра:
# {'paraclinic': [{'title_research': 'Проведение электрокардиографических исследований ( ЭКГ )', 'result': [
# {'date': '05.01.20 117', 'data': [{'group_title': '', 'fields': [{'title_field': 'Заключение',
# 'value': 'Повышение пучка Гиса'}]}]},
# {'date': '05.01.20 119', 'data': [{'group_title': '', 'fields': [{'title_field': 'Заключение',
# 'value': 'Диффузные нарушения'}]}]}]} ]}]
# ]}
if directions is None:
directions = []
if directions:
num_paraclinic_dirs = directions
else:
if mode is None:
return {}
num_dir = Issledovaniya.objects.get(pk=current_iss).napravleniye_id
# получить все направления в истории по типу hosp
hosp_dirs = hosp_get_hosp_direction(num_dir)

# получить текущее направление типа hosp из текущего эпикриза
current_dir = hosp_get_curent_hosp_dir(current_iss)
if not extract:
hosp_dirs = [i for i in hosp_dirs if i["direction"] <= current_dir]

# получить по каждому hosp_dirs Дочерние направления по типу is_paraclinic, is_doc_refferal, is_morfology
num_paraclinic_dirs = set()
for h in hosp_dirs:
obj_hosp_dirs = hosp_get_data_direction(h["direction"], site_type=-1, type_service=mode, level=2)
if not obj_hosp_dirs:
continue
for k in obj_hosp_dirs:
paraclinic_dir = k.get('direction')
num_paraclinic_dirs.add(paraclinic_dir)

def hosp_get_text(directions):
num_paraclinic_dirs = directions
num_paraclinic_dirs = list(num_paraclinic_dirs)

return desc_to_data(num_paraclinic_dirs)
return desc_to_data(num_paraclinic_dirs, force_all_fields=True)


def desc_to_data(num_dirs: List[int], force_all_fields: bool = False):
Expand Down Expand Up @@ -432,18 +359,9 @@ def desc_to_data(num_dirs: List[int], force_all_fields: bool = False):
return result


def hosp_get_text_iss(current_iss, is_extract, mode):
if mode is None:
return []
if mode == 'desc':
modes = ['is_paraclinic', 'is_doc_refferal', 'is_morfology']
else:
modes = [mode]

def hosp_get_text_iss(directions):
v = []
for m in modes:
v.extend(hosp_get_text(current_iss, is_extract, mode=m))

v.extend(hosp_get_text(directions))
return v


Expand Down
27 changes: 9 additions & 18 deletions api/cases/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from api.cases.helpers import get_case_direction_tree
from api.cases.stationar_func import (
get_direction_attrs,
hosp_get_lab_iss,
hosp_get_lab_iss, hosp_get_text_iss,
)
from clients.models import Card
from directions.models import Issledovaniya, Napravleniya
Expand Down Expand Up @@ -245,25 +245,17 @@ def directions_by_key(request):
'date_create': strfdatetime(x.data_sozdaniya_local, "%d.%m.%Y"),
'researches_short': [y.short_title for y in x.services],
'researches': [y.title for y in x.services],
'showResults': x.issledovaniya_set.all().filter(research__podrazdeleniye__p_type=2).exists(),
}
for x in directions
]})


@login_required
def aggregate_laboratory(request):
data = json.loads(request.body)
pk = data.get('caseId', -1)
result = hosp_get_lab_iss(pk, False)
return JsonResponse(result)


@login_required
def aggregate(request):
data = json.loads(request.body)
pk = data.get('caseId', -1)
view = data.get("view")

pk = data.get('caseDirection', -1)
view = data["view"]
directions = Napravleniya.objects.filter(parent_case__napravleniye_id=pk)

if view == 'laboratory':
Expand All @@ -277,9 +269,8 @@ def aggregate(request):

directions = directions.distinct().order_by('id')

return JsonResponse({'rows': [
{
'confirm': x.total_confirmed,
}
for x in directions
]})
if view == 'laboratory':
result = hosp_get_lab_iss([x.pk for x in directions])
else:
result = hosp_get_text_iss([x.pk for x in directions])
return JsonResponse(result, safe=False)
7 changes: 6 additions & 1 deletion l2-frontend/src/fields/AggregateDesc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const makeKey = (t, group) => `${group}${delimiter}${t}`;
export default {
props: {
pk: {},
caseDirection: {},
extract: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -171,7 +172,11 @@ export default {
return s.split(delimiter)[1];
},
async load() {
this.data = await stationarPoint.aggregateDesc(this, ['pk', 'extract', 'r_type']);
if (this.caseDirection) {
this.data = await this.$api('cases/aggregate', this, ['caseDirection'], { view: this.r_type });
} else {
this.data = await stationarPoint.aggregateDesc(this, ['pk', 'extract', 'r_type']);
}
},
fix_html(v) {
let lv = v;
Expand Down
7 changes: 6 additions & 1 deletion l2-frontend/src/fields/AggregateLaboratory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const makeKey = (t, group) => `${group}${delimiter}${t}`;
export default {
props: {
pk: {},
caseDirection: {},
extract: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -297,7 +298,11 @@ export default {
async load() {
this.excluded.dateDir = [];
this.excluded.titles = [];
this.data = await stationarPoint.aggregateLaboratory(this, ['pk', 'extract']);
if (this.caseDirection) {
this.data = await this.$api('cases/aggregate', this, ['caseDirection'], { view: 'laboratory' });
} else {
this.data = await stationarPoint.aggregateLaboratory(this, ['pk', 'extract']);
}
},
excludedTitle(t, group) {
const title = makeKey(t, group);
Expand Down
14 changes: 14 additions & 0 deletions l2-frontend/src/hooks/usePrint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { getCurrentInstance } from 'vue';

export default () => {
const root = getCurrentInstance().proxy.$root;

return {
printResults(ids: number[]) {
root.$emit(
'print:results',
ids,
);
},
};
};
1 change: 1 addition & 0 deletions l2-frontend/src/modals/ResultsViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ export default {
methods: {
hide_modal() {
this.$root.$emit('hide_results');
this.$emit('hide');
if (this.$refs.modal) {
this.$refs.modal.$el.style.display = 'none';
}
Expand Down
50 changes: 43 additions & 7 deletions l2-frontend/src/pages/CaseControl/Content/TopView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,38 @@ import { computed, ref, watch } from 'vue';
import useLoader from '@/hooks/useLoader';
import useOn from '@/hooks/useOn';
import usePrint from '@/hooks/usePrint';
import { menuItems } from '@/pages/CaseControl/Sidebar/menu';
import DisplayDirection from '@/pages/Stationar/DisplayDirection.vue';
import api from '@/api';
import ResultsViewer from '@/modals/ResultsViewer.vue';
// eslint-disable-next-line no-spaced-func,func-call-spacing
const emit = defineEmits<{
(e: 'input', value: number): void
(e: 'close-view'): void
(e: 'close-direction'): void
}>();
const props = defineProps<{
caseId?: number | null;
view?: string | null;
value?: number | null;
}>();
type Direction = {
pk: number;
confirm: boolean;
date_create: boolean;
researches_short: string[];
researches: string[];
showResults: boolean;
};
const loader = useLoader();
const { printResults } = usePrint();
const mainItem = computed(() => menuItems[props.view]);
const directions = ref<any[]>([]);
const directions = ref<Direction[]>([]);
const showResultsId = ref<number | null>(null);
const loadDirections = async () => {
if (!props.caseId || !props.view) {
Expand All @@ -41,12 +55,22 @@ useOn('researches-picker:directions_createdcd', loadDirections);
// eslint-disable-next-line @typescript-eslint/no-empty-function
const printAll = () => {
printResults(directions.value.map((d) => d.pk));
};
const close = () => {
emit('close-view');
};
const openDirection = (id: number) => {
emit('input', id);
const closeDirection = () => {
emit('close-direction');
};
const openDirection = (d: Direction) => {
if (d.showResults) {
showResultsId.value = d.pk;
} else if (props.view === 'all') {
printResults([d.pk]);
} else {
emit('input', d.pk);
}
};
</script>

Expand Down Expand Up @@ -77,12 +101,24 @@ const openDirection = (id: number) => {
$style.block,
$style.direction,
]"
@click="openDirection(d.pk)"
@click="openDirection(d)"
>
<span>
<DisplayDirection :direction="d" />
<i
v-if="props.value === d.pk"
class="fa fa-times"
:class="$style.topRight"
@click="closeDirection"
/>
</span>
</div>
<ResultsViewer
v-if="showResultsId"
:pk="showResultsId"
no_desc
@hide="showResultsId = null"
/>
</div>
</template>

Expand Down Expand Up @@ -146,20 +182,20 @@ export default {
left: 0;
}
&:hover {
&:hover:not(.active) {
z-index: 1;
transform: translateY(-1px);
}
&:not(.confirmed):hover {
&:not(.confirmed):not(.active):hover {
box-shadow: 0 7px 14px rgba(0, 0, 0, 0.1), 0 5px 5px rgba(0, 0, 0, 0.12);
}
&.confirmed {
border-color: #049372;
background: linear-gradient(to bottom, #04937254 0%, #049372ba 100%);
&:hover {
&:hover:not(.active) {
box-shadow: 0 7px 14px #04937254, 0 5px 5px #049372ba;
}
}
Expand Down
Loading

0 comments on commit 505991c

Please sign in to comment.