Skip to content

Commit

Permalink
Use engagehf-models package (#41)
Browse files Browse the repository at this point in the history
# Use engagehf-models package

## ♻️ Current situation & Problem
Previously, model types were copied from Firebase repository. This PR
aims to clean this up.

Closes #15

## ✅ Testing
It's a draft, because it relies on features from
StanfordBDHG/ENGAGE-HF-Firebase#128 to work. We
can merge this as
StanfordBDHG/ENGAGE-HF-Firebase#128 gets
released.


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
arkadiuszbachorski authored Sep 15, 2024
1 parent ad11c0a commit 3c4f08a
Show file tree
Hide file tree
Showing 45 changed files with 7,821 additions and 14,065 deletions.
2 changes: 1 addition & 1 deletion modules/firebase/AuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
import { useNavigate } from '@tanstack/react-router'
import { type ReactNode, useEffect } from 'react'
import { auth } from '@/modules/firebase/guards'
import { auth } from '@/modules/firebase/app'
import { routes } from '@/modules/routes'
import { useAuthUser } from '@/packages/design-system/src/modules/auth/hooks'

Expand Down
2 changes: 1 addition & 1 deletion modules/firebase/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// SPDX-License-Identifier: MIT
//
import { queryOptions, useSuspenseQuery } from '@tanstack/react-query'
import { getCurrentUser } from '@/modules/firebase/guards'
import { getCurrentUser } from '@/modules/firebase/app'
import { getUserInfo } from '@/packages/design-system/src/modules/auth/user'

export const currentUserQueryOptions = () =>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion modules/firebase/guards.tsx → modules/firebase/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//
import { initializeApp } from '@firebase/app'
import { connectFunctionsEmulator, getFunctions } from '@firebase/functions'
import { type UserType } from '@stanfordbdhg/engagehf-models'
import { queryOptions } from '@tanstack/react-query'
import { redirect } from '@tanstack/react-router'
import { connectAuthEmulator, getAuth, OAuthProvider } from 'firebase/auth'
Expand All @@ -19,7 +20,6 @@ import {
getCollectionRefs,
getDocDataOrThrow,
getDocumentsRefs,
type UserType,
} from '@/modules/firebase/utils'

const firebaseApp = initializeApp(firebaseConfig)
Expand Down
2 changes: 1 addition & 1 deletion modules/firebase/localizedText.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// SPDX-License-Identifier: MIT
//
import { isObject } from 'lodash'
import { type LocalizedText } from '@/modules/firebase/models/medication'
import { type LocalizedText } from '@/modules/firebase/models'

const locale = 'en'

Expand Down
62 changes: 62 additions & 0 deletions modules/firebase/medication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// This source file is part of the ENGAGE-HF project based on the Stanford Spezi Template Application project
//
// SPDX-FileCopyrightText: 2023 Stanford University
//
// SPDX-License-Identifier: MIT
//
import { type FHIRMedicationRequest } from '@/modules/firebase/models'

export const getMedicationRequestData = (medication: {
medication: string
drug: string
frequencyPerDay: number
quantity: number
instructions: string
}): FHIRMedicationRequest => ({
id: null,
extension: null,
resourceType: 'MedicationRequest',
medicationReference: {
reference: `medications/${medication.medication}/drugs/${medication.drug}`,
type: null,
display: null,
identifier: null,
},
dosageInstruction: [
{
text: medication.instructions,
timing: {
code: null,
repeat: {
frequency: medication.frequencyPerDay,
period: 1,
periodUnit: 'd',
timeOfDay: null,
},
},
doseAndRate: [
{
type: null,
doseQuantity: {
code: '{tbl}',
system: 'http://unitsofmeasure.org',
unit: 'tbl.',
value: medication.quantity,
},
},
],
patientInstruction: null,
},
],
})

export const getMedicationRequestMedicationIds = (
request: FHIRMedicationRequest,
) => {
const reference = request.medicationReference?.reference.split('/')
return {
medicationId: reference?.at(1),
drugId: reference?.at(3),
}
}
63 changes: 63 additions & 0 deletions modules/firebase/models.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// This source file is part of the Stanford Biodesign Digital Health ENGAGE-HF open-source project
//
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
//
// SPDX-License-Identifier: MIT
//
import type {
fhirAllergyIntoleranceConverter,
fhirAppointmentConverter,
fhirCodingConverter,
fhirElementConverter,
fhirMedicationRequestConverter,
fhirObservationConverter,
fhirResourceConverter,
InferEncoded,
invitationConverter,
medicationClassConverter,
organizationConverter,
userConverter,
} from '@stanfordbdhg/engagehf-models'

export type Organization = InferEncoded<typeof organizationConverter> & {
id: string
}

export type Invitation = InferEncoded<typeof invitationConverter>

export type User = InferEncoded<typeof userConverter> & { id: string }

export type FHIRElement = InferEncoded<typeof fhirElementConverter>
export const basicFhirElement: FHIRElement = {
id: null,
extension: null,
}

export type FHIRResource = InferEncoded<typeof fhirResourceConverter>

export type FHIRCoding = InferEncoded<typeof fhirCodingConverter>
export const basicFhirCoding: FHIRCoding = {
...basicFhirElement,
system: null,
version: null,
code: null,
display: null,
userSelected: null,
}

export type FHIRMedicationRequest = InferEncoded<
typeof fhirMedicationRequestConverter
>

export type MedicationClass = InferEncoded<typeof medicationClassConverter>

export type FHIRObservation = InferEncoded<typeof fhirObservationConverter>

export type FHIRAllergyIntolerance = InferEncoded<
typeof fhirAllergyIntoleranceConverter
>

export type FHIRAppointment = InferEncoded<typeof fhirAppointmentConverter>

export type LocalizedText = string | Record<string, string>
72 changes: 0 additions & 72 deletions modules/firebase/models/baseTypes.ts

This file was deleted.

Loading

0 comments on commit 3c4f08a

Please sign in to comment.