-
Notifications
You must be signed in to change notification settings - Fork 72
feat(ehr): creating the athena diff bundles #3883
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
Conversation
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
…rt/metriport into 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
…rt/metriport into 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
… 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
…etriport/metriport into 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
WalkthroughThis change set introduces AthenaHealth EHR support for fetching FHIR resource bundles by resource type, including new API endpoints and client methods. It centralizes and refactors bundle fetching logic for all EHRs, removes Canvas-specific pre-signed URL logic, eliminates Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API_Route
participant Athena_Util
participant Athena_API
participant Shared_Util
participant Bundle_Store
Client->>API_Route: POST /ehr/athenahealth/patient/:id/resource/diff
API_Route->>Athena_Util: getAthenaPracticeIdFromPatientId(id)
API_Route->>Shared_Util: startCreateResourceDiffBundlesJobAtEhr({ practiceId, ... })
Shared_Util->>Bundle_Store: Create resource diff job
Bundle_Store-->>Shared_Util: Job ID
Shared_Util-->>API_Route: Job ID
API_Route-->>Client: { jobId }
Client->>API_Route: GET /ehr/athenahealth/patient/:id/resource/diff/latest
API_Route->>Shared_Util: getLatestResourceDiffBundlesJobPayload({ ehr, cxId, ehrPatientId, bundleType })
Shared_Util->>Athena_API: getBundleByResourceType({ ... })
Athena_API->>Athena_API: Validate resourceType
Athena_API->>Athena_API: Fetch paginated resources
Athena_API-->>Shared_Util: Bundle
Shared_Util-->>API_Route: Payload with pre-signed URLs (if job complete)
API_Route-->>Client: Payload
Client->>API_Route: GET /ehr/athenahealth/patient/:id/resource/diff/:jobId
API_Route->>Shared_Util: getResourceDiffBundlesJobPayload({ ehr, cxId, ehrPatientId, bundleType, jobId })
Shared_Util->>Athena_API: getBundleByResourceType({ ... })
Athena_API-->>Shared_Util: Bundle
Shared_Util-->>API_Route: Payload with pre-signed URLs (if job complete)
API_Route-->>Client: Payload
Possibly related PRs
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
npm error code ERR_SSL_WRONG_VERSION_NUMBER 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now using the bundle command from core directly instead of a client command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/core/src/external/ehr/athenahealth/index.ts (1)
735-747
: Consider stronger typing for resourceType parameterThe method validates
resourceType
with a type guard, but you could improve type safety by acceptingSupportedAthenaHealthResource
directly:async getBundleByResourceType({ cxId, metriportPatientId, athenaPatientId, - resourceType, + resourceType: SupportedAthenaHealthResource, useCachedBundle = true, }: { cxId: string; metriportPatientId: string; athenaPatientId: string; - resourceType: string; + resourceType: SupportedAthenaHealthResource; useCachedBundle?: boolean; }): Promise<Bundle> {This would catch invalid resource types at compile time rather than runtime.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/core/src/external/ehr/athenahealth/index.ts
(10 hunks)packages/core/src/external/ehr/canvas/index.ts
(8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/src/external/ehr/canvas/index.ts
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.ts`: - Use the Onion Pattern to organize a package's code in layers - Try to use immutable code and avoid sharing state across different functions, objects, and systems - Try...
**/*.ts
: - Use the Onion Pattern to organize a package's code in layers
- Try to use immutable code and avoid sharing state across different functions, objects, and systems
- Try to build code that's idempotent whenever possible
- Prefer functional programming style functions: small, deterministic, 1 input, 1 output
- Minimize coupling / dependencies
- Avoid modifying objects received as parameter
- Only add comments to code to explain why something was done, not how it works
- Naming
- classes, enums:
PascalCase
- constants, variables, functions:
camelCase
- file names:
kebab-case
- table and column names:
snake_case
- Use meaningful names, so whoever is reading the code understands what it means
- Don’t use negative names, like
notEnabled
, preferisDisabled
- For numeric values, if the type doesn’t convey the unit, add the unit to the name
- Typescript
- Use types
- Prefer
const
instead oflet
- Avoid
any
and casting fromany
to other types- Type predicates: only applicable to narrow down the type, not to force a complete type conversion
- Prefer deconstructing parameters for functions instead of multiple parameters that might be of
the same type- Don’t use
null
inside the app, only on code interacting with external interfaces/services,
like DB and HTTP; convert toundefined
before sending inwards into the code- Use
async/await
instead of.then()
- Use the strict equality operator
===
, don’t use abstract equality operator==
- When calling a Promise-returning function asynchronously (i.e., not awaiting), use
.catch()
to
handle errors (seeprocessAsyncError
andemptyFunction
depending on the case)- Date and Time
- Always use
buildDayjs()
to createdayjs
instances- Prefer
dayjs.duration(...)
to create duration consts and keep them asduration
- Prefer Nullish Coalesce (??) than the OR operator (||) to provide a default value
- Avoid creating arrow functions
- Use truthy syntax instead of
in
- i.e.,if (data.link)
notif ('link' in data)
- Error handling
- Pass the original error as the new one’s
cause
so the stack trace is persisted- Error messages should have a static message - add dynamic data to MetriportError's
additionalInfo
prop- Avoid sending multiple events to Sentry for a single error
- Global constants and variables
- Move literals to constants declared after imports when possible (avoid magic numbers)
- Avoid shared, global objects
- Avoid using
console.log
andconsole.error
in packages other than utils, infra and shared,
and try to useout().log
instead- Avoid multi-line logs
- don't send objects as a second parameter to
console.log()
orout().log()
- don't create multi-line strings when using
JSON.stringify()
- Use
eslint
to enforce code style- Use
prettier
to format code- max column length is 100 chars
- multi-line comments use
/** */
- scripts: top-level comments go after the import
packages/core/src/external/ehr/athenahealth/index.ts
🧠 Learnings (1)
packages/core/src/external/ehr/athenahealth/index.ts (2)
Learnt from: thomasyopes
PR: metriport/metriport#3883
File: packages/core/src/external/ehr/athenahealth/index.ts:0-0
Timestamp: 2025-06-04T12:48:50.151Z
Learning: When arrays contain overlapping values (like supportedAthenaHealthResources and scopes in AthenaHealth), derive one from the other programmatically using spread syntax to prevent divergence when lists change. Use a pattern like `const derivedArray = [...baseArray, ...additionalItems]` to maintain consistency.
Learnt from: thomasyopes
PR: metriport/metriport#3608
File: packages/core/src/external/ehr/canvas/index.ts:451-469
Timestamp: 2025-04-21T17:07:30.574Z
Learning: The `getMetriportOnlyBundleByResourceType` method in CanvasApi returns `Promise<Bundle | undefined>` because the Metriport-only bundle is a computed artifact that may not exist yet. In contrast, `getBundleByResourceType` returns `Promise<Bundle>` because it can always fetch from the EHR API if the S3 cached bundle doesn't exist.
🧬 Code Graph Analysis (1)
packages/core/src/external/ehr/athenahealth/index.ts (4)
packages/api/src/routes/medical/schemas/fhir.ts (1)
Bundle
(23-23)packages/shared/src/index.ts (1)
BadRequestError
(40-40)packages/core/src/external/ehr/shared.ts (2)
fetchEhrFhirResourcesWithPagination
(349-363)fetchEhrBundleUsingCache
(318-338)packages/shared/src/interface/external/ehr/fhir-resource.ts (2)
EhrFhirResourceBundle
(26-26)ehrFhirResourceBundleSchema
(21-25)
⏰ Context from checks skipped due to timeout of 90000ms (8)
- GitHub Check: check-pr / lint-build-test
- GitHub Check: check-pr / lint-build-test
- GitHub Check: check-pr / lint-build-test
- GitHub Check: check-pr / lint-build-test
- GitHub Check: check-pr / lint-build-test
- GitHub Check: check-pr / lint-build-test
- GitHub Check: check-pr / lint-build-test
- GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
packages/core/src/external/ehr/athenahealth/index.ts (6)
2-2
: LGTM: Import additions support new functionalityThe new imports for Bundle, ResourceType, EhrFhirResourceBundle, and shared utilities are properly scoped and necessary for the getBundleByResourceType implementation.
Also applies to: 9-9, 56-59, 77-78
99-99
: LGTM: Constants improve maintainabilityGood practice using named constants instead of magic numbers. The values are reasonable for AthenaHealth's API constraints.
Also applies to: 124-125
156-195
: LGTM: Resource type definitions follow established patternsExcellent implementation that addresses previous feedback:
- Arrays are properly typed as
ResourceType[]
- Scopes are derived programmatically using spread syntax to prevent divergence
- Type guard function provides runtime validation
- Clear separation between supported and reference resources
This follows the learned pattern and prevents maintenance issues when resource lists change.
224-227
: LGTM: Dynamic OAuth scope generationGood improvement to dynamically build FHIR scopes from the resource arrays. This ensures OAuth permissions stay in sync with supported resource types automatically.
756-806
: LGTM: Robust implementation with good practicesThe method implementation demonstrates several best practices:
- Immutable parameter construction using object spread
- Conditional parameter inclusion using spread operator
- Defensive validation of returned bundle resource types
- Proper integration with shared pagination and caching utilities
- Comprehensive error handling
The bundle validation (lines 786-792) is particularly good defensive programming to catch API inconsistencies early.
861-861
: LGTM: Consistent use of centralized constantGood refactoring to replace magic numbers with the centralized
defaultCountOrLimit
constant. This improves maintainability and ensures consistent pagination limits across methods.Also applies to: 923-923
…etriport/metriport into 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
…etriport/metriport into 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
…etriport/metriport into 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
… 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
Ref: ENG-199 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
… 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
… 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MacBook-Pro.local>
… 199-elation-contribution-2 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MacBook-Pro.local>
Issues:
Dependencies
Description
Testing
Release Plan
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests