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): my pages & app fix for health #16873

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import { HealthDirectorateClientModule } from '@island.is/clients/health-directo
import { Module } from '@nestjs/common'
import { HealthDirectorateResolver } from './health-directorate.resolver'
import { HealthDirectorateService } from './health-directorate.service'
import { FeatureFlagModule } from '@island.is/nest/feature-flags'

@Module({
imports: [HealthDirectorateClientModule],
imports: [HealthDirectorateClientModule, FeatureFlagModule],
providers: [HealthDirectorateResolver, HealthDirectorateService],
})
export class HealthDirectorateModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ import { DonorInput, Organ, OrganDonation } from './models/organ-donation.model'
import type { Locale } from '@island.is/shared/types'
import { Vaccinations } from './models/vaccinations.model'
import { HealthDirectorateService } from './health-directorate.service'

@UseGuards(IdsUserGuard, ScopesGuard)
@Scopes(ApiScope.internal)
import {
FeatureFlag,
FeatureFlagGuard,
Features,
} from '@island.is/nest/feature-flags'
@UseGuards(IdsUserGuard, ScopesGuard, FeatureFlagGuard)
@Audit({ namespace: '@island.is/api/health-directorate' })
@Resolver(() => OrganDonation)
export class HealthDirectorateResolver {
Expand All @@ -35,6 +38,8 @@ export class HealthDirectorateResolver {
name: 'healthDirectorateOrganDonation',
})
@Audit()
@Scopes(ApiScope.healthOrganDonation)
@FeatureFlag(Features.servicePortalHealthOrganDonationPageEnabled)
async getDonorStatus(
@Args('locale', { type: () => String, nullable: true })
locale: Locale = 'is',
Expand All @@ -43,6 +48,7 @@ export class HealthDirectorateResolver {
const data = await this.api.getDonorStatus(user, locale)
return { donor: data, locale: locale }
}

@ResolveField('organList', () => [Organ], {
nullable: true,
})
Expand All @@ -58,6 +64,8 @@ export class HealthDirectorateResolver {
name: 'healthDirectorateOrganDonationUpdateDonorStatus',
})
@Audit()
@Scopes(ApiScope.healthOrganDonation)
@FeatureFlag(Features.servicePortalHealthOrganDonationPageEnabled)
async updateDonorStatus(
@Args('input') input: DonorInput,
@Args('locale', { type: () => String, nullable: true })
Expand All @@ -72,7 +80,13 @@ export class HealthDirectorateResolver {
name: 'healthDirectorateVaccinations',
})
@Audit()
getVaccinations(@CurrentUser() user: User): Promise<Vaccinations | null> {
return this.api.getVaccinations(user)
@Scopes(ApiScope.healthVaccinations)
@FeatureFlag(Features.servicePortalHealthVaccinationsPageEnabled)
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
}
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
3 changes: 2 additions & 1 deletion libs/feature-flags/src/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export enum Features {
servicePortalVehicleBulkMileagePageEnabled = 'isServicePortalVehicleBulkMileagePageEnabled',
servicePortalSocialInsurancePageEnabled = 'isServicePortalSocialInsurancePageEnabled',
servicePortalSocialInsuranceIncomePlanPageEnabled = 'isServicePortalSocialInsuranceIncomePlanPageEnabled',

servicePortalHealthVaccinationsPageEnabled = 'isServicePortalHealthVaccinationsPageEnabled',
servicePortalHealthOrganDonationPageEnabled = 'isServicePortalHealthOrganDonationPageEnabled',
ServicePortalNotificationsEnabled = 'isServicePortalNotificationsPageEnabled',
servicePortalLawAndOrderModuleEnabled = 'isServicePortalLawAndOrderModuleEnabled',
servicePortalDocumentsActionsEnabled = 'isServicePortalDocumentsActionsEnabled',
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