-
Notifications
You must be signed in to change notification settings - Fork 68
ENG-191 Only load the bundle when converting #3692
New issu 8000 e
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
ENG-191 Only load the bundle when converting #3692
Conversation
WalkthroughThe function The Telemetry reporting was added to the In the local snapshot retrieval command, analytics imports and usage were added. The code was refactored to extract A new function Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant recreateConsolidated
participant getConsolidated
participant Connector
Caller->>recreateConsolidated: Call with patient, conversionType?
alt conversionType is provided
recreateConsolidated->>getConsolidated: getConsolidated(patient, conversionType, requestId?)
getConsolidated-->>recreateConsolidated: Return result
else conversionType is not provided
recreateConsolidated->>Connector: buildConsolidatedSnapshotConnector()
recreateConsolidated->>Connector: execute(payload with patient, isAsync: false)
Connector-->>recreateConsolidated: Return result
end
recreateConsolidated-->>Caller: Return consolidated data or error
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
🪧 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 (
|
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/api/src/command/medical/patient/consolidated-recreate.ts (1)
39-48
: Conditional handling aligns with PR objective.This change ensures the bundle is only loaded when necessary during conversion by implementing two distinct paths:
- When
conversionType
is provided - usegetConsolidated
as before- When
conversionType
is absent - create a sync request via the snapshot connectorThe implementation follows the functional programming style recommended in the coding guidelines and maintains proper error handling.
However, consider updating the error message on line 50 to be more generic since it references "Post-DQ getConsolidated" which only directly applies to the first branch.
- processAsyncError(`Post-DQ getConsolidated`, log)(err); + processAsyncError(`Failed to retrieve consolidated data`, log)(err);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
commitlint.config.js
(1 hunks)packages/api/src/command/medical/patient/consolidated-recreate.ts
(2 hunks)
🧰 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/api/src/command/medical/patient/consolidated-recreate.ts
🧬 Code Graph Analysis (1)
packages/api/src/command/medical/patient/consolidated-recreate.ts (1)
packages/core/src/command/consolidated/consolidated-get.ts (1)
getConsolidated
(22-40)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: check-pr / lint-build-test
- GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
commitlint.config.js (1)
16-16
: Adding the period variant for consistency is sensible.This addition allows for more flexibility in commit message formatting while maintaining semantic meaning. It accommodates both "Ref ENG-" and "Ref. ENG-" formats, making the configuration more robust.
packages/api/src/command/medical/patient/consolidated-recreate.ts (1)
3-4
: New imports support conditional bundle loading functionality.These imports enable the implementation of the alternative path for retrieving consolidation when no conversion type is specified.
62ac756
to
082d50e
Compare
packages/api/src/command/medical/patient/consolidated-recreate.ts
Outdated
Show resolved
Hide resolved
ae0ee26
to
8764dee
Compare
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/command/consolidated/get-snapshot-local.ts (1)
64-64
: Consider removing this variable assignmentAdding
resultBundle
as an alias fornormalizedBundle
doesn't add much clarity since it's just a direct assignment. Consider usingnormalizedBundle
consistently instead to reduce cognitive load.- const resultBundle = normalizedBundle;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Lite
📒 Files selected for processing (3)
packages/api/src/command/medical/patient/consolidated-get 10000 .ts
(1 hunks)packages/api/src/command/medical/patient/convert-fhir-bundle.ts
(2 hunks)packages/core/src/command/consolidated/get-snapshot-local.ts
(6 hunks)
🧰 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/api/src/command/medical/patient/convert-fhir-bundle.ts
packages/core/src/command/consolidated/get-snapshot-local.ts
packages/api/src/command/medical/patient/consolidated-get.ts
🧬 Code Graph Analysis (1)
packages/core/src/command/consolidated/get-snapshot-local.ts (1)
packages/core/src/external/analytics/posthog.ts (1)
analytics
(23-39)
🔇 Additional comments (7)
packages/api/src/command/medical/patient/convert-fhir-bundle.ts (2)
14-14
: LGTM: Added analytics importThe import of analytics and EventTypes is correctly placed and follows the import order convention.
85-93
: Well-placed analytics tracking for telemetryGood addition of analytics tracking after bundle processing is complete. This provides valuable telemetry about consolidated queries with appropriate context (patientId, conversionType, and resource count).
The analytics event is triggered at an appropriate point in the execution flow, after the bundle has been fully processed and we know its final state. This aligns with the PR objective of optimizing bundle handling during conversion.
packages/core/src/command/consolidated/get-snapshot-local.ts (4)
11-11
: LGTM: Added analytics importThe import of analytics and EventTypes is correctly placed and follows the project conventions.
67-67
: Consistent use of resultBundle variableThe usage of
resultBundle
is consistent throughout the file, replacing previous references tonormalizedBundle
. This change is connected to the introduction of theresultBundle
variable.Also applies to: 78-78, 103-103
87-87
: Fixed bundle reference in Promise.all resultThis change correctly captures the third upload result as
resultS3Info
(instead of the second asdedupedS3Info
), fixing a potential bug in the original code. The correct S3 info is now used for the bundle location and filename.Also applies to: 108-108
126-135
: Well-placed analytics tracking for consolidated operationsGood addition of analytics tracking after successful bundle processing. This provides valuable telemetry with appropriate context (patientId, conversion type as "bundle", and resource count).
This change complements the analytics tracking added in the convert-fhir-bundle.ts file, ensuring comprehensive telemetry for both bundle processing and conversion operations.
packages/api/src/command/medical/patient/consolidated-get.ts (1)
256-261
: Simplified data retrieval flowThe function now always fetches a fresh bundle using
getConsolidatedPatientData
instead of conditionally using a passed-in bundle. This simplification aligns with the PR's objective of only loading bundles when converting.This change:
- Makes the code more consistent and easier to maintain
- Supports the optimization of bundle handling during MR creation
- Works well with the analytics tracking moved to more appropriate places in the processing flow
Ref eng-141 Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
Ref eng-141 Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
980be4f
to
4f84264
Compare
const currentConsolidatedProgress = patient.data.consolidatedQueries?.find( | ||
q => q.requestId === requestId | ||
); | ||
|
||
const defaultAnalyticsProps = { | ||
distinctId: patient.cxId, | ||
event: EventTypes.consolidatedQuery, | ||
properties: { | ||
patientId: patient.id, | ||
conversionType: "bundle", | ||
duration: elapsedTimeFromNow(currentConsolidatedProgress?.startedAt), | ||
resourceCount: bundle.entry?.length, | ||
}, | ||
}; | ||
|
||
analytics(defaultAnalyticsProps); |
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.
moved to get-snapshot-local.ts
analytics({ | ||
...defaultAnalyticsProps, | ||
properties: { | ||
...defaultAnalyticsProps.properties, | ||
duration: elapsedTimeFromNow(currentConsolidatedProgress?.startedAt), | ||
conversionType, | ||
}, | ||
}); |
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.
moved to handleBundleToMedicalRecord
- convert-fhir-bundle.ts
Ref eng-141 Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
78bf361
to
65acf46
Compare
Dependencies
none
Description
Only load the bundle upon recreate consolidated when converting (creating a MR).
Testing
Release Plan
Summary by CodeRabbit