Skip to content

Commit

Permalink
Add age division statistics queries, UI and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkrepo committed Jan 17, 2025
1 parent 6d99790 commit 07e886d
Show file tree
Hide file tree
Showing 8 changed files with 937 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import range from 'lodash/range'
import React, { useMemo, useState } from 'react'

import { useTranslation } from 'employee-frontend/state/i18n'
import { RegionalSurveyReportResult } from 'lib-common/generated/api-types/reports'
import {
RegionalSurveyReportAgeStatisticsResult,
RegionalSurveyReportResult
} from 'lib-common/generated/api-types/reports'
import LocalDate from 'lib-common/local-date'
import { constantQuery, useQueryResult } from 'lib-common/query'
import Title from 'lib-components/atoms/Title'
import { Button } from 'lib-components/atoms/buttons/Button'
import ReturnButton from 'lib-components/atoms/buttons/ReturnButton'
import Combobox from 'lib-components/atoms/dropdowns/Combobox'
import Container, { ContentArea } from 'lib-components/layout/Container'
import {
FixedSpaceColumn,
FixedSpaceRow
} from 'lib-components/layout/flex-helpers'
import { FixedSpaceRow } from 'lib-components/layout/flex-helpers'
import { H2, Label } from 'lib-components/typography'
import { Gap } from 'lib-components/white-space'

Expand All @@ -27,7 +27,10 @@ import { FlexRow } from '../common/styled/containers'

import ReportDownload from './ReportDownload'
import { FilterLabel, FilterRow } from './common'
import { tampereRegionalSurveyReport } from './queries'
import {
tampereRegionalSurveyAgeReport,
tampereRegionalSurveyMonthlyReport
} from './queries'

interface ReportQueryParams {
year: number
Expand All @@ -52,15 +55,26 @@ export default React.memo(function TampereRegionalSurveyReport() {
null
)

const emptyValue: RegionalSurveyReportResult = {
const emptyMonthlyValue: RegionalSurveyReportResult = {
monthlyCounts: [],
year: 0
}

const reportResult = useQueryResult(
const emptyAgeValue: RegionalSurveyReportAgeStatisticsResult = {
ageStatistics: [],
year: 0
}

const monthlyStatisticsResult = useQueryResult(
activeParams
? tampereRegionalSurveyMonthlyReport(activeParams)
: constantQuery(emptyMonthlyValue)
)

const ageStatisticsResult = useQueryResult(
activeParams
? tampereRegionalSurveyReport(activeParams)
: constantQuery(emptyValue)
? tampereRegionalSurveyAgeReport(activeParams)
: constantQuery(emptyAgeValue)
)

const fetchResults = () => {
Expand All @@ -71,16 +85,17 @@ export default React.memo(function TampereRegionalSurveyReport() {
}
}

const sortedReportResult = useMemo(
const sortedMonthlyReportResult = useMemo(
() =>
reportResult.map((result) => {
monthlyStatisticsResult.map((result) => {
return {
year: result.year,
monthlyCounts: orderBy(result.monthlyCounts, [(r) => r.month])
}
}),
[reportResult]
[monthlyStatisticsResult]
)

return (
<Container>
<ReturnButton label={i18n.common.goBack} />
Expand Down Expand Up @@ -109,58 +124,123 @@ export default React.memo(function TampereRegionalSurveyReport() {
/>
</FilterRow>
<Gap size="m" />

{renderResult(sortedReportResult, (result) => {
{activeParams && <H2>{`${t.reportLabel} ${activeParams.year}`}</H2>}
<Gap size="m" />
{renderResult(sortedMonthlyReportResult, (result) => {
return result.monthlyCounts.length > 0 &&
result.year === selectedYear ? (
<FixedSpaceColumn spacing="L">
<H2>{`${t.reportLabel} ${result.year}`}</H2>
<FixedSpaceRow spacing="L">
<Label>{t.monthlyReport}</Label>
<ReportDownload
data={result.monthlyCounts.map((row) => ({
...row,
month: i18n.common.datetime.months[row.month - 1] ?? ''
}))}
headers={[
{ label: t.monthlyColumns.month, key: 'month' },
{
label: t.monthlyColumns.municipalOver3FullTimeCount,
key: 'municipalOver3FullTimeCount'
},
{
label: t.monthlyColumns.municipalOver3PartTimeCount,
key: 'municipalOver3PartTimeCount'
},
{
label: t.monthlyColumns.municipalUnder3FullTimeCount,
key: 'municipalUnder3FullTimeCount'
},
{
label: t.monthlyColumns.municipalUnder3PartTimeCount,
key: 'municipalUnder3PartTimeCount'
},
{
label: t.monthlyColumns.familyOver3Count,
key: 'familyOver3Count'
},
{
label: t.monthlyColumns.familyUnder3Count,
key: 'familyUnder3Count'
},
{
label: t.monthlyColumns.municipalShiftCareCount,
key: 'municipalShiftCareCount'
},
{
label: t.monthlyColumns.assistanceCount,
key: 'assistanceCount'
}
]}
filename={`${t.reportLabel} ${selectedYear} - ${t.monthlyReport}.csv`}
/>
</FixedSpaceRow>
</FixedSpaceColumn>
<FixedSpaceRow spacing="L">
<Label>{t.monthlyReport}</Label>
<ReportDownload
data={result.monthlyCounts.map((row) => ({
...row,
month: i18n.common.datetime.months[row.month - 1] ?? ''
}))}
headers={[
{ label: t.monthlyColumns.month, key: 'month' },
{
label: t.monthlyColumns.municipalOver3FullTimeCount,
key: 'municipalOver3FullTimeCount'
},
{
label: t.monthlyColumns.municipalOver3PartTimeCount,
key: 'municipalOver3PartTimeCount'
},
{
label: t.monthlyColumns.municipalUnder3FullTimeCount,
key: 'municipalUnder3FullTimeCount'
},
{
label: t.monthlyColumns.municipalUnder3PartTimeCount,
key: 'municipalUnder3PartTimeCount'
},
{
label: t.monthlyColumns.familyOver3Count,
key: 'familyOver3Count'
},
{
label: t.monthlyColumns.familyUnder3Count,
key: 'familyUnder3Count'
},
{
label: t.monthlyColumns.municipalShiftCareCount,
key: 'municipalShiftCareCount'
},
{
label: t.monthlyColumns.assistanceCount,
key: 'assistanceCount'
}
]}
filename={`${t.reportLabel} ${selectedYear} - ${t.monthlyReport}.csv`}
/>
</FixedSpaceRow>
) : null
})}

{renderResult(ageStatisticsResult, (result) => {
return result.ageStatistics.length > 0 &&
result.year === selectedYear ? (
<FixedSpaceRow spacing="L">
<Label>{t.ageStatisticsReport}</Label>
<ReportDownload
data={result.ageStatistics}
headers={[
{
label: t.ageStatisticColumns.voucherUnder3Count,
key: 'voucherUnder3Count'
},
{
label: t.ageStatisticColumns.voucherOver3Count,
key: 'voucherOver3Count'
},
{
label: t.ageStatisticColumns.purchasedUnder3Count,
key: 'purchasedUnder3Count'
},
{
label: t.ageStatisticColumns.purchasedOver3Count,
key: 'purchasedOver3Count'
},
{
label: t.ageStatisticColumns.clubUnder3Count,
key: 'clubUnder3Count'
},
{
label: t.ageStatisticColumns.clubOver3Count,
key: 'clubOver3Count'
},
{
label: t.ageStatisticColumns.nonNativeLanguageUnder3Count,
key: 'nonNativeLanguageUnder3Count'
},
{
label: t.ageStatisticColumns.nonNativeLanguageOver3Count,
key: 'nonNativeLanguageOver3Count'
},
{
label: t.ageStatisticColumns.effectiveCareDaysUnder3Count,
key: 'effectiveCareDaysUnder3Count'
},
{
label: t.ageStatisticColumns.effectiveCareDaysOver3Count,
key: 'effectiveCareDaysOver3Count'
},
{
label:
t.ageStatisticColumns
.effectiveFamilyDaycareDaysUnder3Count,
key: 'effectiveFamilyDaycareDaysUnder3Count'
},
{
label:
t.ageStatisticColumns
.effectiveFamilyDaycareDaysOver3Count,
key: 'effectiveFamilyDaycareDaysOver3Count'
}
]}
filename={`${t.reportLabel} ${selectedYear} - ${t.ageStatisticsReport}.csv`}
/>
</FixedSpaceRow>
) : null
})}
</ContentArea>
Expand Down
11 changes: 9 additions & 2 deletions frontend/src/employee-frontend/components/reports/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import {
getPreschoolApplicationReport,
getServiceVoucherReportForAllUnits,
getStartingPlacementsReport,
getTampereRegionalSurvey,
getTampereRegionalSurveyAgeStatistics,
getTampereRegionalSurveyMonthlyStatistics,
getTitaniaErrorsReport,
getUnitsReport,
getVardaChildErrorsReport,
Expand Down Expand Up @@ -144,4 +145,10 @@ export const startingPlacementsReportQuery = q.query(
getStartingPlacementsReport
)

export const tampereRegionalSurveyReport = q.query(getTampereRegionalSurvey)
export const tampereRegionalSurveyMonthlyReport = q.query(
getTampereRegionalSurveyMonthlyStatistics
)

export const tampereRegionalSurveyAgeReport = q.query(
getTampereRegionalSurveyAgeStatistics
)
27 changes: 24 additions & 3 deletions frontend/src/employee-frontend/generated/api-clients/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { PreschoolUnitsReportRow } from 'lib-common/generated/api-types/reports'
import { PresenceReportRow } from 'lib-common/generated/api-types/reports'
import { ProviderType } from 'lib-common/generated/api-types/daycare'
import { RawReportRow } from 'lib-common/generated/api-types/reports'
import { RegionalSurveyReportAgeStatisticsResult } from 'lib-common/generated/api-types/reports'
import { RegionalSurveyReportResult } from 'lib-common/generated/api-types/reports'
import { Report } from 'lib-common/generated/api-types/reports'
import { ServiceNeedReportRow } from 'lib-common/generated/api-types/reports'
Expand Down Expand Up @@ -1061,9 +1062,29 @@ export async function getStartingPlacementsReport(


/**
* Generated from fi.espoo.evaka.reports.TampereRegionalSurvey.getTampereRegionalSurvey
* Generated from fi.espoo.evaka.reports.TampereRegionalSurvey.getTampereRegionalSurveyAgeStatistics
*/
export async function getTampereRegionalSurvey(
export async function getTampereRegionalSurveyAgeStatistics(
request: {
year: number
}
): Promise<RegionalSurveyReportAgeStatisticsResult> {
const params = createUrlSearchParams(
['year', request.year.toString()]
)
const { data: json } = await client.request<JsonOf<RegionalSurveyReportAgeStatisticsResult>>({
url: uri`/employee/reports/tampere-regional-survey/age-statistics`.toString(),
method: 'GET',
params
})
return json
}


/**
* Generated from fi.espoo.evaka.reports.TampereRegionalSurvey.getTampereRegionalSurveyMonthlyStatistics
*/
export async function getTampereRegionalSurveyMonthlyStatistics(
request: {
year: number
}
Expand All @@ -1072,7 +1093,7 @@ export async function getTampereRegionalSurvey(
['year', request.year.toString()]
)
const { data: json } = await client.request<JsonOf<RegionalSurveyReportResult>>({
url: uri`/employee/reports/tampere-regional-survey/monthly`.toString(),
url: uri`/employee/reports/tampere-regional-survey/monthly-statistics`.toString(),
method: 'GET',
params
})
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/lib-common/generated/api-types/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@ import { TitaniaErrorsId } from './shared'
import { UUID } from '../../types'
import { VoucherValueDecisionId } from './shared'

/**
* Generated from fi.espoo.evaka.reports.TampereRegionalSurvey.AgeStatisticsResult
*/
export interface AgeStatisticsResult {
clubOver3Count: number
clubUnder3Count: number
effectiveCareDaysOver3Count: number
effectiveCareDaysUnder3Count: number
effectiveFamilyDaycareDaysOver3Count: number
effectiveFamilyDaycareDaysUnder3Count: number
nonNativeLanguageOver3Count: number
nonNativeLanguageUnder3Count: number
purchasedOver3Count: number
purchasedUnder3Count: number
voucherOver3Count: number
voucherUnder3Count: number
}

/**
* Generated from fi.espoo.evaka.reports.ApplicationsReportRow
*/
Expand Down Expand Up @@ -822,6 +840,14 @@ export interface ReferenceCount {
table: string
}

/**
* Generated from fi.espoo.evaka.reports.TampereRegionalSurvey.RegionalSurveyReportAgeStatisticsResult
*/
export interface RegionalSurveyReportAgeStatisticsResult {
ageStatistics: AgeStatisticsResult[]
year: number
}

/**
* Generated from fi.espoo.evaka.reports.TampereRegionalSurvey.RegionalSurveyReportMonthlyStatistics
*/
Expand Down
Loading

0 comments on commit 07e886d

Please sign in to comment.