{"id":19504821,"url":"https://github.com/nice-digital/mas","last_synced_at":"2025-02-25T22:12:59.400Z","repository":{"id":37914779,"uuid":"215289471","full_name":"nice-digital/MAS","owner":"nice-digital","description":"Medicines Awareness Service","archived":false,"fork":false,"pushed_at":"2024-07-24T10:12:20.000Z","size":1695,"stargazers_count":0,"open_issues_count":27,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-08T10:45:31.540Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nice-digital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-15T12:09:07.000Z","updated_at":"2021-11-15T17:06:12.000Z","dependencies_parsed_at":"2025-01-08T10:43:25.360Z","dependency_job_id":"a8453695-732b-421c-ba4e-f716019936b2","html_url":"https://github.com/nice-digital/MAS","commit_stats":null,"previous_names":[],"tags_count":58,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nice-digital%2FMAS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nice-digital%2FMAS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nice-digital%2FMAS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nice-digital%2FMAS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nice-digital","download_url":"https://codeload.github.com/nice-digital/MAS/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240754366,"owners_count":19852189,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T22:27:19.828Z","updated_at":"2025-02-25T22:12:59.298Z","avatar_url":"https://github.com/nice-digital.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MAS (Medicines awareness service)\n\n- [MAS (Medicines awareness service)](#mas-medicines-awareness-service)\n  - [What is it?](#what-is-it)\n    - [Architecture](#architecture)\n      - [Diagram](#diagram)\n  - [Requirements](#requirements)\n    - [IDE](#ide)\n  - [Local development](#local-development)\n    - [Lambdas](#lambdas)\n      - [Faking the lamda schedule locally](#faking-the-lamda-schedule-locally)\n        - [SAM requirements](#sam-requirements)\n        - [Disable TeamCity Nuget](#disable-teamcity-nuget)\n        - [Build SAM project](#build-sam-project)\n        - [Invoke the lambda](#invoke-the-lambda)\n    - [Rest of the app](#rest-of-the-app)\n\n## What is it?\n\nMedicines awareness service is:\n\n\u003e A daily or weekly email service that provides links to current awareness and evidence-based information relating to medicines and prescribing. Provides a quick overview of the latest evidence-based information, to help busy health professionals stay up to date.\n\n### Architecture\n\nThe overall Medicines awareness service system consists of the following applications:\n\n- Headless CMS (KeystoneJS) backed by a Mongo database\n- S3 bucket to serve a static website\n- Several lambdas to:\n  - Translate content from the CMS into:\n    - HTML on the static site\n    - Feeds on the static site\n  - Send the MAS daily email\n  - Send the MAS weekly email\n- MailChimp to manage subscribers, templates and send emails.\n\n#### Diagram\n\n```\n+----------+           +---------------------------+                 +--------------+\n|          |  Manages  |                           |                 |              |\n|  SPS     +--daily----\u003e      CMS                  |                 | CloudWatch   |\n|          |  content  |                           |                 | events       |\n+----------+           |  +----------+  +-------+  |                 |              |\n                       |  |          |  |       |  |                 +------+-------+\n+----------+           |  | Webhooks |  |  API  \u003c-------------+             |\n|          |  Curates  |  |          |  |       |  |          |             |Scheduled trigger\n|  NICE    +--weekly---\u003e  +----+-----+  +-------+  |       Gets             |\n|          |  content  |       |                   |       content   +------v-------+\n+----------+           +---------------------------+          |      |              |\n                               |                              +------+ Daily/weekly |\n                               |On content                           | lambdas      |\n                               |change                               |              |\n                               |                                     +------+-------+\n                          +----v-----+                                      |\n                          |          |                                      |Creates and sends email\n                          |  Lambda  |                                      |\n                          |          |                               +------v---------------------------+\n                          +----+-----+                               |                                  |\n                               |                                     |            MailChimp             |\n                               |Creates and                          |                                  |\n                               |pushes HTML                          |  +------------+  +------------+  |\n                               |                   +----------+      |  |            |  |            |  |\n                          +----v-----+             |          |      |  | Subscriber |  | Template   |  |\n                          |          |  Views SPS  | User     |      |  | management |  | management |  |\n                          |  Static  |  comment    | receives |      |  |            |  |            |  |\n                          |  site    +\u003c------------+ email    \u003c------+  -------------+  +------------+  |\n                          |          |             |          |      |                                  |\n                          +----------+             +----------+      +----------------------------------+\n```\n\n\u003e Note: to edit the diagram, copy the source into http://asciiflow.com/ or similar.\n\n## Requirements\n\n- Docker (a licence is required for Docker Desktop)\n- AWS CLI\n- SAM CLI\n- Amazon.lambda.tools \n  - Install this with the following command: \n  - `dotnet tool install --global Amazon.Lambda.Tools --version 3.3.1`\n  - \u003e Note: If you encounter an error try disabling all non-standard nuget sources\n\n### IDE\n\nVisual Studio 2017+\nVS Code, extension(s) - TODO add extensions.json\n\n## Local development\n\nYou can run each part of the application (CMS, lambdas, S3 etc) independently. See each of the sections below for detailed steps.\n\nHowever, the easiest way to run the [lambdas](#lambdas) via Visual Studio and the [rest of the app](#rest-of-the-app) via Docker:\n\n### Lambdas\n\nWe use the [Amazon.Lambda.AspNetCoreServer](https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.AspNetCoreServer) package which makes running a lambda via IIS Express (as a fake API Gateway) locally really easy.\n\nFirst, you'll need user secrets with all the application settings locally. This avoids checking application config into git. Get a copy of user-secrets.json from a member of the MAS team. Open up [lambdas/MAS.sln](lambdas/MAS.sln) in Visual Studio and right click the MAS project in solution explorer before selecting \"Manage user secrets\". In the blank file that opens paste in the contents from user-secrets.json.\n\nRestore packages and run the *MAS* project. This runs up a mock API gateway on http://localhost:64418 via IIS express (it will just serve a 404 as there's nothing set up serve from the root).\n\n\u003e Note: you will need to reference the NICE NuGet server(s) to be able to restore packages.\n\n#### Faking the lamda schedule locally\n\nWe have an [AWS Serverless Application Model (SAM) template](lambda/MAS/serverless.template) that describes the lambda. This can be used to invoke the lambda locally using the SAM CLI. If you've never used SAM, then read the [AWS SAM docs](https://docs.aws.amazon.com/serverless-application-model/index.html) before getting started.\n\n\u003e Note: we don't use this SAM template for our deployments to production, it's only used for local testing.\n\nIn production, we use CloudWatch schedule triggers to send the daily and weekly emails. Locally, we normally run the lambda via IIS Express to mimick API Gateway. Use SAM CLI instead to trigger the lambda locally to fake the schedule event.\n\n##### SAM requirements\n\nMake sure you have the latest:\n\n- [Microsoft .NET Core SDK 2.1](https://dotnet.microsoft.com/download/dotnet-core/2.1) (\u003e=2.1.803) (check your version by running `dotnet --version`)\n- [NuGet](https://www.nuget.org/downloads) (on Windows run `nuget update -self`)\n- [AWS CLI](https://aws.amazon.com/cli/)\n- [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-windows.html) (run `sam --version` to check your version)\n\n##### Disable TeamCity Nuget\n\nYou might need to temporarily disable the TeamCity NuGet feed first. Open *%appdata%\\NuGet\\NuGet.Config* and add the following:\n\n```xml\n\u003cdisabledPackageSources\u003e\n    \u003cadd key=\"TeamCity\" value=\"true\" /\u003e\n\u003c/disabledPackageSources\u003e\n```\n\n\u003e This stops the SAM CLI commands from getting a 401 from our internal TeamCity NuGet feed.\n\n##### Build SAM project\n\nWhen you've installed the dependencies above:\n\n1. Open CMD on Windows (the `sam` command doesn't seem to work in Bash on Windows)\n2. `cd` into the *lambda/MAS* project directory\n3. Build the SAM project: `sam build -t serverless.template`\n\nThis builds the project and creates a *.aws-sam* folder which contains the template (yaml) and the compiled application.\n\n\u003e Note: when you've done this once, next time you can speed it up by running `sam build -t serverless.template --skip-pull-image`\n\nOpen *MAS/.aws-sam/build/AspNetCoreFunction/appsettings.json* and you'll notice all the settings are empty. To run the lambda locally, copy the contents of your secrets.json into this appsettings.json.\n\nThe *.aws-sam* folder is excluded from git, so don't worry about these secrets.\n\n##### Invoke the lambda\n\nOnce you've built the SAM project as above, execute the daily schedule trigger by running:\n\n```sh\necho {\"resource\": \"daily\" } | sam local invoke -e -\n```\n\nOr the weekly with \n\n```sh\necho {\"resource\": \"weekly\" } | sam local invoke -e -\n```\n\n\u003e Note: You can also run lambda and fake API Gateway via SAM CLI with this command `sam local start-api`, but we normally don't do this as it's A LOT easier to just use IIS Express.\n\n### Rest of the app\nBefore starting the docker containers the environmental variables creating. These live in the .env file which docker uses for variable replacement. (For more info read: https://docs.docker.com/compose/environment-variables/#the-env-file)\nTo create the variables get a copy of the .env file from a member of the MAS team and replace the some of the variables to make them relivant to you. Place this it in the root MAS directory.\n\nInstall Docker and run `docker-compose up` from the root of the repository. This creates:\n\n- a Mongo dabatase on port 27017\n- the CMS on port 3010\n- a mock S3 backend server (MinIO) on port 9000\n- a mock S3 frontend on port 8000.\n\nEach of these ports is exposed to the host machine. This means you can view each application locally, for example visit:\n\n- http://localhost:3010 in your browser to access the CMS\n- http://localhost:9000 to browse the MinIO server\n- http://localhost:8000 to view the static website.\n\n\u003e Note: the first time you do this it will **take a while**. This is because it needs to download all the required images. Subsequent runs will use cached images so will be quicker.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnice-digital%2Fmas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnice-digital%2Fmas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnice-digital%2Fmas/lists"}