From 43e0c8544a4145275e1f72a585ede8a4b3478533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Fran=C3=A7a?= Date: Mon, 1 Dec 2025 15:29:21 -0300 Subject: [PATCH 01/10] feat(statistics): add schemas for patients by state statistics --- src/domain/schemas/statistics.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/domain/schemas/statistics.ts b/src/domain/schemas/statistics.ts index d9473c4..0c983fc 100644 --- a/src/domain/schemas/statistics.ts +++ b/src/domain/schemas/statistics.ts @@ -1,12 +1,14 @@ import { z } from 'zod'; +import { BRAZILIAN_STATES } from '@/constants/brazilian-states'; + import { baseResponseSchema } from './base'; import { GENDERS } from './patient'; import { baseQuerySchema } from './query'; // Patients -export const PATIENTS_STATISTIC_FIELDS = ['gender', 'city'] as const; +export const PATIENTS_STATISTIC_FIELDS = ['gender', 'city', 'state'] as const; export type PatientsStatisticFieldType = (typeof PATIENTS_STATISTIC_FIELDS)[number]; @@ -64,3 +66,22 @@ export const getPatientsByCityResponseSchema = baseResponseSchema.extend({ export type GetPatientsByCityResponse = z.infer< typeof getPatientsByCityResponseSchema >; + +export const patientsByStateSchema = z + .object({ + state: z.enum(BRAZILIAN_STATES), + total: z.number(), + percentage: z.number(), + }) + .strict(); +export type PatientsByStateType = z.infer; + +export const getPatientsByStateResponseSchema = baseResponseSchema.extend({ + data: z.object({ + states: z.array(patientsByStateSchema), + total: z.number(), + }), +}); +export type GetPatientsByStateResponse = z.infer< + typeof getPatientsByStateResponseSchema +>; From 7ef7b422be5bf81c9ff3960a7dfd0da110061cc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Fran=C3=A7a?= Date: Mon, 1 Dec 2025 15:30:08 -0300 Subject: [PATCH 02/10] feat(statistics): create DTO for patients by state endpoint --- src/app/http/statistics/statistics.dtos.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/app/http/statistics/statistics.dtos.ts b/src/app/http/statistics/statistics.dtos.ts index c66b083..7a906c8 100644 --- a/src/app/http/statistics/statistics.dtos.ts +++ b/src/app/http/statistics/statistics.dtos.ts @@ -5,3 +5,5 @@ import { getPatientsByPeriodSchema } from '@/domain/schemas/statistics'; export class GetPatientsByPeriodDto extends createZodDto( getPatientsByPeriodSchema, ) {} + +export class GetPatientsByStateDto extends GetPatientsByPeriodDto {} From 8fa28ffbead44cc677f8ef816ffaaf349576d461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Fran=C3=A7a?= Date: Mon, 1 Dec 2025 15:30:48 -0300 Subject: [PATCH 03/10] fix(query): add last_30_days to period enum validation --- src/domain/schemas/query.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/domain/schemas/query.ts b/src/domain/schemas/query.ts index 9619ae3..630151c 100644 --- a/src/domain/schemas/query.ts +++ b/src/domain/schemas/query.ts @@ -3,7 +3,12 @@ import { z } from 'zod'; export const ORDER = ['ASC', 'DESC'] as const; export type OrderType = (typeof ORDER)[number]; -export const PERIOD = ['last-year', 'last-month', 'last-week'] as const; +export const PERIOD = [ + 'last-year', + 'last-month', + 'last-week', + 'last_30_days', +] as const; export type PeriodType = (typeof PERIOD)[number]; export const baseQuerySchema = z.object({ From a762c18b07509bcd9abb8473347b849c81469d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Fran=C3=A7a?= Date: Mon, 1 Dec 2025 15:31:26 -0300 Subject: [PATCH 04/10] feat(utils): add last_30_days period handling in date range calculation --- src/utils/utils.service.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/utils.service.ts b/src/utils/utils.service.ts index 6fac3cd..751962e 100644 --- a/src/utils/utils.service.ts +++ b/src/utils/utils.service.ts @@ -69,6 +69,10 @@ export class UtilsService { startDate: startOfYear(today), endDate: today, }, + last_30_days: { + startDate: new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000), + endDate: today, + }, }; return periodMapper[period]; From 69971adb967f8f36bd95850742954b1be6896e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Fran=C3=A7a?= Date: Mon, 1 Dec 2025 15:32:07 -0300 Subject: [PATCH 05/10] feat(statistics): implement service method for patients by state statistics --- src/app/http/statistics/statistics.service.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/app/http/statistics/statistics.service.ts b/src/app/http/statistics/statistics.service.ts index 4798dff..e68e597 100644 --- a/src/app/http/statistics/statistics.service.ts +++ b/src/app/http/statistics/statistics.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import type { GetPatientsTotalResponseSchema, + PatientsByStateType, PatientsStatisticFieldType, } from '@/domain/schemas/statistics'; import { UtilsService } from '@/utils/utils.service'; @@ -35,4 +36,17 @@ export class StatisticsService { query, ); } + + async getPatientsByState( + query: GetPatientsByPeriodDto, + ): Promise<{ items: PatientsByStateType[]; total: number }> { + const { startDate, endDate } = this.utilsService.getDateRangeForPeriod( + query.period, + ); + return await this.patientsRepository.getPatientsByState( + startDate, + endDate, + query, + ); + } } From 7e5bafb81fb71891d8a9528400765f3c3445c8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Fran=C3=A7a?= Date: Mon, 1 Dec 2025 15:32:53 -0300 Subject: [PATCH 06/10] feat(repository): add getPatientsByState method with referral filtering --- src/app/http/patients/patients.repository.ts | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/app/http/patients/patients.repository.ts b/src/app/http/patients/patients.repository.ts index f02a6b2..3acb61c 100644 --- a/src/app/http/patients/patients.repository.ts +++ b/src/app/http/patients/patients.repository.ts @@ -6,6 +6,7 @@ import { Patient } from '@/domain/entities/patient'; import type { PatientOrderByType, PatientType } from '@/domain/schemas/patient'; import type { GetPatientsTotalResponseSchema, + PatientsByStateType, PatientsStatisticFieldType, } from '@/domain/schemas/statistics'; @@ -228,4 +229,52 @@ export class PatientsRepository { return { items, total }; } + + public async getPatientsByState( + startDate: Date, + endDate: Date, + query: GetPatientsByPeriodDto, + ): Promise<{ items: PatientsByStateType[]; total: number }> { + const totalQuery = this.patientsRepository + .createQueryBuilder('patient') + .select(`COUNT(DISTINCT patient.id)`, 'total') + .innerJoin('patient.referrals', 'referral') + .where('patient.created_at BETWEEN :start AND :end', { + start: startDate, + end: endDate, + }) + .andWhere('referral.referred_to IS NOT NULL') + .andWhere('referral.referred_to != :empty', { empty: '' }); + + const totalResult = await totalQuery.getRawOne<{ total: string }>(); + const total = Number(totalResult?.total ?? 0); + + const queryBuilder = this.patientsRepository + .createQueryBuilder('patient') + .select('patient.state', 'state') + .addSelect('COUNT(DISTINCT patient.id)', 'total') + .innerJoin('patient.referrals', 'referral') + .where('patient.created_at BETWEEN :start AND :end', { + start: startDate, + end: endDate, + }) + .andWhere('referral.referred_to IS NOT NULL') + .andWhere('referral.referred_to != :empty', { empty: '' }) + .groupBy('patient.state') + .orderBy('total', query.order) + .limit(query.limit); + + if (query.withPercentage) { + queryBuilder + .addSelect( + 'ROUND((COUNT(DISTINCT patient.id) * 100.0 / (:total)), 1)', + 'percentage', + ) + .setParameter('total', total > 0 ? total : 1); + } + + const items = await queryBuilder.getRawMany(); + + return { items, total }; + } } From bcb6f8b3031943aa311c4a0ae53c470cc230d8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Fran=C3=A7a?= Date: Mon, 1 Dec 2025 15:33:34 -0300 Subject: [PATCH 07/10] feat(controller): add endpoint for patients by state statistics --- .../http/statistics/statistics.controller.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/app/http/statistics/statistics.controller.ts b/src/app/http/statistics/statistics.controller.ts index 4ef8a8e..d54629c 100644 --- a/src/app/http/statistics/statistics.controller.ts +++ b/src/app/http/statistics/statistics.controller.ts @@ -5,6 +5,7 @@ import { Roles } from '@/common/decorators/roles.decorator'; import type { GetPatientsByCityResponse, GetPatientsByGenderResponse, + GetPatientsByStateResponse, PatientsByCityType, PatientsByGenderType, } from '@/domain/schemas/statistics'; @@ -67,4 +68,22 @@ export class StatisticsController { data: { cities, total }, }; } + @Get('patients-by-state') + @Roles(['manager', 'nurse']) + @ApiOperation({ + summary: + 'Estatísticas de pacientes por estado (comencaminhamentos destinados', + }) + async getPatientsByState( + @Query() query: GetPatientsByPeriodDto, + ): Promise { + const { items: states, total } = + await this.statisticsService.getPatientsByState(query); + + return { + success: true, + message: 'Estatísticas de pacientes por estado retornada com sucesso.', + data: { states, total }, + }; + } } From 77d60d916bf2a52c1232e5cc5ede23a124cd8a65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Fran=C3=A7a?= Date: Thu, 4 Dec 2025 11:16:18 -0300 Subject: [PATCH 08/10] fix(statistics): rename referral method and update period mapping --- src/app/http/patients/patients.repository.ts | 2 +- src/app/http/statistics/statistics.controller.ts | 4 ++-- src/app/http/statistics/statistics.dtos.ts | 2 +- src/app/http/statistics/statistics.service.ts | 4 ++-- src/domain/schemas/query.ts | 2 +- src/utils/utils.service.ts | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/app/http/patients/patients.repository.ts b/src/app/http/patients/patients.repository.ts index 3acb61c..0fb82a5 100644 --- a/src/app/http/patients/patients.repository.ts +++ b/src/app/http/patients/patients.repository.ts @@ -230,7 +230,7 @@ export class PatientsRepository { return { items, total }; } - public async getPatientsByState( + public async getPatientsWithReferralsByState( startDate: Date, endDate: Date, query: GetPatientsByPeriodDto, diff --git a/src/app/http/statistics/statistics.controller.ts b/src/app/http/statistics/statistics.controller.ts index d54629c..e9c1829 100644 --- a/src/app/http/statistics/statistics.controller.ts +++ b/src/app/http/statistics/statistics.controller.ts @@ -74,11 +74,11 @@ export class StatisticsController { summary: 'Estatísticas de pacientes por estado (comencaminhamentos destinados', }) - async getPatientsByState( + async getPatientsWithReferralsByState( @Query() query: GetPatientsByPeriodDto, ): Promise { const { items: states, total } = - await this.statisticsService.getPatientsByState(query); + await this.statisticsService.getReferredPatientsByState(query); return { success: true, diff --git a/src/app/http/statistics/statistics.dtos.ts b/src/app/http/statistics/statistics.dtos.ts index 7a906c8..071837f 100644 --- a/src/app/http/statistics/statistics.dtos.ts +++ b/src/app/http/statistics/statistics.dtos.ts @@ -6,4 +6,4 @@ export class GetPatientsByPeriodDto extends createZodDto( getPatientsByPeriodSchema, ) {} -export class GetPatientsByStateDto extends GetPatientsByPeriodDto {} +export class GetPatientsWithReferralsByStateDto extends GetPatientsByPeriodDto {} diff --git a/src/app/http/statistics/statistics.service.ts b/src/app/http/statistics/statistics.service.ts index e68e597..3176d33 100644 --- a/src/app/http/statistics/statistics.service.ts +++ b/src/app/http/statistics/statistics.service.ts @@ -37,13 +37,13 @@ export class StatisticsService { ); } - async getPatientsByState( + async getReferredPatientsByState( query: GetPatientsByPeriodDto, ): Promise<{ items: PatientsByStateType[]; total: number }> { const { startDate, endDate } = this.utilsService.getDateRangeForPeriod( query.period, ); - return await this.patientsRepository.getPatientsByState( + return await this.patientsRepository.getPatientsWithReferralsByState( startDate, endDate, query, diff --git a/src/domain/schemas/query.ts b/src/domain/schemas/query.ts index 630151c..db74b82 100644 --- a/src/domain/schemas/query.ts +++ b/src/domain/schemas/query.ts @@ -7,7 +7,7 @@ export const PERIOD = [ 'last-year', 'last-month', 'last-week', - 'last_30_days', + 'today', ] as const; export type PeriodType = (typeof PERIOD)[number]; diff --git a/src/utils/utils.service.ts b/src/utils/utils.service.ts index 751962e..fe0621e 100644 --- a/src/utils/utils.service.ts +++ b/src/utils/utils.service.ts @@ -69,8 +69,8 @@ export class UtilsService { startDate: startOfYear(today), endDate: today, }, - last_30_days: { - startDate: new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000), + today: { + startDate: today, endDate: today, }, }; From 13d9f5d0478d26e8fe0b9c7cf992858cc72b268b Mon Sep 17 00:00:00 2001 From: Juliano Sill Date: Sat, 6 Dec 2025 21:54:38 -0300 Subject: [PATCH 09/10] refactor(patients): reduce duplicated code in `getTotalReferredPatientsByState` method --- src/app/http/patients/patients.repository.ts | 68 +++++++++++--------- 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/src/app/http/patients/patients.repository.ts b/src/app/http/patients/patients.repository.ts index e59da23..23afddf 100644 --- a/src/app/http/patients/patients.repository.ts +++ b/src/app/http/patients/patients.repository.ts @@ -8,6 +8,7 @@ import { MoreThanOrEqual, Not, Repository, + type SelectQueryBuilder, } from 'typeorm'; import { Patient } from '@/domain/entities/patient'; @@ -297,41 +298,48 @@ export class PatientsRepository { ): Promise<{ states: TotalReferredPatientsByState[]; total: number }> { const { startDate, endDate, limit = 10 } = input; - const queryBuilder = this.patientsRepository - .createQueryBuilder('patient') - .select('patient.state', 'state') - .addSelect('COUNT(DISTINCT patient.id)', 'total') - .innerJoin('patient.referrals', 'referral') - .where('referral.referred_to IS NOT NULL') - .andWhere('referral.referred_to != :empty', { empty: '' }) - .groupBy('patient.state') - .orderBy('COUNT(DISTINCT patient.id)', 'DESC') - .limit(limit); - - const totalQueryBuilder = this.patientsRepository - .createQueryBuilder('patient') - .select('COUNT(DISTINCT patient.state)', 'total') - .innerJoin('patient.referrals', 'referral') - .where('referral.referred_to IS NOT NULL') - .andWhere('referral.referred_to != :empty', { empty: '' }); - - if (startDate && endDate) { - queryBuilder.where('referral.date BETWEEN :start AND :end', { - start: startDate, - end: endDate, - }); + const createQueryBuilder = (): SelectQueryBuilder => { + return this.patientsRepository + .createQueryBuilder('patient') + .innerJoin('patient.referrals', 'referral') + .where('referral.referred_to IS NOT NULL') + .andWhere('referral.referred_to != :empty', { empty: '' }); + }; - totalQueryBuilder.andWhere('referral.date BETWEEN :start AND :end', { - start: startDate, - end: endDate, - }); + function getQueryBuilderWithFilters( + queryBuilder: SelectQueryBuilder, + ) { + if (startDate && endDate) { + queryBuilder.andWhere('referral.date BETWEEN :start AND :end', { + start: startDate, + end: endDate, + }); + } + + return queryBuilder; } + const stateListQuery = getQueryBuilderWithFilters( + createQueryBuilder() + .select('patient.state', 'state') + .addSelect('COUNT(DISTINCT patient.id)', 'total') + .groupBy('patient.state') + .orderBy('COUNT(DISTINCT patient.id)', 'DESC') + .limit(limit), + ); + + const totalStatesQuery = getQueryBuilderWithFilters( + createQueryBuilder().select('COUNT(DISTINCT patient.state)', 'total'), + ); + const [states, totalResult] = await Promise.all([ - queryBuilder.getRawMany(), - totalQueryBuilder.getRawOne<{ total: string }>(), + stateListQuery.getRawMany(), + totalStatesQuery.getRawOne<{ total: string }>(), ]); - return { states, total: Number(totalResult?.total || 0) }; + return { + states, + total: Number(totalResult?.total || 0), + }; } } From 63d0478e041bcf71d0e46cf2cad72f08f3491c73 Mon Sep 17 00:00:00 2001 From: Juliano Sill Date: Sat, 6 Dec 2025 22:15:05 -0300 Subject: [PATCH 10/10] chore(patients): rename referred patients methods with to more readable and concise names --- src/app/http/patients/patients.repository.ts | 8 +++---- .../http/statistics/statistics.controller.ts | 14 +++++------ src/app/http/statistics/statistics.dtos.ts | 6 ++--- src/app/http/statistics/statistics.service.ts | 10 ++++---- src/domain/schemas/statistics.ts | 24 ++++++++----------- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/src/app/http/patients/patients.repository.ts b/src/app/http/patients/patients.repository.ts index 23afddf..fffcd60 100644 --- a/src/app/http/patients/patients.repository.ts +++ b/src/app/http/patients/patients.repository.ts @@ -19,7 +19,7 @@ import type { } from '@/domain/schemas/patient'; import type { PatientsStatisticField, - TotalReferredPatientsByState, + StateReferredPatients, } from '@/domain/schemas/statistics'; import type { GetPatientsByPeriodQuery } from '../statistics/statistics.dtos'; @@ -293,9 +293,9 @@ export class PatientsRepository { return await this.patientsRepository.count({ where }); } - public async getTotalReferredPatientsByState( + public async getReferredPatientsByState( input: { startDate?: Date; endDate?: Date; limit?: number } = {}, - ): Promise<{ states: TotalReferredPatientsByState[]; total: number }> { + ): Promise<{ states: StateReferredPatients[]; total: number }> { const { startDate, endDate, limit = 10 } = input; const createQueryBuilder = (): SelectQueryBuilder => { @@ -333,7 +333,7 @@ export class PatientsRepository { ); const [states, totalResult] = await Promise.all([ - stateListQuery.getRawMany(), + stateListQuery.getRawMany(), totalStatesQuery.getRawOne<{ total: string }>(), ]); diff --git a/src/app/http/statistics/statistics.controller.ts b/src/app/http/statistics/statistics.controller.ts index 2fc175a..b0aae11 100644 --- a/src/app/http/statistics/statistics.controller.ts +++ b/src/app/http/statistics/statistics.controller.ts @@ -5,16 +5,16 @@ import { Roles } from '@/common/decorators/roles.decorator'; import type { GetPatientsByCityResponse, GetPatientsByGenderResponse, + GetReferredPatientsByStateResponse, GetTotalReferralsAndReferredPatientsPercentageResponse, - GetTotalReferredPatientsByStateResponse, PatientsByCity, PatientsByGender, } from '@/domain/schemas/statistics'; import { GetPatientsByPeriodQuery, + GetReferredPatientsByStateQuery, GetTotalReferralsAndReferredPatientsPercentageQuery, - GetTotalReferredPatientsByStateQuery, } from './statistics.dtos'; import { StatisticsService } from './statistics.service'; @@ -96,18 +96,18 @@ export class StatisticsController { @Get('referrals-by-state') @Roles(['manager', 'nurse']) @ApiOperation({ - summary: 'Estatísticas de pacientes encaminhados por estado', + summary: 'Lista com o total de pacientes encaminhados por estado', }) - async getPatientsWithReferralsByState( - @Query() query: GetTotalReferredPatientsByStateQuery, - ): Promise { + async getReferredPatientsByState( + @Query() query: GetReferredPatientsByStateQuery, + ): Promise { const { states, total } = await this.statisticsService.getReferredPatientsByState(query); return { success: true, message: - 'Estatísticas de pacientes encaminhados por estado retornada com sucesso.', + 'Lista com o total de pacientes encaminhados por estado retornada com sucesso.', data: { states, total }, }; } diff --git a/src/app/http/statistics/statistics.dtos.ts b/src/app/http/statistics/statistics.dtos.ts index 1c35de9..bd9861e 100644 --- a/src/app/http/statistics/statistics.dtos.ts +++ b/src/app/http/statistics/statistics.dtos.ts @@ -2,8 +2,8 @@ import { createZodDto } from 'nestjs-zod'; import { getPatientsByPeriodQuerySchema, + getReferredPatientsByStateQuerySchema, getTotalReferralsAndReferredPatientsPercentageQuerySchema, - getTotalReferredPatientsByStateQuerySchema, } from '@/domain/schemas/statistics'; export class GetPatientsByPeriodQuery extends createZodDto( @@ -14,6 +14,6 @@ export class GetTotalReferralsAndReferredPatientsPercentageQuery extends createZ getTotalReferralsAndReferredPatientsPercentageQuerySchema, ) {} -export class GetTotalReferredPatientsByStateQuery extends createZodDto( - getTotalReferredPatientsByStateQuerySchema, +export class GetReferredPatientsByStateQuery extends createZodDto( + getReferredPatientsByStateQuerySchema, ) {} diff --git a/src/app/http/statistics/statistics.service.ts b/src/app/http/statistics/statistics.service.ts index 454c0c8..bf63d73 100644 --- a/src/app/http/statistics/statistics.service.ts +++ b/src/app/http/statistics/statistics.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@nestjs/common'; import type { GetTotalPatientsByStatusResponse, PatientsStatisticField, - TotalReferredPatientsByState, + StateReferredPatients, } from '@/domain/schemas/statistics'; import { UtilsService } from '@/utils/utils.service'; @@ -11,8 +11,8 @@ import { PatientsRepository } from '../patients/patients.repository'; import { ReferralsRepository } from '../referrals/referrals.repository'; import type { GetPatientsByPeriodQuery, + GetReferredPatientsByStateQuery, GetTotalReferralsAndReferredPatientsPercentageQuery, - GetTotalReferredPatientsByStateQuery, } from './statistics.dtos'; @Injectable() @@ -70,13 +70,13 @@ export class StatisticsService { } async getReferredPatientsByState( - query: GetTotalReferredPatientsByStateQuery, - ): Promise<{ states: TotalReferredPatientsByState[]; total: number }> { + query: GetReferredPatientsByStateQuery, + ): Promise<{ states: StateReferredPatients[]; total: number }> { const { startDate, endDate } = this.utilsService.getDateRangeForPeriod( query.period, ); - return await this.patientsRepository.getTotalReferredPatientsByState({ + return await this.patientsRepository.getReferredPatientsByState({ startDate, endDate, }); diff --git a/src/domain/schemas/statistics.ts b/src/domain/schemas/statistics.ts index 1544945..f8e4348 100644 --- a/src/domain/schemas/statistics.ts +++ b/src/domain/schemas/statistics.ts @@ -84,27 +84,23 @@ export type GetTotalReferralsAndReferredPatientsPercentageResponse = z.infer< typeof getTotalReferralsAndReferredPatientsPercentageResponseSchema >; -export const getTotalReferredPatientsByStateQuerySchema = baseQuerySchema.pick({ +export const getReferredPatientsByStateQuerySchema = baseQuerySchema.pick({ period: true, }); -export const totalReferredPatientsByStateSchema = z - .object({ - state: z.enum(BRAZILIAN_STATES), - total: z.number(), - }) - .strict(); -export type TotalReferredPatientsByState = z.infer< - typeof totalReferredPatientsByStateSchema ->; +export const stateReferredPatientsSchema = z.object({ + state: z.enum(BRAZILIAN_STATES), + total: z.number(), +}); +export type StateReferredPatients = z.infer; -export const getTotalReferredPatientsByStateResponseSchema = +export const getReferredPatientsByStateResponseSchema = baseResponseSchema.extend({ data: z.object({ - states: z.array(totalReferredPatientsByStateSchema), + states: z.array(stateReferredPatientsSchema), total: z.number(), }), }); -export type GetTotalReferredPatientsByStateResponse = z.infer< - typeof getTotalReferredPatientsByStateResponseSchema +export type GetReferredPatientsByStateResponse = z.infer< + typeof getReferredPatientsByStateResponseSchema >;