-
Notifications
You must be signed in to change notification settings - Fork 72
ENG-836 Small fix for CW redownload flow #4354
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
Part of ENG-836 Signed-off-by: Ramil Garipov <ramil@metriport.com>
WalkthroughExpands force-download behavior in document-query to include storage-only documents and always delete existing render artifacts during forced downloads. Public APIs remain unchanged. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller
participant DocumentQuery
participant Storage
participant Renderer
Caller->>DocumentQuery: downloadDocsAndUpsertFHIR({ forceDownload })
alt forceDownload = true
DocumentQuery->>Storage: list existing docs on storage
DocumentQuery->>DocumentQuery: add remaining storage-only docs to filesToDownload
loop for each doc in filesToDownload
DocumentQuery->>Renderer: delete existing HTML/PDF renders
DocumentQuery->>Storage: download doc
DocumentQuery->>DocumentQuery: upsert FHIR resources
end
else forceDownload = false
loop for each doc needing download
DocumentQuery->>Storage: conditional download (size/need based)
DocumentQuery->>DocumentQuery: upsert FHIR resources
end
end
DocumentQuery-->>Caller: result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type 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/external/commonwell/document/document-query.ts (1)
535-539
: Force re-download now correctly includes storage-only docs; consider Set for O(1) dedupeSolid fix to ensure storage-only docs aren't skipped when
forceDownload
is true. Minor perf/readability nit: use aSet
for constant-time membership checks.Apply this diff:
- const alreadyIncluded = filesToDownload.map(f => f.docId); - const remainingFoundOnStorage = foundOnStorage.filter(f => !alreadyIncluded.includes(f.docId)); + const alreadyIncluded = new Set(filesToDownload.map(f => f.docId)); + const remainingFoundOnStorage = foundOnStorage.filter(f => !alreadyIncluded.has(f.docId));
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/api/src/external/commonwell/document/document-query.ts
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit Inference Engine (.cursorrules)
**/*.{js,jsx,ts,tsx}
: Don’t use null inside the app, only on code interacting with external interfaces/services, like DB and HTTP; convert to undefined before sending inwards into the code
Useconst
whenever possible
Useasync/await
instead of.then()
Naming: classes, enums: PascalCase
Naming: constants, variables, functions: camelCase
Naming: file names: kebab-case
Naming: Don’t use negative names, likenotEnabled
, preferisDisabled
If possible, use decomposing objects for function parameters
Prefer Nullish Coalesce (??) than the OR operator (||) when you want to provide a default value
Avoid creating arrow functions
Use truthy syntax instead ofin
- i.e.,if (data.link)
notif ('link' in data)
While handling errors, keep the stack trace around: if you create a new Error (e.g., MetriportError), make sure to pass the original error as the new one’s cause so the stack trace is available upstream.
max column length is 100 chars
multi-line comments use/** */
top-level comments go after the import (save pre-import to basic file header, like license)
move literals to constants declared after imports when possible
Files:
packages/api/src/external/commonwell/document/document-query.ts
**/*.{ts,tsx}
📄 CodeRabbit Inference Engine (.cursorrules)
Use types whenever possible
Files:
packages/api/src/external/commonwell/document/document-query.ts
**/*.ts
⚙️ CodeRabbit Configuration File
**/*.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
- U...
Files:
packages/api/src/external/commonwell/document/document-query.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: RamilGaripov
PR: metriport/metriport#4176
File: packages/fhir-converter/src/lib/handlebars-converter/handlebars-helpers.js:296-320
Timestamp: 2025-07-17T21:24:37.077Z
Learning: RamilGaripov prefers to maintain consistency with existing patterns in a file rather than making isolated fixes to coding guideline violations like var vs const declarations, when the pattern is already established throughout the codebase.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: check-pr / lint-build-test
- GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/api/src/external/commonwell/document/document-query.ts (1)
588-595
: Always delete renders on forceDownload — avoids stale artifacts and matches redownload intentBroadening the condition to delete renders whenever
forceDownload
is true makes the behavior predictable and prevents serving outdated HTML/PDF after a forced re-download. LGTM.
Part of ENG-836
Issues:
Description
Testing
Release Plan
Summary by CodeRabbit