Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

44 create new patient #109

Merged
merged 2 commits into from
Aug 1, 2020
Merged

44 create new patient #109

merged 2 commits into from
Aug 1, 2020

Conversation

priesgo
Copy link
Contributor

@priesgo priesgo commented Aug 1, 2020

Adds endpoint to create individual.

Receives a JSON following the Individual model as payload in the POST request. Authentication credentials are passed in the header instead of encoded in the payload. This makes apparent that we need a better authentication mechanism to avoid passing user and password in every request, we need something like a token created at login time.

Succesful creation returns a JSON as follows:

{
  "id": "PH00008635",
  "message": "Individual was created",
  "success": true
}

The new internal id is based on the assumption that internal ids follow the pattern ^PH\d{8}$. If an id like PH1234 exists it will break this assumption and this endpoint will fail. This may be something to improve.

Error conditions:

  • Demo user is not allowed to post new users
  • Any other payload mimetype than application/json is rejected
  • Empty payload
  • Any field in the JSON not existing in the individual SQLAlchemy model
  • TODO: sanity checks on the individual, eg: sex must be provided

Last this is using SQLAlchemy although we may be moving away from it. The main reason for this is that we have a model in SQLAlchemy that makes parsing the JSON into the DB model easier. If we eventually move away from SQLAlchemy hopefully we will have the database model represented in something else.

@pontikos
Copy link
Contributor

pontikos commented Aug 1, 2020

Thanks @priesgo .
Do we have some code to test this? @alanwilter

@pontikos
Copy link
Contributor

pontikos commented Aug 1, 2020

@YuanTian1991 can you implement the frontend for this please?

The "new patient" button could be in the side-bar. The new patient page can look like the "edit patient" page for now, but in the future will allow uploading of files (e.g genetics, medical imaging etc).

@priesgo
Copy link
Contributor Author

priesgo commented Aug 1, 2020

No, I didn't add any test code. I'll wait for @alanwilter to merge his branch on testing and then I will follow his lead on this.

@pontikos pontikos merged commit bacaa72 into dev-live Aug 1, 2020
@pontikos pontikos deleted the 44-create-new-patient branch August 1, 2020 22:28
alanwilter added a commit that referenced this pull request Aug 2, 2020
@application.route("/update_patient_data/<individual_id>", methods=["POST"])
@requires_auth
def update_patient_data(individual_id, language="en"):
if session["user"] == "demo":
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it's merged already but, just a curiosity, in auth.py you created USER = "user", why that and why it was not used e.g. here?

IsmailM pushed a commit that referenced this pull request Aug 4, 2020
* add endpoint for creating individuals

* make authentication backwards compatible
pontikos pushed a commit that referenced this pull request Aug 4, 2020
* add missing check_auth in change_password

* adding variant search + some refactoring around conversion of results from postgres (#90)

* Code tidy (#97)

* Udated gitignore

* Code tidied after Daniele's suggestions

* Code tidied and improved autocomplete search

* Introducing tox configuration

* Flake8 and Black applied

* Updated tox.ini and created pyproject.toml for Black code formatter

* Files updated by Black new config in pyproject.toml

* Refactored imports from db

* To include Black and Flake8 for Tox

* Commented out _gene_hpo_ids, not used

* 61 consanguinity editing (#101)

* reformat individual.py

* fix the individual update (actually get) + some refactoring around the place

* make good use of postgres API

* black reformatting + excluding some folders from flake8

* controlling none result

* improve search with HGVS, Ensembl ids and HPO ids (#105)

@alanwilter @priesgo we should probably test the suggested search functionality using unit test.  I'm going to merge this now into dev-live for testing on the dev website.

* 44 create new patient (#109)

* add endpoint for creating individuals

* make authentication backwards compatible

* add endpoint to create users (#114)

* add 404s to individuals endpoints (#113)

* add 404s to individuals endpoints

* blackened

* 89 create new user individuals (#116)

* add endpoint to post user_individuals

* blackened

* add limit to the autocomplete query + change query type to a query param + remove best guess endpoint

* blackened

Co-authored-by: IsmailM <ismail.moghul@gmail.com>
Co-authored-by: Alan <alanwilter@gmail.com>
pontikos added a commit that referenced this pull request Aug 8, 2020
* add missing check_auth in change_password

* adding variant search + some refactoring around conversion of results from postgres (#90)

* Code tidy (#97)

* Udated gitignore

* Code tidied after Daniele's suggestions

* Code tidied and improved autocomplete search

* Introducing tox configuration

* Flake8 and Black applied

* Updated tox.ini and created pyproject.toml for Black code formatter

* Files updated by Black new config in pyproject.toml

* Refactored imports from db

* To include Black and Flake8 for Tox

* Commented out _gene_hpo_ids, not used

* 61 consanguinity editing (#101)

* reformat individual.py

* fix the individual update (actually get) + some refactoring around the place

* make good use of postgres API

* black reformatting + excluding some folders from flake8

* controlling none result

* improve search with HGVS, Ensembl ids and HPO ids (#105)

@alanwilter @priesgo we should probably test the suggested search functionality using unit test.  I'm going to merge this now into dev-live for testing on the dev website.

* 44 create new patient (#109)

* add endpoint for creating individuals

* make authentication backwards compatible

* add endpoint to create users (#114)

* add 404s to individuals endpoints (#113)

* add 404s to individuals endpoints

* blackened

* 89 create new user individuals (#116)

* add endpoint to post user_individuals

* blackened

* PyTest at last (#117)

* Updated Demo DB to comply with pytest, also see issue #93

* Port 5432 (postgres) need to be open for pytest to work on docker DB app

* PG DB needs to be 'phenopolis_db' for pytest to work with docker

* Added comments, flake8 and blackened

* CRITICAL: can only go ahead together with frontend issue #160

* Removed duplicated query_user_config()

* New tests, using PyTest, at last, yet no 100% coverage yet

* Commented out _get_hpo_ids_per_gene(), not used

* copy config from admin user for new users (#118)

* Updated tests after PR #118 (#119)

* Update requirements.txt (#120)

Add dotenv to run tests.

* Fix db (#121)

* Updated tests after PR #118

* Fixed a bug in DB:variant_pos_text_pattern_idx

* Debugging for query_type searching.

* Added a ugly function _search_variants_by_match_name to do pure string matching.

* Removed Partial Match for Variant, changed return results.

* Fix regex typo raised by Alan, but did NOT do pytest yet

Co-authored-by: IsmailM <ismail.moghul@gmail.com>
Co-authored-by: Pablo Riesgo Ferreiro <priesgoferreiro@gmail.com>
Co-authored-by: Alan <alanwilter@gmail.com>
Co-authored-by: Nikolas Pontikos <n.pontikos@gmail.com>
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