Ktb2110 203 additional request fields#214
Open
KTB2110 wants to merge 3 commits into
Open
Conversation
…203) - New Lambda function that accepts a request_id from the event payload and queries req_add_info in virginia_dev_saayam_rdbms for all additional fields - Returns request_id and add_info list of field_id, item_id, field_value per row - DB credentials fetched from AWS SSM Parameter Store (no hardcoded creds) - DE 1000 error code returned on DB connection failure to avoid leaking internals - Virginia only per scope confirmed with team lead
…203) New Lambda function that queries req_add_info table and returns structured additional fields for a given request_id. Core logic: - Accepts request_id from event payload; returns DE 1002 400 error if missing - Queries virginia_dev_saayam_rdbms.req_add_info using parameterized query - Groups rows by field_id into additionalFields dict Field value mapping (four cases handled): - item_id not null, field_value null (radio/checkbox): collects all item_ids into a list — field_id: [item_id1, item_id2, ...] - item_id not null, field_value not null, non-datetime (list with values): maps each item_id to its value — field_id: {item_id1: val1, ...} - item_id null, field_value not null, non-datetime (textbox/integer): maps directly — field_id: field_value - field_value matches ISO datetime pattern ^\d{4}-\d{2}-\d{2}T (date&time fields): splits into _date and _time keys; uses item_id as prefix if present, field_id as prefix if item_id is null — field_id: {item_id_date: 2026-03-24, item_id_time: 14:30:00} No field_ids are hardcoded — datetime detection is purely regex-based Error handling: - DE 1000: DB connection failure → 500 - DE 1001: Query execution failure → 500 - DE 1002: Missing request_id in payload → 400 - request_id not found in DB → 200 with empty additionalFields: {}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements the
additional_request_detailsLambda function for the Request Details tab. The frontend passes arequest_idand the Lambda queriesreq_add_infoin Virginia RDS and returns all additional fields for that request, grouped and structured by field type.What was built
New file:
data-analytics/lambda_functions/additional_request_details.pyModelled after the existing
kpi_api_analytics.pystructure with:RealDictCursorfor named column accessbuild_response()helper for consistent HTTP response formatfinallyblock to guarantee DB connection cleanupField value mapping logic
The core of this Lambda is a loop that groups rows from
req_add_infobyfield_idand maps them differently based on theitem_id/field_valuecombination:item_idfield_value"field_id": ["item_id1", "item_id2"]"field_id": {"item_id1": "val1", "item_id2": "val2"}"field_id": "field_value""field_id": {"item_id_date": "...", "item_id_time": "..."}"field_id": {"field_id_date": "...", "field_id_time": "..."}Date & time bifurcation
Date fields are detected dynamically using regex
^\d{4}-\d{2}-\d{2}Tonfield_value— no field IDs are hardcoded. When matched, the value is split onTinto_dateand_timekeys. Ifitem_idis present, it is used as the key prefix; if null,field_idis used as the prefix.Error handling
500DE 1000500DE 1001request_idin payload400DE 1002request_idnot found in DB200additionalFields: {}Error codes avoid leaking internal DB details to the browser.
Testing
Tested locally against
req_add_info.csvloaded intosaayam_localPostgreSQL. Verified all field type combinations including:6.1.B— PREFERRED_MOVE_OUT_DATE)3.7.B)Closes #203