Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(my-pages): health vaccination tags & locale #16567

Merged
merged 10 commits into from
Nov 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ export class HealthDirectorateResolver {
name: 'healthDirectorateVaccinations',
})
@Audit()
getVaccinations(@CurrentUser() user: User): Promise<Vaccinations | null> {
return this.api.getVaccinations(user)
getVaccinations(
@Args('locale', { type: () => String, nullable: true })
locale: Locale = 'is',
@CurrentUser() user: User,
): Promise<Vaccinations | null> {
return this.api.getVaccinations(user, locale)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { Auth } from '@island.is/auth-nest-tools'
import type { Locale } from '@island.is/shared/types'
import { Donor, DonorInput, Organ } from './models/organ-donation.model'

import { Info, Vaccination, Vaccinations } from './models/vaccinations.model'
import { Vaccination, Vaccinations } from './models/vaccinations.model'
import { mapVaccinationStatus } from './utils/mappers'

@Injectable()
export class HealthDirectorateService {
Expand Down Expand Up @@ -72,19 +73,26 @@ export class HealthDirectorateService {
}

/* Vaccinations */
async getVaccinations(auth: Auth): Promise<Vaccinations | null> {
const data = await this.vaccinationApi.getVaccinationDiseaseDetail(auth)
async getVaccinations(
auth: Auth,
locale: Locale,
): Promise<Vaccinations | null> {
const data = await this.vaccinationApi.getVaccinationDiseaseDetail(
auth,
locale === 'is' ? 'is' : 'en',
)
if (data === null) {
return null
}

const vaccinations: Array<Vaccination> =
data?.map((item) => {
return {
id: item.diseaseId,
name: item.diseaseName,
description: item.diseaseDescription,
isFeatured: item.isFeatured,
status: item.vaccinationStatus,
status: mapVaccinationStatus(item.vaccinationStatus),
statusName: item.vaccinationStatusName,
statusColor: item.vaccinationStatusColor,
lastVaccinationDate: item.lastVaccinationDate ?? null,
Expand Down
15 changes: 15 additions & 0 deletions libs/api/domains/health-directorate/src/lib/models/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { registerEnumType } from '@nestjs/graphql'

export enum VaccinationStatusEnum {
valid = 'valid', // mint
expired = 'expired', // blue
complete = 'complete', // mint
incomplete = 'incomplete', // blue
undocumented = 'undocumented', // purple
unvaccinated = 'unvaccinated', // red
rejected = 'rejected', // purple
undetermined = 'undetermined', // purple
disaerna marked this conversation as resolved.
Show resolved Hide resolved
}
registerEnumType(VaccinationStatusEnum, {
name: 'HealthDirectorateVaccinationStatusEnum',
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DiseaseVaccinationDtoVaccinationStatusEnum } from '@island.is/clients/health-directorate'
import { Field, Int, ObjectType, registerEnumType } from '@nestjs/graphql'
import { VaccinationStatusEnum } from './enums'

registerEnumType(DiseaseVaccinationDtoVaccinationStatusEnum, {
name: 'HealthDirectorateVaccinationsStatus',
Expand Down Expand Up @@ -55,8 +56,8 @@ export class Vaccination {
@Field(() => Boolean, { nullable: true })
isFeatured?: boolean

@Field({ nullable: true })
status?: string
@Field(() => VaccinationStatusEnum, { nullable: true })
status?: VaccinationStatusEnum

@Field({ nullable: true })
statusName?: string
Expand Down
27 changes: 27 additions & 0 deletions libs/api/domains/health-directorate/src/lib/utils/mappers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { DiseaseVaccinationDtoVaccinationStatusEnum } from '@island.is/clients/health-directorate'
import { VaccinationStatusEnum } from '../models/enums'

export const mapVaccinationStatus = (
status?: DiseaseVaccinationDtoVaccinationStatusEnum,
): VaccinationStatusEnum => {
switch (status) {
case DiseaseVaccinationDtoVaccinationStatusEnum.Valid:
return VaccinationStatusEnum.valid
case DiseaseVaccinationDtoVaccinationStatusEnum.Complete:
return VaccinationStatusEnum.complete
case DiseaseVaccinationDtoVaccinationStatusEnum.Expired:
return VaccinationStatusEnum.expired
case DiseaseVaccinationDtoVaccinationStatusEnum.Incomplete:
return VaccinationStatusEnum.incomplete
case DiseaseVaccinationDtoVaccinationStatusEnum.Rejected:
return VaccinationStatusEnum.rejected
case DiseaseVaccinationDtoVaccinationStatusEnum.Undetermined:
return VaccinationStatusEnum.undetermined
case DiseaseVaccinationDtoVaccinationStatusEnum.Undocumented:
return VaccinationStatusEnum.undocumented
case DiseaseVaccinationDtoVaccinationStatusEnum.Unvaccinated:
return VaccinationStatusEnum.unvaccinated
default:
return VaccinationStatusEnum.undetermined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@
"get": {
"operationId": "MeVaccinationController_getVaccinationsForDiseases",
"description": "Get overview of vaccinations for a user",
"parameters": [],
"parameters": [
{
"name": "locale",
"required": false,
"in": "query",
"schema": { "enum": ["en", "is"], "type": "string" }
}
],
"responses": {
"200": {
"description": "",
Expand Down Expand Up @@ -120,6 +127,12 @@
"in": "path",
"description": "id of the disease",
"schema": { "type": "string" }
},
{
"name": "locale",
"required": false,
"in": "query",
"schema": { "enum": ["en", "is"], "type": "string" }
}
],
"responses": {
Expand Down Expand Up @@ -877,6 +890,10 @@
"description": { "type": "string" },
"isFeatured": { "type": "boolean" },
"isVisible": { "type": "boolean" },
"vaccines": {
"type": "array",
"items": { "$ref": "#/components/schemas/VaccineDiseaseDto" }
},
"rules": {
"type": "array",
"items": { "$ref": "#/components/schemas/DiseaseRuleDto" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { handle404 } from '@island.is/clients/middlewares'
import { Inject, Injectable } from '@nestjs/common'
import {
DiseaseVaccinationDto,
MeVaccinationControllerGetVaccinationsForDiseasesLocaleEnum,
MeVaccinationsApi,
VaccinationDto,
} from './gen/fetch'
Expand All @@ -29,7 +30,7 @@ export class HealthDirectorateVaccinationsService {
.catch(handle404)

if (!vaccines) {
this.logger.warn('No vaccines returned', {
this.logger.debug('No vaccines returned', {
category: LOG_CATEGORY,
})
return null
Expand All @@ -40,13 +41,19 @@ export class HealthDirectorateVaccinationsService {

public async getVaccinationDiseaseDetail(
auth: Auth,
locale: string,
): Promise<Array<DiseaseVaccinationDto> | null> {
const disease = await this.vaccinationsApiWithAuth(auth)
.meVaccinationControllerGetVaccinationsForDiseases()
.meVaccinationControllerGetVaccinationsForDiseases({
locale:
locale === 'is'
? MeVaccinationControllerGetVaccinationsForDiseasesLocaleEnum.Is
: MeVaccinationControllerGetVaccinationsForDiseasesLocaleEnum.En,
})
.catch(handle404)

if (!disease) {
this.logger.warn('No vaccines diseases returned', {
this.logger.debug('No vaccines diseases returned', {
category: LOG_CATEGORY,
})
return null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
query getVaccinations {
healthDirectorateVaccinations {
query getVaccinations($locale: String) {
healthDirectorateVaccinations(locale: $locale) {
vaccinations {
id
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ import { Problem } from '@island.is/react-spa/shared'

export const VaccinationsWrapper = () => {
useNamespaces('sp.health')
const { formatMessage } = useLocale()
const { data, loading, error } = useGetVaccinationsQuery()
const { formatMessage, locale } = useLocale()
const { data, loading, error } = useGetVaccinationsQuery({
variables: {
locale: locale,
},
})

const vaccinations = data?.healthDirectorateVaccinations.vaccinations

Expand Down
Loading
Loading