Skip to content

[GPCAPIM-287] Orange box#105

Open
Vox-Ben wants to merge 25 commits intomainfrom
feature/GPCAPIM-287-orange_box
Open

[GPCAPIM-287] Orange box#105
Vox-Ben wants to merge 25 commits intomainfrom
feature/GPCAPIM-287-orange_box

Conversation

@Vox-Ben
Copy link
Contributor

@Vox-Ben Vox-Ben commented Mar 6, 2026

Description

This PR permits CDG to call the Orange Box GP Connect demonstrator

Note that it includes a call script. To call the orange box.

  1. Spin up the dev container
  2. Set $STUB_PROVIDER=false in your terminal
  3. Set $BASE_URL=http://gateway-api:8080 in your terminal
  4. make deploy
  5. cd gateway-api
  6. python src/scripts/call_gateway.py 9690937278

To revert to using the stub, repeat the above but unset STUB_PROVIDER before doing make deploy.

Context

This demonstrates that we can build a request that is acceptable to the Orange Box demonstrator for GP Connect and return the response that we get.

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming
  • Exceptions/Exclusions to coding standards (e.g. #noqa or #NOSONAR) are included within this Pull Request.

Sensitive Information Declaration

To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables the gateway-api to construct and send GP Connect Access Record Structured requests that the Orange Box GP Connect demonstrator accepts, including updated stub data to “trigger” the Orange Box path and updated JWT claim structures/validation.

Changes:

  • Added stub SDS/PDS data (ODS/ASID/endpoint + patient) to route a specific NHS number to the Orange Box demonstrator.
  • Updated clinical JWT claim modeling (Device/Practitioner/Organization as dict payloads) and introduced a JWTValidator with unit tests.
  • Updated the GP provider client request URL path/headers and expanded error diagnostics (behind CDG_DEBUG), plus corresponding test updates and a new call script.

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
gateway-api/stubs/stubs/sds/stub.py Adds dummy ODS/ASID/device + Orange Box endpoint seed data for SDS stub responses.
gateway-api/stubs/stubs/provider/stub.py Adds strict header + JWT validation for stubbed provider access_record_structured handling.
gateway-api/stubs/stubs/pds/stub.py Adds a test NHS number mapping to the new Orange Box trigger patient.
gateway-api/stubs/stubs/data/patients/patients.py Registers the new Orange Box trigger patient fixture.
gateway-api/stubs/stubs/data/patients/orange_box_trigger_9690937278.json Adds a Patient resource used to route to Orange Box via GP ODS.
gateway-api/src/gateway_api/test_controller.py Updates controller JWT claim assertions to match new dict-based organization claim.
gateway-api/src/gateway_api/provider/test_client.py Updates provider client tests for new endpoint path, headers, and stub signature.
gateway-api/src/gateway_api/provider/client.py Changes provider endpoint path handling, content-type headers, and error reporting.
gateway-api/src/gateway_api/controller.py Updates JWT generation to use dict claim objects (Device/Practitioner/Organization).
gateway-api/src/gateway_api/conftest.py Adds a shared valid_jwt fixture for validator/client tests.
gateway-api/src/gateway_api/common/error.py Introduces JWTValidationError for claim validation failures.
gateway-api/src/gateway_api/common/common.py Adds get_http_text() helper for HTTP status phrase lookup.
gateway-api/src/gateway_api/clinical_jwt/validator.py New JWTValidator implementing claim structure/timestamp validation.
gateway-api/src/gateway_api/clinical_jwt/test_validator.py New unit tests for JWTValidator behavior.
gateway-api/src/gateway_api/clinical_jwt/test_practitioner.py Updates Practitioner tests to use to_dict() output.
gateway-api/src/gateway_api/clinical_jwt/test_jwt.py Updates JWT tests for dict-based claims and default algorithm behavior.
gateway-api/src/gateway_api/clinical_jwt/test_device.py Updates Device tests to use to_dict() output.
gateway-api/src/gateway_api/clinical_jwt/practitioner.py Refactors Practitioner to emit structured dict payloads (no JSON string building).
gateway-api/src/gateway_api/clinical_jwt/organization.py Adds Organization claim model emitting dict payloads.
gateway-api/src/gateway_api/clinical_jwt/jwt.py Changes JWT claim field types to dict payloads and sets default algorithm to none.
gateway-api/src/gateway_api/clinical_jwt/device.py Refactors Device to emit structured dict payloads (no JSON string building).
gateway-api/src/gateway_api/clinical_jwt/init.py Exposes Organization and JWTValidator from the clinical_jwt package.
gateway-api/scripts/call_gateway.py Adds a CLI script for calling the gateway’s getstructuredrecord endpoint.
gateway-api/poetry.lock Updates lockfile metadata (Poetry version and content hash).
Makefile Passes stub/debug env vars into the docker container on make deploy.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Vox-Ben Vox-Ben marked this pull request as ready for review March 12, 2026 17:08
@Vox-Ben Vox-Ben requested a review from a team as a code owner March 12, 2026 17:08
@davidhamill1-nhs
Copy link
Contributor

Spin up the dev container
Set $STUB_PROVIDER=false in your terminal
Set $BASE_URL=http://gateway-api:8080 in your terminal

The gateway api container has the STUB_PROVIDER env var hard coded in the infrastructure/images/gateway-api/Dockerfile, right?

Copilot AI review requested due to automatic review settings March 16, 2026 23:09
@Vox-Ben Vox-Ben force-pushed the feature/GPCAPIM-287-orange_box branch from 9456e81 to c56c3d1 Compare March 16, 2026 23:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 37 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

github-actions bot commented Mar 17, 2026

Trivy gate: no Critical/High issues.

Trivy IaC (Terraform) Summary

Severity Count
CRITICAL 0
HIGH 0
MEDIUM 0
LOW 0
UNKNOWN 0
Findings (top 50)
Severity ID Title File

@github-actions
Copy link

github-actions bot commented Mar 17, 2026

Trivy gate: no Critical/High vulnerabilities.

Trivy Image Scan Summary

Image: 900119715266.dkr.ecr.eu-west-2.amazonaws.com/whoami:feature-gpcapim-287-orange-box

Severity Count
CRITICAL 0
HIGH 0
MEDIUM 0
LOW 1
UNKNOWN 0
Findings (top 50)
Severity ID Package Installed Fixed Source
LOW CVE-2026-1703 pip 25.3 26.0 Python

Copilot AI review requested due to automatic review settings March 17, 2026 14:42
@sonarqubecloud
Copy link

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 35 out of 37 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +74 to +103
def validate_device(device: dict[str, Any]) -> None:
"""
Validate JWT requesting_device structure.

Raises:
JWTValidationError: If device structure is invalid.
"""
device_errors = []
if device.get("resourceType") != "Device":
device_errors.append("resourceType must be 'Device'")
if not device.get("identifier") or not isinstance(
device.get("identifier"), list
):
device_errors.append("Device identifier must be a non-empty list")
else:
identifier = device["identifier"][0]
if not identifier.get("system"):
device_errors.append("identifier[0].system is required")
if not identifier.get("value"):
device_errors.append("identifier[0].value is required")
if not device.get("model"):
device_errors.append("model is required")
if not device.get("version"):
device_errors.append("version is required")

if device_errors:
raise JWTValidationError(
error_details=f"Invalid requesting_device: {', '.join(device_errors)}"
)

@github-actions
Copy link

Deployment Complete

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.

3 participants