2022-04-04 02:54:31 +08:00
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
import { ref, watch } from "vue"
|
2022-04-09 22:57:06 +08:00
|
|
|
import dayjs from 'dayjs'
|
|
|
|
import quarterOfYear from 'dayjs/plugin/quarterOfYear'
|
2022-04-04 02:54:31 +08:00
|
|
|
import {
|
|
|
|
GET_SAMPLE_GROUP_BY_STATUS,
|
|
|
|
GET_ANALYSIS_GROUP_BY_STATUS,
|
|
|
|
GET_WORKSHEET_GROUP_BY_STATUS,
|
2022-11-27 04:32:49 +08:00
|
|
|
GET_EXTRAS_GROUP_BY_STATUS,
|
2022-04-04 02:54:31 +08:00
|
|
|
GET_ANALYSIS_GROUP_BY_INSTRUMENT,
|
|
|
|
GET_SAMPLE_PROCESS_PEFORMANCE,
|
|
|
|
GET_ANALYSIS_PROCESS_PEFORMANCE,
|
|
|
|
GET_SAMPLE_GROUPS_BY_ACTION,
|
|
|
|
GET_SAMPLE_LAGGARDS,
|
|
|
|
} from '../graphql/dashboard.queries'
|
|
|
|
|
|
|
|
import { useApiUtil } from "../composables";
|
|
|
|
const { withClientQuery } = useApiUtil();
|
|
|
|
|
|
|
|
interface GroupCount {
|
|
|
|
group: string,
|
|
|
|
count: number,
|
|
|
|
}
|
2022-04-09 22:57:06 +08:00
|
|
|
interface ISampleCounts {
|
|
|
|
totalSamples: number;
|
|
|
|
totalLate: number;
|
|
|
|
totalNotLate: number;
|
|
|
|
processAverage: number;
|
|
|
|
avgExtraDays: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IAnalysisGroup extends ISampleCounts {
|
|
|
|
service: string
|
|
|
|
}
|
|
|
|
export interface IProcess {
|
|
|
|
process: string;
|
|
|
|
counts: ISampleCounts,
|
|
|
|
groups: IAnalysisGroup[],
|
|
|
|
}
|
|
|
|
|
|
|
|
dayjs.extend(quarterOfYear)
|
2022-04-04 02:54:31 +08:00
|
|
|
|
|
|
|
export const useDashBoardStore = defineStore('dashboard', () => {
|
|
|
|
|
|
|
|
const dashboard = ref({
|
|
|
|
currentTab: 'overview',
|
2022-11-06 21:09:15 +08:00
|
|
|
tabs: ['overview', 'resource', 'laggard', 'peformance', 'notices', 'line-listing'], // 'tat'
|
2022-04-09 22:57:06 +08:00
|
|
|
showFilters: false,
|
2022-04-04 02:54:31 +08:00
|
|
|
filterRange: { from: "", to: "" },
|
2022-04-22 03:33:54 +08:00
|
|
|
currentFilter: "T",
|
|
|
|
filters: ['T', 'Y', 'TW', 'LW', 'TM', 'LM', 'TQ', 'LQ', 'TY'],
|
|
|
|
overViewStats: {
|
|
|
|
analyses: [] as GroupCount[],
|
|
|
|
samples: [] as GroupCount[],
|
2022-11-27 04:32:49 +08:00
|
|
|
extras: [] as GroupCount[],
|
2022-04-22 03:33:54 +08:00
|
|
|
worksheets: [] as GroupCount[]
|
|
|
|
},
|
2022-04-15 16:32:24 +08:00
|
|
|
fetchingOverViewStats: false,
|
2022-04-22 03:33:54 +08:00
|
|
|
resourceStats: {
|
|
|
|
instruments: [] as GroupCount[], samples: [] as any[]
|
|
|
|
},
|
2022-04-15 16:32:24 +08:00
|
|
|
fetchingResourceStats: false,
|
2022-04-22 03:33:54 +08:00
|
|
|
peformancePeriods: [30, 60, 90, 180, 365],
|
|
|
|
currentPeformancePeriod: 30,
|
|
|
|
peformanceStats: {
|
|
|
|
sample: [] as IProcess[],
|
|
|
|
analysis: [] as IProcess[]
|
|
|
|
},
|
2022-04-15 16:32:24 +08:00
|
|
|
fetchingSampePeformanceStats: false,
|
|
|
|
fetchingAnalysisPeformanceStats: false,
|
2022-04-09 22:57:06 +08:00
|
|
|
currentPeformance: "received_to_published",
|
|
|
|
performances: ["received_to_published", "received_to_submitted","submitted_to_verified", "verified_to_published"],
|
2022-04-15 16:32:24 +08:00
|
|
|
laggards: {} as any,
|
|
|
|
fetchingLaggards: false
|
2022-04-04 02:54:31 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
// get_OverViewStats
|
|
|
|
const getOverViewStats = async () => {
|
2022-04-15 16:32:24 +08:00
|
|
|
dashboard.value.fetchingOverViewStats = true;
|
|
|
|
try {
|
|
|
|
await countSamplesGroupsByStatus();
|
|
|
|
await countAnalysisGroupsByStatus();
|
|
|
|
await countWrksheetGroupsByStatus();
|
2022-11-27 04:32:49 +08:00
|
|
|
await countExtrasGroupsByStatus();
|
2022-04-15 16:32:24 +08:00
|
|
|
} catch (error) {
|
|
|
|
dashboard.value.fetchingOverViewStats = false;
|
|
|
|
}
|
|
|
|
dashboard.value.fetchingOverViewStats = false;
|
2022-04-04 02:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// get_PeformanceStats
|
|
|
|
const getResourceStats = async () => {
|
2022-04-15 16:32:24 +08:00
|
|
|
dashboard.value.fetchingResourceStats = true;
|
|
|
|
try {
|
|
|
|
await countAnalysisGroupsByInstrument();
|
|
|
|
await getSampleGroupByAction();
|
|
|
|
} catch (error) {
|
|
|
|
dashboard.value.fetchingResourceStats = false;
|
|
|
|
}
|
|
|
|
dashboard.value.fetchingResourceStats = false;
|
2022-04-04 02:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GET_SAMPLE_GROUP_BY_STATUS
|
|
|
|
const countSamplesGroupsByStatus = async () => {
|
2022-04-09 22:57:06 +08:00
|
|
|
const filters = {
|
|
|
|
startDate: dashboard.value.filterRange.from,
|
|
|
|
endDate: dashboard.value.filterRange.to
|
|
|
|
}
|
2022-04-15 16:32:24 +08:00
|
|
|
await withClientQuery(GET_SAMPLE_GROUP_BY_STATUS, filters , 'countSampleGroupByStatus', 'network-only')
|
2022-04-04 02:54:31 +08:00
|
|
|
.then(payload => dashboard.value.overViewStats.samples = payload.data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GET_ANALYSIS_GROUP_BY_STATUS
|
|
|
|
const countAnalysisGroupsByStatus = async () => {
|
2022-04-09 22:57:06 +08:00
|
|
|
const filters = {
|
|
|
|
startDate: dashboard.value.filterRange.from,
|
|
|
|
endDate: dashboard.value.filterRange.to
|
|
|
|
}
|
2022-04-15 16:32:24 +08:00
|
|
|
await withClientQuery(GET_ANALYSIS_GROUP_BY_STATUS, filters , 'countAnalyteGroupByStatus', 'network-only')
|
2022-04-04 02:54:31 +08:00
|
|
|
.then(payload => dashboard.value.overViewStats.analyses = payload.data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GET_WORKSHEET_GROUP_BY_STATUS
|
|
|
|
const countWrksheetGroupsByStatus = async () => {
|
2022-04-09 22:57:06 +08:00
|
|
|
const filters = {
|
|
|
|
startDate: dashboard.value.filterRange.from,
|
|
|
|
endDate: dashboard.value.filterRange.to
|
|
|
|
}
|
2022-04-15 16:32:24 +08:00
|
|
|
await withClientQuery(GET_WORKSHEET_GROUP_BY_STATUS,filters, 'countWorksheetGroupByStatus', 'network-only')
|
2022-04-04 02:54:31 +08:00
|
|
|
.then(payload => dashboard.value.overViewStats.worksheets = payload.data)
|
|
|
|
}
|
|
|
|
|
2022-11-27 04:32:49 +08:00
|
|
|
// GET_extras_GROUP_BY_STATUS
|
|
|
|
const countExtrasGroupsByStatus = async () => {
|
|
|
|
const filters = {
|
|
|
|
startDate: dashboard.value.filterRange.from,
|
|
|
|
endDate: dashboard.value.filterRange.to
|
|
|
|
}
|
|
|
|
await withClientQuery(GET_EXTRAS_GROUP_BY_STATUS, filters , 'countExtrasGroupByStatus', 'network-only')
|
|
|
|
.then(payload => dashboard.value.overViewStats.extras = payload.data)
|
|
|
|
}
|
|
|
|
|
2022-04-04 02:54:31 +08:00
|
|
|
// GET_ANALYSIS_GROUP_BY_INSTRUMENT
|
|
|
|
const countAnalysisGroupsByInstrument = async () => {
|
2022-04-09 22:57:06 +08:00
|
|
|
const filters = {
|
|
|
|
startDate: dashboard.value.filterRange.from,
|
|
|
|
endDate: dashboard.value.filterRange.to
|
|
|
|
}
|
2022-04-15 16:32:24 +08:00
|
|
|
await withClientQuery(GET_ANALYSIS_GROUP_BY_INSTRUMENT,filters, 'countAnalyteGroupByInstrument', 'network-only')
|
2022-04-04 02:54:31 +08:00
|
|
|
.then(payload => dashboard.value.resourceStats.instruments = payload.data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GET_SAMPLE_GROUPS_BY_ACTION
|
|
|
|
const getSampleGroupByAction = async () => {
|
2022-04-09 22:57:06 +08:00
|
|
|
const filters = {
|
|
|
|
startDate: dashboard.value.filterRange.from,
|
|
|
|
endDate: dashboard.value.filterRange.to
|
|
|
|
}
|
2022-04-15 16:32:24 +08:00
|
|
|
await withClientQuery(GET_SAMPLE_GROUPS_BY_ACTION,filters, 'countSampleGroupByAction', 'network-only')
|
2022-04-04 02:54:31 +08:00
|
|
|
.then(payload => dashboard.value.resourceStats.samples = payload.data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GET_SAMPLE_PROCESS_PEFORMANCE
|
|
|
|
const getSampleProcessPeformance = async () => {
|
2022-04-09 22:57:06 +08:00
|
|
|
const filters = {
|
2022-04-22 03:33:54 +08:00
|
|
|
startDate: dayjs().startOf('day').subtract(dashboard.value.currentPeformancePeriod, 'day').toISOString(),
|
|
|
|
endDate: dayjs().endOf('day').toISOString()
|
2022-04-09 22:57:06 +08:00
|
|
|
}
|
2022-04-16 03:57:45 +08:00
|
|
|
dashboard.value.fetchingSampePeformanceStats = true
|
2022-04-15 16:32:24 +08:00
|
|
|
await withClientQuery(GET_SAMPLE_PROCESS_PEFORMANCE,filters, 'sampleProcessPerformance', 'network-only')
|
|
|
|
.then(payload => {
|
2022-04-16 03:57:45 +08:00
|
|
|
dashboard.value.fetchingSampePeformanceStats = false
|
2022-04-15 16:32:24 +08:00
|
|
|
dashboard.value.peformanceStats.sample = payload.data
|
2022-04-16 03:57:45 +08:00
|
|
|
}).catch(err => dashboard.value.fetchingSampePeformanceStats = false)
|
2022-04-04 02:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GET_ANALYSIS_PROCESS_PEFORMANCE
|
|
|
|
const getAnalysisProcessPeformance = async () => {
|
2022-04-09 22:57:06 +08:00
|
|
|
const filters = {
|
|
|
|
process: dashboard.value.currentPeformance,
|
2022-04-22 03:33:54 +08:00
|
|
|
startDate: dayjs().startOf('day').subtract(dashboard.value.currentPeformancePeriod, 'day').toISOString(),
|
|
|
|
endDate: dayjs().endOf('day').toISOString()
|
2022-04-09 22:57:06 +08:00
|
|
|
}
|
2022-04-16 03:57:45 +08:00
|
|
|
dashboard.value.fetchingAnalysisPeformanceStats = true
|
2022-04-15 16:32:24 +08:00
|
|
|
await withClientQuery(GET_ANALYSIS_PROCESS_PEFORMANCE,filters, 'analysisProcessPerformance', 'network-only')
|
|
|
|
.then(payload => {
|
2022-04-16 03:57:45 +08:00
|
|
|
dashboard.value.fetchingAnalysisPeformanceStats = false
|
2022-04-15 16:32:24 +08:00
|
|
|
dashboard.value.peformanceStats.analysis = payload.data
|
2022-04-16 03:57:45 +08:00
|
|
|
}).catch(err => dashboard.value.fetchingAnalysisPeformanceStats = false)
|
2022-04-04 02:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// GET_SAMPLE_LAGGARDS
|
2022-04-09 22:57:06 +08:00
|
|
|
const getSampleLaggards = async () => {
|
2022-04-15 16:32:24 +08:00
|
|
|
dashboard.value.fetchingLaggards = true;
|
2022-04-22 03:33:54 +08:00
|
|
|
await withClientQuery(GET_SAMPLE_LAGGARDS, {}, 'sampleLaggards', 'network-only')
|
2022-04-15 16:32:24 +08:00
|
|
|
.then(payload => {
|
|
|
|
dashboard.value.laggards = payload.data
|
|
|
|
dashboard.value.fetchingLaggards = false;
|
|
|
|
}).catch(err => dashboard.value.fetchingLaggards = false)
|
2022-04-04 02:54:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const setCurrentTab = (tab: string) => dashboard.value.currentTab = tab;
|
|
|
|
const setCurrentFilter = (filter: string) => dashboard.value.currentFilter = filter;
|
|
|
|
const setFilterRange = (from: string, to: string) => {dashboard.value.filterRange.from = from; dashboard.value.filterRange.to = to}
|
2022-04-09 22:57:06 +08:00
|
|
|
const setCurrentPeformance = (event: any) => {
|
|
|
|
dashboard.value.currentPeformance = event.target.value
|
|
|
|
};
|
2022-04-22 03:33:54 +08:00
|
|
|
const setCurrentPeformancePeriod = (event: any) => {
|
|
|
|
const period: number = +event.target.value
|
|
|
|
dashboard.value.currentPeformancePeriod = period
|
|
|
|
};
|
|
|
|
const setShowFilters = (show: boolean) => dashboard.value.showFilters = show;
|
2022-04-04 02:54:31 +08:00
|
|
|
|
|
|
|
const calculateFilterRange = (filter: string): void => {
|
|
|
|
switch (filter) {
|
2022-04-09 22:57:06 +08:00
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'T':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('day').toISOString(), dayjs().endOf('day').toISOString())
|
|
|
|
break;
|
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'Y':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('day').subtract(1, 'day').toISOString(), dayjs().endOf('day').subtract(1, 'day').toISOString())
|
2022-04-04 02:54:31 +08:00
|
|
|
break;
|
2022-04-09 22:57:06 +08:00
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'TW':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('week').toISOString(), dayjs().endOf('week').toISOString())
|
|
|
|
break;
|
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'LW':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('week').subtract(1, 'week').toISOString(), dayjs().endOf('week').subtract(1, 'week').toISOString())
|
|
|
|
break;
|
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'TM':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('month').toISOString(), dayjs().endOf('month').toISOString())
|
|
|
|
break;
|
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'LM':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('month').subtract(1, 'month').toISOString(), dayjs().endOf('month').subtract(1, 'month').toISOString())
|
|
|
|
break;
|
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'TQ':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('quarter').toISOString(), dayjs().endOf('quarter').toISOString())
|
|
|
|
break;
|
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'LQ':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('quarter').subtract(1, 'quarter').toISOString(), dayjs().endOf('quarter').subtract(1, 'quarter').toISOString())
|
|
|
|
break;
|
|
|
|
|
2022-04-22 03:33:54 +08:00
|
|
|
case 'TY':
|
2022-04-09 22:57:06 +08:00
|
|
|
setFilterRange(dayjs().startOf('year').toISOString(), dayjs().endOf('year').toISOString())
|
|
|
|
break;
|
|
|
|
|
2022-04-04 02:54:31 +08:00
|
|
|
default:
|
2022-04-22 03:33:54 +08:00
|
|
|
alert("Unknown Range Selected")
|
2022-04-04 02:54:31 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-04-09 22:57:06 +08:00
|
|
|
calculateFilterRange(dashboard.value.currentFilter);
|
2022-04-04 02:54:31 +08:00
|
|
|
|
|
|
|
watch(() => dashboard.value.currentFilter, (filter, prev) => {
|
|
|
|
calculateFilterRange(filter);
|
|
|
|
})
|
|
|
|
|
|
|
|
return {
|
2022-04-22 03:33:54 +08:00
|
|
|
dashboard, setShowFilters,
|
2022-04-04 02:54:31 +08:00
|
|
|
setCurrentTab, setCurrentFilter, setFilterRange,
|
2022-04-09 22:57:06 +08:00
|
|
|
getOverViewStats, getResourceStats, getSampleLaggards,
|
|
|
|
getSampleProcessPeformance, getAnalysisProcessPeformance,
|
2022-04-22 03:33:54 +08:00
|
|
|
setCurrentPeformance, setCurrentPeformancePeriod
|
2022-04-04 02:54:31 +08:00
|
|
|
}
|
|
|
|
})
|