VED-1147: Convert Upstream Time Format to ISO#1327
Conversation
|
This branch is working on a ticket in the NHS England VED JIRA Project. Here's a handy link to the ticket: VED-1147 |
|
|
||
|
|
||
| def _parse_timestamp_to_iso(timestamp: str) -> str: | ||
| dt_part = timestamp[:15] |
There was a problem hiding this comment.
we are assuming an exact shape by slicing fixed positions and then calling [int(timestamp[15:])] It has no explicit validation for:
empty or non-string input
wrong length
missing T
invalid date/time values
unsupported timezone suffixes
Also, I would want a ValueError message not
There was a problem hiding this comment.
I could re-check, but this validation are already handled in the delta and API code, making it impossible to have an empty data or incomplete timestamp. Also our occurrence date time would always be in that format YYYYTTHHMDDSfz as described in our OAS, anyone not giving us that format should be rejected upfront in the API.

There was a problem hiding this comment.
That's fair. I think the right place for this helper function should be in the shared folder and so it should be assumed that no validation would be happening on consumers of it. If there additional validation then great but otherwise we should be making it robust. What do you think?
There was a problem hiding this comment.
Having it robust wouldn't do no harm, would add that now
|
|
||
| return gp_ods_code | ||
|
|
||
|
|
There was a problem hiding this comment.
Is it better to move this to a shared helper - shared folder perhaps?
There was a problem hiding this comment.
We already need to convert from the custom CSV date format to a standard ISO date in recordprocessor. We could share utils_for_fhir_conversion.Convert to save duplicating the code and tests.
|
|
||
| self.assertEqual(str(context.exception), "PDS API error") | ||
|
|
||
|
|
There was a problem hiding this comment.
-Please can you add the following:
-
Add a UTC conversion test for 20260212T17443700 -> 2026-02-12T17:44:37Z.
-
Add a BST conversion test for 20260212T17443701 -> 2026-02-12T17:44:37+01:00.
-
Add failure tests for missing, malformed, and unsupported-offset DATE_AND_TIME
-
Add a contract test proving output is RFC 3339 second-precision, not the raw compact string.
| return gp_ods_code | ||
|
|
||
|
|
||
| def _parse_timestamp_to_iso(timestamp: str) -> str: |
There was a problem hiding this comment.
_parse_timestamp_to_iso() has no input shape validation and will raise generic exceptions (TypeError/ValueError) without a clear DATE_AND_TIME contract message. (As Akshay mentioned)
…Digital/immunisation-fhir-api into VED-1147-Time-Format-RFC3339
| raise ValueError(f"{field_name} must contain a valid compact timestamp") from e | ||
|
|
||
| tz = timezone(timedelta(hours=int(offset_suffix))) | ||
| return parsed_date.replace(tzinfo=tz).isoformat(timespec="milliseconds").replace("+00:00", "Z") |
There was a problem hiding this comment.
I think we might need to change "milliseconds" to "seconds"
|
avshetty1980
left a comment
There was a problem hiding this comment.
Looks good, thank you Akin



Summary
Fix a bug for time format crafted in MNS Payload, the time previously used maintained Delta time format rather than converting the format to RFC33399
Add any other relevant notes or explanations here. Remove this line if you have nothing to add.
Reviews Required
Review Checklist
ℹ️ This section is to be filled in by the reviewer.