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

feat(api): WIP - client addons for health directorate #17421

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
@@ -1,8 +1,8 @@
import { HealthDirectorateClientModule } from '@island.is/clients/health-directorate'
import { FeatureFlagModule } from '@island.is/nest/feature-flags'
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, FeatureFlagModule],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@ import {

import { UseGuards } from '@nestjs/common'

import type { User } from '@island.is/auth-nest-tools'
import {
CurrentUser,
IdsUserGuard,
Scopes,
ScopesGuard,
} from '@island.is/auth-nest-tools'
import type { User } from '@island.is/auth-nest-tools'
import { ApiScope } from '@island.is/auth/scopes'
import { Audit } from '@island.is/nest/audit'
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'
import {
FeatureFlag,
FeatureFlagGuard,
Features,
} from '@island.is/nest/feature-flags'
import type { Locale } from '@island.is/shared/types'
import { HealthDirectorateService } from './health-directorate.service'
import { DonorInput, Organ, OrganDonation } from './models/organ-donation.model'
import { Prescriptions } from './models/prescriptions'
import { Referrals } from './models/referrals.model'
import { Vaccinations } from './models/vaccinations.model'
import { Waitlists } from './models/waitlists.model'
@UseGuards(IdsUserGuard, ScopesGuard, FeatureFlagGuard)
@Audit({ namespace: '@island.is/api/health-directorate' })
@Resolver(() => OrganDonation)
Expand Down Expand Up @@ -89,4 +92,43 @@ export class HealthDirectorateResolver {
): Promise<Vaccinations | null> {
return this.api.getVaccinations(user, locale)
}

/* Waitlists */
@Query(() => Waitlists, {
name: 'healthDirectorateWaitlists',
})
@Audit()
getWaitlists(
@Args('locale', { type: () => String, nullable: true })
locale: Locale = 'is',
@CurrentUser() user: User,
): Promise<Waitlists | null> {
return this.api.getWaitlists(user, locale)
}

/* Referrals */
@Query(() => Referrals, {
name: 'healthDirectorateReferrals',
})
@Audit()
getReferalls(
@Args('locale', { type: () => String, nullable: true })
locale: Locale = 'is',
@CurrentUser() user: User,
): Promise<Referrals | null> {
return this.api.getReferrals(user, locale)
}

/* Prescriptions */
@Query(() => Prescriptions, {
name: 'healthDirectoratePrescriptions',
})
@Audit()
getPrescriptions(
@Args('locale', { type: () => String, nullable: true })
locale: Locale = 'is',
@CurrentUser() user: User,
): Promise<Prescriptions | null> {
return this.api.getPrescriptions(user, locale)
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
import { Injectable } from '@nestjs/common'
import { Auth } from '@island.is/auth-nest-tools'
import {
HealthDirectorateVaccinationsService,
HealthDirectorateOrganDonationService,
HealthDirectorateVaccinationsService,
OrganDonorDto,
VaccinationDto,
organLocale,
} from '@island.is/clients/health-directorate'
import { Auth } from '@island.is/auth-nest-tools'
import type { Locale } from '@island.is/shared/types'
import { Injectable } from '@nestjs/common'
import { Donor, DonorInput, Organ } from './models/organ-donation.model'

import { HealthDirectorateHealthService } from '@island.is/clients/health-directorate'
import { Logger } from '@island.is/logging'
import { Prescription, Prescriptions } from './models/prescriptions'
import { Referral, Referrals } from './models/referrals.model'
import { Vaccination, Vaccinations } from './models/vaccinations.model'
import { mapVaccinationStatus } from './utils/mappers'
import { Waitlist, Waitlists } from './models/waitlists.model'
import {
mapPrescriptionRenewalBlockedReason,
mapPrescriptionRenewalStatus,
mapVaccinationStatus,
} from './utils/mappers'

@Injectable()
export class HealthDirectorateService {
constructor(
private readonly vaccinationApi: HealthDirectorateVaccinationsService,
private readonly organDonationApi: HealthDirectorateOrganDonationService,
private readonly healthApi: HealthDirectorateHealthService,
private readonly logger: Logger,
) {}

/* Organ Donation */
Expand Down Expand Up @@ -91,12 +102,12 @@ export class HealthDirectorateService {
auth,
locale === 'is' ? 'is' : 'en',
)
if (data === null) {
if (!data) {
return null
}

const vaccinations: Array<Vaccination> =
data?.map((item) => {
data.map((item) => {
return {
id: item.diseaseId,
name: item.diseaseName,
Expand All @@ -123,6 +134,132 @@ export class HealthDirectorateService {
),
}
}) ?? []

return { vaccinations }
}

/* Waitlists */
async getWaitlists(auth: Auth, locale: Locale): Promise<Waitlists | null> {
const data = await this.healthApi.getWaitlists(auth, locale)

if (!data) {
return null
}
const waitlists: Array<Waitlist> =
data.map((item) => {
return {
id: item.id,
lastUpdated: item.lastUpdated
? new Date(item.lastUpdated?.toString())
: undefined,
name: item.name,
waitBeganDate: item.waitBeganDate
? new Date(item.waitBeganDate?.toString())
: undefined,
organizationName: item.organizationName.toString(),
statusDisplay: item.statusDisplay?.toString(),
}
}) ?? []

return { waitlists }
}

/* Referrals */
async getReferrals(auth: Auth, locale: Locale): Promise<Referrals | null> {
const data = await this.healthApi.getReferrals(auth, locale)

if (!data) {
return null
}

const referrals: Array<Referral> =
data.map((item) => {
return {
id: item.id,
serviceName: item.serviceName,
createdDate: item.createdDate
? new Date(item.createdDate?.toString())
: undefined,
validUntilDate: item.validUntilDate
? new Date(item.validUntilDate?.toString())
: undefined,
stateDisplay: item.stateDisplay,
reason: item.reasonForReferral,
fromContactInfo: item.fromContactInfo,
toContactInfo: item.toContactInfo,
}
}) ?? []

return { referrals }
}

/* Prescriptions */
async getPrescriptions(
auth: Auth,
locale: Locale,
): Promise<Prescriptions | null> {
const data = await this.healthApi.getPrescriptions(auth, locale)

if (!data) {
return null
}
const prescriptions: Array<Prescription> =
data.map((item) => {
return {
prescribedItemId: item.prescribedItemId.toString(),
prescriptionId: item.prescriptionId,
prescriberId: item.prescriberId,
prescriberName: item.prescriberName.toString(),
issueDate: item.issueDate,
expiryDate: item.expiryDate,
productId: item.productId,
productName: item.productName?.toString(),
productType: item.productType?.toString(),
productForm: item.productForm?.toString(),
productUrl: item.productUrl?.toString(),
productStrength: item.productStrength?.toString(),
productQuantity: item.productQuantity?.toString(),
dosageInstructions: item.dosageInstructions?.toString(),
indication: item.indication?.toString(),
totalPrescribedAmount: item.totalPrescribedAmount?.toString(),
totalPrescribedAmountDisplay:
item.totalPrescribedAmountDisplay?.toString(),
isRegiment: item.isRegiment ? true : false,
isRenewable: item.isRenewable,
renewalBlockedReason: item.renewalBlockedReason
? mapPrescriptionRenewalBlockedReason(item.renewalBlockedReason)
: undefined,
renewalStatus: item.renewalStatus
? mapPrescriptionRenewalStatus(item.renewalStatus)
: undefined,
amountRemaining: item.amountRemaining,
amountRemainingUnit: item.amountRemainingUnit,
amountRemainingDisplay: item.amountRemainingDisplay,
percentageRemaining: item.percentageRemaining,
isFullyDispensed: item.isFullyDispensed,
dispensations: item.dispensations.map((item) => {
return {
id: item.id.toString(),
dispensingAgentId: item.dispensingAgentId.toString(),
dispensingAgentName: item.dispensingAgentName,
dispensationDate: item.dispensationDate,
dispensedItemsCount: item.dispensedItemsCount,
dispensedItems: item.dispensedItems.map((item) => {
return {
productId: item.productId,
productName: item.productName?.toString(),
productStrength: item.productStrength?.toString(),
dispensedAmount: item.dispensedAmount?.toString(),
dispensedAmountDisplay:
item.dispensedAmountDisplay?.toString(),
numberOfPackages: item.numberOfPackages?.toString(),
}
}),
}
}),
}
}) ?? []

return { prescriptions }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Field, ID, ObjectType } from '@nestjs/graphql'

@ObjectType('HealthDirectorateDispensedItem')
export class DispensedItem {
@Field()
productId!: string

@Field({ nullable: true })
productName?: string

@Field({ nullable: true })
productStrength?: string

@Field({ nullable: true })
dispensedAmount?: string

@Field({ nullable: true })
dispensedAmountDisplay?: string

@Field({ nullable: true })
numberOfPackages?: string
}

@ObjectType('HealthDirectorateDispensation')
export class Dispensation {
@Field(() => ID)
id!: string

@Field()
dispensingAgentId!: string

@Field({ nullable: true })
dispensingAgentName?: string

@Field(() => Date)
dispensationDate!: Date

@Field()
dispensedItemsCount!: number

@Field(() => [DispensedItem])
dispensedItems!: DispensedItem[]
}
21 changes: 21 additions & 0 deletions libs/api/domains/health-directorate/src/lib/models/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,24 @@ export enum VaccinationStatusEnum {
registerEnumType(VaccinationStatusEnum, {
name: 'HealthDirectorateVaccinationStatusEnum',
})

export enum PrescribedItemRenewalBlockedReasonEnum {
PendingRequest = 'pendingRequest',
RejectedRequest = 'rejectedRequest',
NotFullyDispensed = 'notFullyDispensed',
IsRegiment = 'isRegiment',
}

registerEnumType(PrescribedItemRenewalBlockedReasonEnum, {
name: 'HealthDirectoratePrescriptionRenewalBlockedReason',
})

export enum PrescribedItemRenewalStatusEnum {
NUMBER_0 = 0,
NUMBER_1 = 1,
NUMBER_2 = 2,
}

registerEnumType(PrescribedItemRenewalStatusEnum, {
name: 'HealthDirectoratePrescriptionRenewalStatus',
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectType, Field, InputType } from '@nestjs/graphql'
import { Field, InputType, ObjectType } from '@nestjs/graphql'

@ObjectType('HealthDirectorateOrganDonationOrgan')
export class Organ {
Expand Down
Loading
Loading