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

Adding Data and Bio Consent through DB #476

Merged
merged 78 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
f229de7
consent Table and consent audit changes
raginirai553 Oct 15, 2022
874fc89
Merge pull request #1 from biocore/master-overhaul
raginirai553 Oct 15, 2022
1662f67
Merge https://github.com/raginirai553/microsetta-private-api
raginirai553 Oct 15, 2022
0aa8c7a
merge
raginirai553 Oct 15, 2022
0f26255
updating fork for cassidy to check
ragini7913 Oct 18, 2022
c346c65
onsent changes
ragini7913 Oct 23, 2022
cb17a0c
remove debug commands
ragini7913 Oct 23, 2022
19b48fb
fixing lint error
ragini7913 Oct 23, 2022
2a5c9c7
test whitespace lint error
ragini7913 Oct 23, 2022
d1f66a4
remove debug lines
ragini7913 Oct 23, 2022
4dd37b9
test consent changes
ragini7913 Oct 23, 2022
524e29c
fixing integration test
ragini7913 Oct 24, 2022
54531a4
testing unit test
ragini7913 Oct 24, 2022
96a82f3
Debug to test workflow
ragini7913 Oct 24, 2022
5264db1
Debug#1, consent_type fix
ragini7913 Oct 25, 2022
ddd44bd
remove whitespace, debug#2
ragini7913 Oct 25, 2022
64890c4
debug#3
ragini7913 Oct 25, 2022
7825ee5
debug#4
ragini7913 Oct 25, 2022
ba42464
print all stages for debug
ragini7913 Oct 25, 2022
25085ae
update sample consent doc in db, debug#5
ragini7913 Oct 25, 2022
0532caa
DD DUMMY ACCNT/DOC FOR CONSENT TABLE
ragini7913 Oct 25, 2022
1290efd
fix patch
ragini7913 Oct 25, 2022
c7ea6f5
test consent doc integration testing
ragini7913 Oct 26, 2022
be2fa5b
debug
ragini7913 Oct 26, 2022
d47226c
debug for db patch
ragini7913 Oct 26, 2022
910e821
correct dummy accnt info
ragini7913 Oct 26, 2022
b8a964c
Resolved consent doc tests error
ragini7913 Oct 26, 2022
1fa2540
Consent Test Issues Resolved!
ragini7913 Oct 26, 2022
5307d83
removing debug commands
ragini7913 Oct 26, 2022
7f91760
Cleaned Test codes!
ragini7913 Oct 26, 2022
051d22b
removign remainign debug commands
ragini7913 Oct 26, 2022
8ab9860
added unit test cases for the repo logic and minor recommended change
ragini7913 Oct 28, 2022
e61d275
Merge pull request #2 from biocore/master-overhaul
raginirai553 Oct 28, 2022
499c4fe
committ changes
ragini7913 Oct 29, 2022
e7d1892
dd test consent file
ragini7913 Oct 29, 2022
675a461
Merge https://github.com/raginirai553/microsetta-private-api
ragini7913 Oct 29, 2022
e665fa0
commit test cases
ragini7913 Oct 30, 2022
f6d6308
update tear down to scrub instead delete source/account
ragini7913 Oct 30, 2022
4d1e54d
Fix lint errors
ragini7913 Oct 31, 2022
365d6e1
debug for integration test failure
ragini7913 Oct 31, 2022
7ec4132
debug integration test#2
ragini7913 Nov 1, 2022
05f9f9b
debug#3
ragini7913 Nov 1, 2022
97e7436
fix accnt id
ragini7913 Nov 1, 2022
9a5bf75
add dummy consent doc for consent tests
ragini7913 Nov 1, 2022
ef18513
Debug #4
ragini7913 Nov 1, 2022
00fcaf6
Consent Tests Debug
ragini7913 Nov 1, 2022
081da71
Consent Debug
ragini7913 Nov 1, 2022
57121ff
Debug Account Error In Consent
ragini7913 Nov 1, 2022
2d161a5
Consent Error Debug
ragini7913 Nov 1, 2022
3ae0960
add the source scrub route and test
ragini7913 Nov 1, 2022
af4e609
Delete .DS_Store
raginirai553 Nov 1, 2022
b183f5e
Delete .DS_Store
raginirai553 Nov 1, 2022
d85e70b
fix test_Scrub
ragini7913 Nov 1, 2022
739d653
Merge branch 'master' of https://github.com/raginirai553/microsetta-p…
ragini7913 Nov 1, 2022
ef0ef77
test Scrub 500 internal erro
ragini7913 Nov 1, 2022
07a920e
debug scrub source
ragini7913 Nov 1, 2022
2b9bc29
change dummy data for accnt
ragini7913 Nov 1, 2022
622a20a
scrub test fixed
ragini7913 Nov 1, 2022
73d6cde
scrub test
ragini7913 Nov 1, 2022
ae6a0ac
Scrub Test Debug
ragini7913 Nov 1, 2022
f6b95c4
add new token for scrub test
ragini7913 Nov 1, 2022
d3f007b
update auth token
ragini7913 Nov 1, 2022
eee31de
scrub assertion error
ragini7913 Nov 1, 2022
34fbf30
test
ragini7913 Nov 1, 2022
0643eea
debug internal error
ragini7913 Nov 1, 2022
ca20e70
test teardown
ragini7913 Nov 1, 2022
e275a3a
fix lint error final
ragini7913 Nov 1, 2022
8e6c792
remove DS_Store
ragini7913 Nov 2, 2022
675aec8
djusting api for scrub http method
ragini7913 Nov 3, 2022
07c9151
Fix lint error
ragini7913 Nov 3, 2022
363a42f
add new patch to insert consent content
ragini7913 Nov 9, 2022
f2e3ce4
update patch filename and merge, resolve conflict in pullmerge
ragini7913 Nov 9, 2022
d7100f9
update test api to debug merge error
ragini7913 Nov 9, 2022
efcb076
address PR comments
ragini7913 Nov 10, 2022
f6b5e3b
fix lint error
ragini7913 Nov 10, 2022
53cae2b
address final PR comments
ragini7913 Nov 10, 2022
9808dcc
rename patch file 0106 to 0105
ragini7913 Nov 11, 2022
06821bc
rename patch file to resolve conflict
ragini7913 Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion microsetta_private_api/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
)
from ._consent import (
render_consent_doc,
check_consent_signature,
sign_consent_doc
)
from ._source import (
create_source, read_source, update_source, delete_source,
read_sources, create_human_source_from_consent,
check_duplicate_source_name
check_duplicate_source_name, scrub_source
)
from ._survey import (
read_survey_template, read_survey_templates, read_answered_survey,
Expand Down Expand Up @@ -71,9 +73,12 @@
'read_source',
'update_source',
'delete_source',
'scrub_source',
'read_sources',
'check_duplicate_source_name',
'create_human_source_from_consent',
'check_consent_signature',
'sign_consent_doc',
'read_survey_template',
'read_survey_templates',
'read_answered_survey',
Expand Down
65 changes: 60 additions & 5 deletions microsetta_private_api/api/_consent.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,73 @@
from flask import jsonify

import uuid
from microsetta_private_api import localization
from microsetta_private_api.api._account import \
_validate_account_access
from microsetta_private_api.model.consent import ConsentSignature
from microsetta_private_api.repo.consent_repo import ConsentRepo
from microsetta_private_api.repo.transaction import Transaction
from microsetta_private_api.api.literals import CONSENT_DOC_NOT_FOUND_MSG


def render_consent_doc(account_id, language_tag, token_info):
_validate_account_access(token_info, account_id)

# NB: Do NOT need to explicitly pass account_id into template for
# integration into form submission URL because form submit URL builds on
# the base of the URL that called it (which includes account_id)
consent_form = {}

localization_info = localization.LANG_SUPPORT[language_tag]
content = localization_info[localization.NEW_PARTICIPANT_KEY]
consent_form["PARTICIPANT_FORM"] = content

with Transaction() as t:
consent_repo = ConsentRepo(t)
documents = consent_repo.get_all_consent_documents(language_tag)
data = [x.to_api() for x in documents]
consent_form["CONSENT_DOCS"] = data

return jsonify(consent_form), 200


def get_consent_doc(account_id, consent_id, token_info):
_validate_account_access(token_info, account_id)

with Transaction() as t:
consent_repo = ConsentRepo(t)
document = consent_repo.get_consent_document(consent_id)

if document:
data = document.to_api()
return jsonify(data), 200
else:
return jsonify(code=404, message=CONSENT_DOC_NOT_FOUND_MSG), 404


def check_consent_signature(account_id, source_id, consent_type, token_info):
_validate_account_access(token_info, account_id)

with Transaction() as t:
consent_repo = ConsentRepo(t)
res = consent_repo.is_consent_required(source_id, consent_type)

return jsonify({"result": res}), 200


def sign_consent_doc(account_id, source_id, consent_type, body, token_info):
cassidysymons marked this conversation as resolved.
Show resolved Hide resolved

_validate_account_access(token_info, account_id)

with Transaction() as t:
consent_repo = ConsentRepo(t)
sign_id = str(uuid.uuid4())
consent_sign = ConsentSignature.from_dict(body, source_id, sign_id)
try:
consent_repo.sign_consent(account_id, consent_sign)
t.commit()
except Exception:
return jsonify(code=404, message=CONSENT_DOC_NOT_FOUND_MSG), 404

response = jsonify({"result": True})
response.status_code = 201
response.headers['Location'] = '/api/accounts/%s' % \
(account_id)

return jsonify(content), 200
return response
43 changes: 42 additions & 1 deletion microsetta_private_api/api/_source.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import uuid
from datetime import date

from flask import jsonify

from microsetta_private_api.api._account import _validate_account_access
from microsetta_private_api.api.literals import SRC_NOT_FOUND_MSG
from microsetta_private_api.exceptions import RepoException
from microsetta_private_api.model.source import Source, HumanInfo, NonHumanInfo
from microsetta_private_api.repo.source_repo import SourceRepo
from microsetta_private_api.repo.consent_repo import ConsentRepo
from microsetta_private_api.repo.sample_repo import SampleRepo
from microsetta_private_api.repo.survey_answers_repo import SurveyAnswersRepo
from microsetta_private_api.repo.transaction import Transaction

Expand Down Expand Up @@ -109,20 +110,60 @@ def delete_source(account_id, source_id, token_info):
with Transaction() as t:
source_repo = SourceRepo(t)
survey_answers_repo = SurveyAnswersRepo(t)
consent_repo = ConsentRepo(t)
samp_repo = SampleRepo(t)

samples = samp_repo.get_samples_by_source(account_id, source_id)
for sample in samples:
# we scrub rather than disassociate in the event that the
# sample is in our freezers but not with an up-to-date scan
samp_repo.dissociate_sample(account_id, source_id, sample.id)

answers = survey_answers_repo.list_answered_surveys(account_id,
source_id)
for survey_id in answers:
survey_answers_repo.delete_answered_survey(account_id,
survey_id)

# delete all consents accosiated with source
consent_repo.delete_signatures(account_id, source_id)

if not source_repo.delete_source(account_id, source_id):
return jsonify(code=404, message=SRC_NOT_FOUND_MSG), 404
# TODO: 422?
t.commit()
return '', 204


def scrub_source(account_id, source_id, token_info):
_validate_account_access(token_info, account_id)

with Transaction() as t:
source_repo = SourceRepo(t)
consent_repo = ConsentRepo(t)
samp_repo = SampleRepo(t)
sur_repo = SurveyAnswersRepo(t)

samples = samp_repo.get_samples_by_source(account_id, source_id)
for sample in samples:
# we scrub rather than disassociate in the event that the
# sample is in our freezers but not with an up-to-date scan
samp_repo.scrub(account_id, source_id, sample.id)

# fetch and scrub all surveys
surveys = sur_repo.list_answered_surveys(account_id, source_id)
for survey_id in surveys:
sur_repo.scrub(account_id, source_id, survey_id)

# scrub all consents accosiated with source
consent_repo.scrub(account_id, source_id)

# scrub the source
source_repo.scrub(account_id, source_id)
t.commit()
return jsonify({"result": True}), 200


def create_human_source_from_consent(account_id, body, token_info):
_validate_account_access(token_info, account_id)

Expand Down
1 change: 1 addition & 0 deletions microsetta_private_api/api/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
ACCT_NOT_FOUND_MSG = "Account not found"
SRC_NOT_FOUND_MSG = "Source not found"
INVALID_TOKEN_MSG = "Invalid token"
CONSENT_DOC_NOT_FOUND_MSG = "Consent not found"
Loading