From 274ca32224e82c4cc4149f38a505484be5bb4d02 Mon Sep 17 00:00:00 2001 From: ZijingY <115186965+ZijingY@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:03:48 +0000 Subject: [PATCH] Initialize readme-updates --- .gitattributes | 6 ++++ .github/dependabot.yml | 7 +++++ .github/workflows/setup.yaml | 45 ++++++++++++++++++++++++++++++ .github/workflows/test_runner.yaml | 17 +++++++++++ .gitignore | 11 ++++++++ .gitpod.yml | 44 +++++++++++++++++++++++++++++ .vscode/settings.json | 14 ++++++++++ .vscode/tasks.json | 25 +++++++++++++++++ LICENSE | 21 ++++++++++++++ README.md | 25 +++++++++++++++++ analysis/study_definition.py | 13 +++++++++ codelists/codelists.json | 3 ++ codelists/codelists.txt | 0 docs/.gitkeep | 1 + logs/.gitkeep | 0 output/.gitkeep | 0 project.yaml | 12 ++++++++ 17 files changed, 244 insertions(+) create mode 100644 .gitattributes create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/setup.yaml create mode 100644 .github/workflows/test_runner.yaml create mode 100644 .gitignore create mode 100644 .gitpod.yml create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 LICENSE create mode 100644 README.md create mode 100644 analysis/study_definition.py create mode 100644 codelists/codelists.json create mode 100644 codelists/codelists.txt create mode 100644 docs/.gitkeep create mode 100644 logs/.gitkeep create mode 100644 output/.gitkeep create mode 100644 project.yaml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5d37250 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=auto + +# ensure unix line endings on windows for files that need them. +*.sh eol=lf +codelists/* eol=lf diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..27f4a0a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 + +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "monthly" diff --git a/.github/workflows/setup.yaml b/.github/workflows/setup.yaml new file mode 100644 index 0000000..fb1c5fc --- /dev/null +++ b/.github/workflows/setup.yaml @@ -0,0 +1,45 @@ +name: Setup repository +on: + workflow_dispatch: + push: + branches: [main] +permissions: + contents: write +jobs: + setup: + name: Initialise OpenSAFELY project. + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Update README.md and remove action + shell: bash + run: | + export GITHUB_REPOSITORY_OWNER="$(echo $GITHUB_REPOSITORY | awk -F/ '{print $1}')" + export GITHUB_REPOSITORY_NAME="$(echo $GITHUB_REPOSITORY | awk -F/ '{print $2}')" + envsubst < README.md > tmp && mv tmp README.md + rm .github/workflows/setup.yaml + - name: Do not run on template repository + id: is_template + # The only way to trigger this to run when used as a template is on + # push to main. But that means it would also trigger when we push to + # the template repo itself, which we do not want. So, check if we are + # in a template repo + run: | + is_template=false + curl --silent -X GET \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.baptiste-preview+json" \ + https://api.github.com/repos/$GITHUB_REPOSITORY \ + | jq --exit-status '.is_template == false' || is_template=true + # output true/false so later actions can be skipped + echo "::set-output name=is_template::$is_template" + - name: Commit changes + # only actually commit the changes if this is not a template repo + if: steps.is_template.outputs.is_template == 'false' + run: | + # use the same author as the initial commit + git config user.email "$(git log -1 --pretty=format:'%ae')" + git config user.name "$(git log -1 --pretty=format:'%an')" + git add . + git commit --amend --no-edit + git push origin $GITHUB_REF --force diff --git a/.github/workflows/test_runner.yaml b/.github/workflows/test_runner.yaml new file mode 100644 index 0000000..ae9026d --- /dev/null +++ b/.github/workflows/test_runner.yaml @@ -0,0 +1,17 @@ +name: Test that the project is runnable + +on: [push, workflow_dispatch] +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCKER_RO_TOKEN: ${{ secrets.DOCKER_RO_TOKEN }} + STATA_LICENSE: ${{ secrets.STATA_LICENSE }} + HONEYCOMB_API_KEY: ${{ secrets.HONEYCOMB_API_KEY }} +jobs: + test: + runs-on: ubuntu-latest + name: Test the project can run, using dummy data + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Test that the project is runnable + uses: opensafely-core/research-action@v2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5e16945 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*~ +model.log +*/input.csv +__pycache__ +.python-version +/output/* +metadata/* +venv/ +.DS_Store +.Rhistory +.Rproj.user/ diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..e73425a --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,44 @@ +--- +# List the start up tasks. Learn more https://www.gitpod.io/docs/config-start-tasks/ +tasks: + - name: Install opensafely + # prebuild, run in the background on every commit + init: | + # install everything into a venv in /workspace, so it is persisted in the prebuild image + python -m venv /workspace/venv + # install opensafely + /workspace/venv/bin/pip install --progress-bar off opensafely + # ensure essential docker images are preloaded preloaded + /workspace/venv/bin/opensafely pull cohortextractor + # run everytime we start a workspace + command: | + # limit action concurrency to as not to exhaust gitpod's RAM + export MAX_WORKERS=2 + # add opensafely to the path + export PATH=/workspace/venv/bin:$PATH + opensafely upgrade + opensafely pull --project project.yaml +github: + prebuilds: + # enable for the default branch (defaults to true) + master: true + # enable for all branches in this repo (defaults to false) + branches: true + # enable for pull requests coming from this repo (defaults to true) + pullRequests: true + # enable for pull requests coming from forks (defaults to false) + pullRequestsFromForks: true + # add a check to pull requests (defaults to true) + addCheck: true + # add a "Review in Gitpod" button as a comment to pull requests (defaults to false) + addComment: true + # add a "Review in Gitpod" button to the pull request's description (defaults to false) + addBadge: false + +vscode: + extensions: + - ms-python.python + - vscode.html-language-features + - redhat.vscode-yaml + - ikuyadeu.r + - randomfractalsinc.vscode-data-preview diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..4a01863 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,14 @@ +{ + "python.linting.pylintEnabled": false, + "python.linting.flake8Enabled": true, + "python.linting.enabled": true, + "data.preview.create.json.schema": false, + "files.associations": { + "*.feather": "arrow", + }, + "files.autoSave": "afterDelay", + "files.autoSaveDelay": 1000, + "window.autoDetectColorScheme": true, + "extensions.ignoreRecommendations": true, + "data.preview.theme": "light" +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..a67970f --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,25 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "OpenSAFELY run project", + "type": "shell", + "command": "opensafely run run_all -f", + "problemMatcher": [], + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "new", + "showReuseMessage": false, + "clear": true, + } + } + ] +} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c656213 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) {{organisation}} + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2a02a33 --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# ${GITHUB_REPOSITORY_NAME} + +This is a repository for work conducted on electronic health records in England via [OpenSAFELY](https://opensafely.org). + +Up to date details of the purpose and any published outputs from this project can be found [on OpenSAFELY](https://jobs.opensafely.org/repo/https%253A%252F%252Fgithub.com%252Fopensafely%252F${GITHUB_REPOSITORY_NAME}). + +For your interest - to evaluate the code only, without any use of any actual patient data - you can execute the code for this project against randomly generated dummy patient data via [Gitpod](https://gitpod.io/) in a web browser by clicking on this badge: [![Gitpod ready-to-code] + +# DISCLAIMER +This repository contains highly technical content for technical users. It is not a research publication. It has been made public to support the OpenSAFELY [open science and transparency principles] (https://www.opensafely.org/about/#contributing-to-best-practice-around-open-science) and to support the sharing of re-usable code for other subsequent users of the OpenSAFELY platform. +This repository must be interpreted in context: it may reflect the final codebase for a published project; or it may be an incomplete project; or have other shortcomings to be expected of a technical working document shared during development of the work. +Therefore the contents of this repository MUST NOT be considered an accurate or valid representation of the study or its purpose. + +No clinical, policy or safety conclusions must be drawn from the contents of this repository. + +# About the OpenSAFELY framework + +The OpenSAFELY framework is a Trusted Research Environment (TRE) for electronic +health records research in the NHS, with a focus on public accountability and +research quality. + +Read more at [OpenSAFELY.org](https://opensafely.org). + +# Licences +As standard, research projects have a MIT license. diff --git a/analysis/study_definition.py b/analysis/study_definition.py new file mode 100644 index 0000000..3b111d1 --- /dev/null +++ b/analysis/study_definition.py @@ -0,0 +1,13 @@ +from cohortextractor import StudyDefinition, patients, codelist, codelist_from_csv # NOQA + + +study = StudyDefinition( + default_expectations={ + "date": {"earliest": "1900-01-01", "latest": "today"}, + "rate": "uniform", + "incidence": 0.5, + }, + population=patients.registered_with_one_practice_between( + "2019-02-01", "2020-02-01" + ), +) diff --git a/codelists/codelists.json b/codelists/codelists.json new file mode 100644 index 0000000..5cc232f --- /dev/null +++ b/codelists/codelists.json @@ -0,0 +1,3 @@ +{ + "files": {} +} \ No newline at end of file diff --git a/codelists/codelists.txt b/codelists/codelists.txt new file mode 100644 index 0000000..e69de29 diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/docs/.gitkeep @@ -0,0 +1 @@ + diff --git a/logs/.gitkeep b/logs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/output/.gitkeep b/output/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/project.yaml b/project.yaml new file mode 100644 index 0000000..fbdb81b --- /dev/null +++ b/project.yaml @@ -0,0 +1,12 @@ +version: '3.0' + +expectations: + population_size: 1000 + +actions: + + generate_study_population: + run: cohortextractor:latest generate_cohort --output-format csv.gz --study-definition study_definition + outputs: + highly_sensitive: + cohort: output/input.csv.gz