-
Notifications
You must be signed in to change notification settings - Fork 68
feat(ihe): fix dob #4050
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
base: develop
Are you sure you want to change the base?
feat(ihe): fix dob #4050
Conversation
Ref: ENG-482 Ref: #1040 Signed-off-by: Thomas Yopes <thomasyopes@Thomass-MBP.attlocal.net>
WalkthroughThe changes update date and timestamp formatting in both inbound and outbound Carequality IHE Gateway v2 modules by replacing manual string manipulations with conversions to HL7v3-compliant date formats using new utility functions. This affects patient birth dates and response/creation timestamps in XML and SOAP envelope constructions without altering control flow or error handling. Changes
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 10000 's a critical failure. 🔧 ESLint
npm error code ERR_SSL_WRONG_VERSION_NUMBER ✨ 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 (1)
packages/core/src/external/carequality/ihe-gateway-v2/inbound/xcpd/create/xcpd-response.ts (1)
142-142
: Extract repeated DOB formatting into a helper
The samereplace(/-/g, "")
logic is duplicated. Consider introducing a smallformatSoapDate
/stripHyphensFromDate
utility and reusing it in both builders to adhere to DRY principles.+// near top of file +function stripHyphensFromDate(date: string): string { + return date.replace(/-/g, ""); +} --- a/packages/core/src/external/carequality/ihe-gateway-v2/inbound/xcpd/create/xcpd-response.ts @@ createQueryByParameter(request: InboundPatientDiscoveryReq) - "@_value": patientResource.birthDate.replace(/-/g, ""), + "@_value": stripHyphensFromDate(patientResource.birthDate), @@ createSubjectAndRegistrationEvent(response: InboundPatientDiscoveryResp) - "@_value": patientResource.birthDate.replace(/-/g, ""), + "@_value": stripHyphensFromDate(patientResource.birthDate),
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/core/src/external/carequality/ihe-gateway-v2/inbound/xcpd/create/xcpd-response.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/core/src/external/carequality/ihe-gateway-v2/inbound/xcpd/create/xcpd-response.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: check-pr / lint-build-test
- GitHub Check: Analyze (javascript)
🔇 Additional comments (1)
packages/core/src/external/carequality/ihe-gateway-v2/inbound/xcpd/create/xcpd-response.ts (1)
43-43
: Correct DOB formatting for livingSubjectBirthTime
Stripping hyphens viareplace(/-/g, "")
ensures the birthDate appears asYYYYMMDD
in thelivingSubjectBirthTime
element.
Ref: ENG-482 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.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
packages/core/src/external/carequality/ihe-gateway-v2/inbound/xcpd/create/xcpd-response.ts
(4 hunks)packages/core/src/external/carequality/ihe-gateway-v2/outbound/xcpd/create/iti55-envelope.ts
(3 hunks)packages/core/src/external/carequality/ihe-gateway-v2/utils.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/core/src/external/carequality/ihe-gateway-v2/inbound/xcpd/create/xcpd-response.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/carequality/ihe-gateway-v2/outbound/xcpd/create/iti55-envelope.ts
packages/core/src/external/carequality/ihe-gateway-v2/utils.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: check-pr / lint-build-test
- GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/core/src/external/carequality/ihe-gateway-v2/outbound/xcpd/create/iti55-envelope.ts (2)
14-14
: LGTM on import statement.The import correctly brings in the new HL7v3 formatting utility functions.
65-65
: Correct usage of timestamp formatting.The implementation properly uses the new
timestampToHl7v3DateTime
function to format creation time according to HL7v3 standards.
export function timestampToHl7v3DateTime(createdTimestamp: string): string { | ||
return dayjs(createdTimestamp).format("YYYYMMDDHHmmss"); | ||
} |
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.
🛠️ Refactor suggestion
Good implementation but add input validation.
The function correctly formats timestamps to HL7v3 standard format. However, consider adding input validation to handle undefined/null values gracefully.
export function timestampToHl7v3DateTime(createdTimestamp: string): string {
+ if (!createdTimestamp) {
+ throw new Error("createdTimestamp is required");
+ }
return dayjs(createdTimestamp).format("YYYYMMDDHHmmss");
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function timestampToHl7v3DateTime(createdTimestamp: string): string { | |
return dayjs(createdTimestamp).format("YYYYMMDDHHmmss"); | |
} | |
export function timestampToHl7v3DateTime(createdTimestamp: string): string { | |
if (!createdTimestamp) { | |
throw new Error("createdTimestamp is required"); | |
} | |
return dayjs(createdTimestamp).format("YYYYMMDDHHmmss"); | |
} |
🤖 Prompt for AI Agents
In packages/core/src/external/carequality/ihe-gateway-v2/utils.ts around lines 6
to 8, the function timestampToHl7v3DateTime lacks input validation for undefined
or null values. Add a check at the start of the function to verify if
createdTimestamp is defined and not null; if it is invalid, return an empty
string or a default value. This will prevent runtime errors and handle invalid
inputs gracefully.
export function dateToHl7v3Date(date: string): string { | ||
return dayjs(date).format("YYYYMMDD"); | ||
} |
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.
🛠️ Refactor suggestion
Add input validation for robust error handling.
The function correctly formats dates to HL7v3 standard format without dashes. However, it should handle undefined/null inputs to prevent runtime errors when dayjs(undefined)
creates an invalid date object.
export function dateToHl7v3Date(date: string): string {
+ if (!date) {
+ throw new Error("date is required");
+ }
return dayjs(date).format("YYYYMMDD");
}
Alternatively, if undefined dates should be handled gracefully:
-export function dateToHl7v3Date(date: string): string {
+export function dateToHl7v3Date(date: string | undefined): string | undefined {
+ if (!date) {
+ return undefined;
+ }
return dayjs(date).format("YYYYMMDD");
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function dateToHl7v3Date(date: string): string { | |
return dayjs(date).format("YYYYMMDD"); | |
} | |
export function dateToHl7v3Date(date: string): string { | |
if (!date) { | |
throw new Error("date is required"); | |
} | |
return dayjs(date).format("YYYYMMDD"); | |
} |
export function dateToHl7v3Date(date: string): string { | |
return dayjs(date).format("YYYYMMDD"); | |
} | |
export function dateToHl7v3Date(date: string | undefined): string | undefined { | |
if (!date) { | |
return undefined; | |
} | |
return dayjs(date).format("YYYYMMDD"); | |
} |
🤖 Prompt for AI Agents
In packages/core/src/external/carequality/ihe-gateway-v2/utils.ts around lines
10 to 12, the dateToHl7v3Date function lacks input validation and can throw
runtime errors if the input date is undefined or null. Add a check at the start
of the function to verify the input is a valid non-null string; if not, handle
it gracefully by either returning an empty string or throwing a descriptive
error. This prevents dayjs from processing invalid inputs and ensures robust
error handling.
@@ -247,7 +246,7 @@ function createSoapBody({ | |||
const providerId = bodyData.principalCareProviderIds[0]; | |||
const homeCommunityId = getHomeCommunityId(gateway, bodyData.samlAttributes); | |||
const patientGender = mapFhirToIheGender(bodyData.patientResource.gender); | |||
const patientBirthtime = bodyData.patientResource.birthDate?.replace(DATE_DASHES_REGEX, ""); | |||
const patientBirthtime = dateToHl7v3Date(bodyData.patientResource.birthDate); |
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.
Handle optional birth date to prevent runtime errors.
The birthDate
property might be undefined according to FHIR specification, but dateToHl7v3Date
expects a string parameter. This could cause runtime errors if the utility function doesn't handle undefined values.
- const patientBirthtime = dateToHl7v3Date(bodyData.patientResource.birthDate);
+ const patientBirthtime = bodyData.patientResource.birthDate
+ ? dateToHl7v3Date(bodyData.patientResource.birthDate)
+ : undefined;
This ensures that dateToHl7v3Date
is only called when birthDate
is defined, preventing potential runtime errors.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const patientBirthtime = dateToHl7v3Date(bodyData.patientResource.birthDate); | |
const patientBirthtime = bodyData.patientResource.birthDate | |
? dateToHl7v3Date(bodyData.patientResource.birthDate) | |
: undefined; |
🤖 Prompt for AI Agents
In
packages/core/src/external/carequality/ihe-gateway-v2/outbound/xcpd/create/iti55-envelope.ts
at line 249, the code calls dateToHl7v3Date with
bodyData.patientResource.birthDate which may be undefined. To fix this, add a
check to ensure birthDate is defined before calling dateToHl7v3Date, and only
call it if birthDate is a valid string. This prevents runtime errors from
passing undefined to the function.
Ref: ENG-482
Issues:
Description
Testing
Release Plan
Summary by CodeRabbit