-
Notifications
You must be signed in to change notification settings - Fork 68
ENG-238 Validate contributed bundle before hitting the DB #3775
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-238 Signed-off-by: Rafael Leite <2132564+leite08@users.noreply.github.com>
WalkthroughThe changes update the Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API_Route
participant handleDataContribution
participant S3
participant OrganizationService
Client->>API_Route: PUT /consolidated (with bundle)
API_Route->>API_Route: getPatientInfoOrFail(req) → patient
API_Route->>handleDataContribution: { requestId, patient, cxId, bundle }
handleDataContribution->>handleDataContribution: Normalize, hydrate, validate bundle with patient
handleDataContribution->>S3: Upload original bundle
handleDataContribution->>OrganizationService: Fetch organization
handleDataContribution->>handleDataContribution: Process bundle (resource limits, CDA, CCD, etc.)
handleDataContribution-->>API_Route: Result
API_Route-->>Client: Response
✨ 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 (
|
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 (2)
packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts (2)
50-50
: Minor improvement: Update log messageThe log message still mentions "to get org and patient" but the patient is no longer being fetched in the Promise.all.
- log(`${Date.now() - mainStartedAt}ms to get org and patient, and store on S3`); + log(`${Date.now() - mainStartedAt}ms to get org and store on S3`);
52-56
: Outdated log messageThe timing log message mentions "hydrate, validate, and check limits" but hydration and validation have been moved before the Promise.all. Only resource limit checking is performed during this timing measurement.
- log(`${Date.now() - validationStartedAt}ms to hydrate, validate, and check limits`); + log(`${Date.now() - validationStartedAt}ms to check resource limits`);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts
(2 hunks)packages/api/src/routes/medical/patient.ts
(1 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/routes/medical/patient.ts
packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts
🧬 Code Graph Analysis (2)
packages/api/src/routes/medical/patient.ts (1)
packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts (1)
handleDataContribution
(19-90)
packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts (2)
packages/shared/src/interface/external/ehr/healthie/patient.ts (1)
Patient
(22-22)packages/shared/src/interface/external/ehr/fhir-resource.ts (1)
Bundle
(42-42)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: check-pr / lint-build-test
- GitHub Check: Analyze (javascript)
🔇 Additional comments (4)
packages/api/src/routes/medical/patient.ts (1)
365-367
: Function signature adaptation looks goodThe change properly adapts to the updated
handleDataContribution
function signature by passing the fullpatient
object instead of just thepatientId
. This is consistent with the PR objective to validate bundles earlier in the process.packages/api/src/command/medical/patient/data-contribution/handle-data-contributions.ts (3)
3-3
: Appropriate import changeThe import path change properly sources the
Patient
type needed for the function parameter.
20-30
: Good refactoring to accept Patient object directlyChanging the function to accept a
Patient
object instead of apatientId
string eliminates the need for a database lookup inside the function, which aligns with the PR objective to validate bundles before hitting the DB.
39-49
: Excellent reordering of validation stepsMoving the normalization, hydration, and validation steps before the database operations allows for early rejection of invalid bundles, which directly achieves the PR objective. The Promise.all now only includes S3 upload and organization retrieval, removing the patient fetch operation since the patient is provided upfront.
Issues:
Dependencies
none
Description
Validate contributed bundle before hitting the DB.
Testing
Release Plan
Summary by CodeRabbit