Skip to content

Ktb2110 203 additional request fields#214

Open
KTB2110 wants to merge 3 commits into
mainfrom
KTB2110_203_additional_request_fields
Open

Ktb2110 203 additional request fields#214
KTB2110 wants to merge 3 commits into
mainfrom
KTB2110_203_additional_request_fields

Conversation

@KTB2110

@KTB2110 KTB2110 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR implements the additional_request_details Lambda function for the Request Details tab. The frontend passes a request_id and the Lambda queries req_add_info in 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.py

Modelled after the existing kpi_api_analytics.py structure with:

  • AWS SSM Parameter Store for DB credentials (no hardcoded values)
  • RealDictCursor for named column access
  • build_response() helper for consistent HTTP response format
  • finally block to guarantee DB connection cleanup

Field value mapping logic

The core of this Lambda is a loop that groups rows from req_add_info by field_id and maps them differently based on the item_id / field_value combination:

item_id field_value Output
not null null "field_id": ["item_id1", "item_id2"]
not null not null (non-datetime) "field_id": {"item_id1": "val1", "item_id2": "val2"}
null not null (non-datetime) "field_id": "field_value"
not null not null (datetime) "field_id": {"item_id_date": "...", "item_id_time": "..."}
null not null (datetime) "field_id": {"field_id_date": "...", "field_id_time": "..."}

Date & time bifurcation

Date fields are detected dynamically using regex ^\d{4}-\d{2}-\d{2}T on field_value — no field IDs are hardcoded. When matched, the value is split on T into _date and _time keys. If item_id is present, it is used as the key prefix; if null, field_id is used as the prefix.

Error handling

Scenario Status Code Error Code
DB connection failure 500 DE 1000
Query execution failure 500 DE 1001
Missing request_id in payload 400 DE 1002
request_id not found in DB 200 empty additionalFields: {}

Error codes avoid leaking internal DB details to the browser.

Testing

Tested locally against req_add_info.csv loaded into saayam_local PostgreSQL. Verified all field type combinations including:

  • Multi-select checkboxes (multiple item_ids under same field_id)
  • Textbox fields (null item_id, direct field_value mapping)
  • Date&time fields with item_id (6.1.B — PREFERRED_MOVE_OUT_DATE)
  • Date&time fields without item_id (3.7.B)
  • Mixed field types in the same request

Closes #203

KTB2110 added 3 commits July 7, 2026 15:15
…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: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Get Additional info fields for Request Details- Details tab

1 participant