This is the code for the Prescription Tracker UI.
packages/cpt-uiClient side react front end for Prescription Tracker UIpackages/cdk/Contains the cdk code used to define the stacks.packages/cloudfrontFunctions/Functions used to modify the requests and responses in CloudFront.packages/staticContent/Static content used by the website.packages/cognito/Lambda function used by cognitopackages/CIS2SignOutLambda/Lambda function used by CIS2 to sign out userspackages/prescriptionListLambda/Lambda function used to list prescriptionspackages/patientSearchLambda/Lambda function used to search for patientspackages/common/middyErrorHandler/Common error handler used by the lambda functionspackages/common/pdsClient/Common PDS client used by the lambda functionspackages/common/commonTypes/Common types used throughout the lambda functionspackages/common/lambdaUtils/Common utils used by the lambda functionspackages/common/testing/Common testing utils used by the lambda functionspackages/common/authFunctions/Common auth functions used by the lambda functionsscripts/Utilities helpful to developers of this specification..devcontainerContains a dockerfile and vscode devcontainer definition..githubContains github workflows that are used for building and deploying from pull requests and releases..vscodeContains vscode workspace file.
Contributions to this project are welcome from anyone, providing that they conform to the guidelines for contribution and the community code of conduct.
This code is dual licensed under the MIT license and the OGL (Open Government License). Any new work added to this repository must conform to the conditions of these licenses. In particular this means that this project may not depend on GPL-licensed or AGPL-licensed libraries, as these would violate the terms of those libraries' licenses.
The contents of this repository are protected by Crown Copyright (C).
It is recommended that you use visual studio code and a devcontainer as this will install all necessary components and correct versions of tools and languages. See https://code.visualstudio.com/docs/devcontainers/containers for details on how to set this up on your host machine. There is also a workspace file in .vscode that should be opened once you have started the devcontainer. The workspace file can also be opened outside of a devcontainer if you wish.
All commits must be made using signed commits
Once the steps at the link above have been completed. Add to your ~/.gnupg/gpg.conf as below:
use-agent
pinentry-mode loopback
and to your ~/.gnupg/gpg-agent.conf as below:
allow-loopback-pinentry
As described here: https://stackoverflow.com/a/59170001
You will need to create the files, if they do not already exist. This will ensure that your VSCode bash terminal prompts you for your GPG key password.
You can cache the gpg key passphrase by following instructions at https://superuser.com/questions/624343/keep-gnupg-credentials-cached-for-entire-user-session
Ensure you have the following lines in the file .envrc
export AWS_DEFAULT_PROFILE=prescription-dev
Once you have saved .envrc, start a new terminal in vscode and run this command to authenticate against AWS
make aws-configure
Put the following values in:
SSO session name (Recommended): sso-session
SSO start URL [None]: <USE VALUE OF SSO START URL FROM AWS LOGIN COMMAND LINE ACCESS INSTRUCTIONS ACCESSED FROM https://myapps.microsoft.com>
SSO region [None]: eu-west-2
SSO registration scopes [sso:account:access]:
This will then open a browser window and you should authenticate with your hscic credentials You should then select the development account and set default region to be eu-west-2.
You will now be able to use AWS and CDK CLI commands to access the dev account. You can also use the AWS extension to view resources.
When the token expires, you may need to reauthorise using make aws-login
To speed up feedback time during development, you can run the website locally and automatically sync any cdk changes automatically to AWS.
You must have already created a pull request for your branch to set up the initial CDK infrastructure.
Once this is done, you can run
make cdk-watch
and enter the pull request id (just the number) Log files are written to at
- .local_config/stateful_app.log
- .local_config/stateless_app.log
- .local_config/website.log
You should monitor the stateful and stateless log files as it can take a few minutes for the sync to complete.
This runs cdk watch against the stateless and stateful stacks, and also starts the website running locally which you can access at http://localhost:3000
React code resides in packages/cpt-ui folder.
The GitHub Actions require a secret to exist on the repo called "SONAR_TOKEN". This can be obtained from SonarCloud as described here. You will need the "Execute Analysis" permission for the project (NHSDigital_electronic-prescription-service-clinical-prescription-tracker) in order for the token to work.
Some pre-commit hooks are installed as part of the install above, to run basic lint checks and ensure you can't accidentally commit invalid changes. The pre-commit hook uses python package pre-commit and is configured in the file .pre-commit-config.yaml. A combination of these checks are also run in CI.
There are make commands that are run as part of the CI pipeline and help alias some functionality during development.
install-nodeInstalls node dependenciesinstall-pythonInstalls python dependenciesinstall-hooksInstalls git pre commit hooksinstallRuns all install targets
These are used to do common commands related to cdk
cdk-deployBuilds and deploys the code to AWScdk-synthConverts the CDK code to cloudformation templatescdk-diffRuns cdk diff comparing the deployed stack with local CDK code to see differencescdk-watchSyncs the code and CDK templates to AWS, and starts local webserver. This keeps running and automatically uploads changes to AWS
cleanClears up any files that have been generated by building or testing locally.deep-cleanRuns clean target and also removes any node_modules and python libraries installed locally.
lintRuns lint for all codelint-nodeRuns lint for node codetestRuns unit tests for all codecfn-guardruns cfn-guard for cloudformation templates generated by cdk synth
compileCompiles all codecompile-nodeRuns tsc to compile typescript code
check-licensesChecks licenses for all packages used - calls check-licenses-node, check-licenses-pythoncheck-licenses-nodeChecks licenses for all node codecheck-licenses-pythonChecks licenses for all python code
aws-configureConfigures a connection to AWSaws-loginReconnects to AWS from a previously configured connection
react-devStarts app in dev mode on localhostreact-buildGenerates static files in .next folderreact-startStarts app in production mode using build-generated static files
This .github folder contains workflows and templates related to GitHub, along with actions and scripts pertaining to Jira.
pull_request_template.mdTemplate for pull requests.dependabot.ymlDependabot definition file.
Actions are in the .github/actions folder:
mark_jira_releasedAction to mark Jira issues as released.update_confluence_jiraAction to update Confluence with Jira issues.
Scripts are in the .github/scripts folder:
call_mark_jira_released.shCalls a Lambda function to mark Jira issues as released.create_env_release_notes.shGenerates release notes for a specific environment using a Lambda function.create_int_rc_release_notes.shCreates release notes for integration environment using a Lambda function.delete_stacks.shChecks and deletes active CloudFormation stacks associated with closed pull requests.get_current_dev_tag.shRetrieves the current development tag and sets it as an environment variable.get_target_deployed_tag.shRetrieves the currently deployed tag and sets it as an environment variable.
Workflows are in the .github/workflows folder:
ci.ymlWorkflow that runs on merges to main branch and releases to dev and qa environments.delete_old_cloudformation_stacks.ymlWorkflow for deleting old cloud formation stacks. Runs daily.dependabot_auto_approve_and_merge.ymlWorkflow to auto merge dependabot updates.pr_title_check.ymlThis workflow checks the pull request title has the correct format.pr-link.ymlThis workflow template links Pull Requests to Jira tickets and runs when a pull request is opened.pull_request.ymlCalled when pull request is opened or updated. Calls package_code and release_code to build and deploy the code. Deploys to dev AWS account. The main stack deployed adopts the naming convention cpt-ui-pr-<PULL_REQUEST_ID>quality_checks.ymlRuns check-licenses, lint, test and SonarCloud scan against the repo. Called from pull_request.yml and release.ymlrelease.ymlCreates a new release tag and deploys to all environmentscdk_package_code.ymlPackages code into a docker image and uploads to a github artifact for later deployment.cdk_release_code.ymlRelease code built by cdk_package_code.yml to an environment.