Skip to content

Commit

Permalink
Merge pull request #197 from AberystwythSystemsBiology/feature/admin-…
Browse files Browse the repository at this point in the history
…cart

New feature on admin-cart , and improved sample index, and audit report
  • Loading branch information
KeironO committed May 5, 2022
2 parents 24d3d79 + 6eff046 commit 2e3c777
Show file tree
Hide file tree
Showing 53 changed files with 3,248 additions and 893 deletions.
428 changes: 385 additions & 43 deletions services/web/app/admin/api.py

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions services/web/app/admin/routes/audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
from datetime import datetime
from ..enums import *

from flask import make_response, json
import gzip
from ...sample.routes import compress_response


@admin.route("/audit/index", methods=["GET", "POST"])
@login_required
Expand All @@ -37,18 +41,18 @@ def audit_index():
sites = sites_response.json()["content"]["choices"]

sites.append((99999, "Bots"))
users_by_site = {s[0]: [] for s in sites}
# users_by_site = {s[0]: [] for s in sites}
sites_dict = {s[0]: s[1] for s in sites}

auth_response = requests.get(
url_for("api.auth_home", _external=True),
url_for("api.auth_home_tokenuser", _external=True),
headers=get_internal_api_header(),
)

users = []
if auth_response.status_code == 200:
auth_info = auth_response.json()["content"]

# print("auth_info", auth_info)
for user in auth_info:
if user["site_id"]:
site_id = user["site_id"]
Expand Down Expand Up @@ -81,14 +85,20 @@ def audit_query():

args["start_date"] = start_date
args["end_date"] = end_date
time1 = datetime.now()

audit_response = requests.get(
url_for("api.audit_query", _external=True),
headers=get_internal_api_header(),
json=args,
)

if audit_response.status_code != 200:
abort(audit_response.status_code)
time2 = datetime.now()
td1 = time2 - time1
print("api call audit_query took %0.3f ms" % (td1.microseconds / 1000))

if audit_response.status_code == 200:
return compress_response(audit_response.json())

return audit_response.json()

Expand Down
40 changes: 22 additions & 18 deletions services/web/app/admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class Meta:
reference_id = masql.auto_field()
event = ma.Nested(AuditInfoEventSchema)
protocol_id = masql.auto_field()
# protocol = ma.Nested(BasicProtocolTemplateSchema)
protocol = ma.Nested(BasicProtocolTemplateSchema)
created_on = masql.auto_field()
author = ma.Nested(UserAccountSearchSchema, many=False)
updated_on = masql.auto_field()
Expand Down Expand Up @@ -451,14 +451,14 @@ class Meta:
reduced_quantity = masql.auto_field()
event = ma.Nested(AuditInfoEventSchema)
protocol_id = masql.auto_field()
# protocol = ma.Nested(BasicProtocolTemplateSchema)
protocol = ma.Nested(BasicProtocolTemplateSchema)

created_on = masql.auto_field()
author_id = masql.auto_field
# author = ma.Nested(UserAccountSearchSchema, many=False)
# author_id = masql.auto_field
author = ma.Nested(UserAccountSearchSchema, many=False)
updated_on = masql.auto_field()
editor_id = masql.auto_field
# editor = ma.Nested(UserAccountSearchSchema, many=False)
# editor_id = masql.auto_field
editor = ma.Nested(UserAccountSearchSchema, many=False)
operation_type = masql.auto_field()
transaction_id = masql.auto_field()
end_transaction_id = masql.auto_field()
Expand Down Expand Up @@ -529,54 +529,58 @@ class Meta:

class AuditEntityToStorageSchema(masql.SQLAlchemySchema):
class Meta:
# model = version_class(EntityToStorage)
model = EntityToStorage
model = version_class(EntityToStorage)
# model = EntityToStorage

id = masql.auto_field()
storage_type = EnumField(EntityToStorageType)

rack = ma.Nested(BasicSampleRackSchema, many=False)
shelf = ma.Nested(BasicColdStorageShelfSchema, many=False)
sample_id = masql.auto_field()
# rack_id = masql.auto_field()
# shelf_id = masql.auto_field()
row = masql.auto_field()
col = masql.auto_field()
entry_datetime = masql.auto_field()
entry = masql.auto_field()
removed = masql.auto_field()

created_on = masql.auto_field()
author = ma.Nested(UserAccountSearchSchema, many=False)
updated_on = masql.auto_field()
editor = ma.Nested(UserAccountSearchSchema, many=False)
# operation_type = masql.auto_field() #masql.Enum(Operation, by_value=True)
# transaction_id = masql.auto_field()
# end_transaction_id = masql.auto_field()
operation_type = masql.auto_field() # masql.Enum(Operation, by_value=True)
transaction_id = masql.auto_field()
end_transaction_id = masql.auto_field()
object = fields.Constant("EntityToStorage")


class AuditBasicEntityToStorageSchema(masql.SQLAlchemySchema):
class Meta:
# model = version_class(EntityToStorage)
model = EntityToStorage
model = version_class(EntityToStorage)
# model = EntityToStorage

id = masql.auto_field()
storage_type = EnumField(EntityToStorageType)
rack_id = masql.auto_field()
# rack = ma.Nested(BasicSampleRackSchema, many=False)
shelf_id = masql.auto_field()
# shelf = ma.Nested(BasicColdStorageShelfSchema, many=False)
sample_id = masql.auto_field()
row = masql.auto_field()
col = masql.auto_field()
entry_datetime = masql.auto_field()
entry = masql.auto_field()
removed = masql.auto_field()

created_on = masql.auto_field()
author = ma.Nested(UserAccountSearchSchema, many=False)
updated_on = masql.auto_field()
editor = ma.Nested(UserAccountSearchSchema, many=False)
# operation_type = masql.auto_field()
# transaction_id = masql.auto_field()
# end_transaction_id = masql.auto_field()
operation_type = masql.auto_field()
transaction_id = masql.auto_field()
end_transaction_id = masql.auto_field()
object = fields.Constant("EntityToStorage")


Expand Down Expand Up @@ -770,8 +774,8 @@ class Meta:
remaining_quantity = masql.auto_field()
comments = masql.auto_field()
barcode = masql.auto_field()
sample_to_type_id = masql.auto_field()
# sample_type_information = ma.Nested(SampleTypeSchema)
# sample_to_type_id = masql.auto_field()
sample_type_information = ma.Nested(SampleTypeSchema)

colour = EnumField(Colour, by_value=True)
source = EnumField(SampleSource, by_value=True)
Expand Down
2 changes: 1 addition & 1 deletion services/web/app/api/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_filters_and_joins(args: object, model: object) -> object:

def generate_base_query_filters(tokenuser: UserAccount, type: str):

if tokenuser.account_type.value is "Administrator":
if tokenuser.account_type.value == "Administrator":
return {}, True

else:
Expand Down
1 change: 1 addition & 0 deletions services/web/app/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def login():
user = (
db.session.query(UserAccount)
.filter(func.lower(UserAccount.email) == func.lower(form.email.data))
.filter_by(is_locked=False)
.first()
)

Expand Down
2 changes: 1 addition & 1 deletion services/web/app/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Meta:

id = masql.auto_field()

title = EnumField(Title, by_value=True)
title = EnumField(Title) # , by_value=True)

email = masql.auto_field()
first_name = masql.auto_field()
Expand Down
19 changes: 18 additions & 1 deletion services/web/app/donor/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
new_donor_diagnosis_event_schema,
donor_diagnosis_event_schema,
new_donor_protocol_event_schema,
# donor_protocol_event_info_schema,
# donor_protocol_events_info_schema,
NewDonorProtocolEventSchema,
)

from ...event.views import new_event_schema
Expand All @@ -67,6 +68,22 @@
)


@api.route("/donor/get_study_reference", methods=["GET"])
@use_args(NewDonorProtocolEventSchema(), location="json")
@token_required
def donor_study_reference(args, tokenuser: UserAccount):
study_id = args.pop("protocol_id", None)
reference_id = args.pop("reference_id", None)
refs = (
db.session.query(DonorProtocolEvent)
.filter_by(protocol_id=study_id, reference_id=reference_id)
.all()
)
donor_study_references_schema = NewDonorProtocolEventSchema(many=True)

return success_with_content_response(donor_study_references_schema.dump(refs))


@api.route("/donor")
@token_required
def donor_home(tokenuser: UserAccount):
Expand Down
16 changes: 16 additions & 0 deletions services/web/app/donor/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,28 @@ def validate(self):
)
return False

if len(data["questions"]) == 0:
validate_answers = True
else:
validate_answers = False
for question in data["questions"]:
if self[str(question["id"])].data:
validate_answers = True
break

if not validate_answers:
self.submit.errors.append(
"None of the questions has been checked for consent!!"
)
return False

return True

for question in data["questions"]:
checked = ""
if "checked" in question:
checked = question["checked"]

setattr(
StaticForm,
str(question["id"]),
Expand Down
14 changes: 14 additions & 0 deletions services/web/app/donor/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ def view_endpoint(id):
return response.json()


@donor.route("/get_study_reference", methods=["POST"])
@login_required
def get_study_reference():
response = requests.get(
url_for("api.donor_study_reference", _external=True),
headers=get_internal_api_header(),
json=request.json,
)
if response.status_code == 200:
return response.json()
else:
abort(response.status_code)


# TODO sample to donor association:
# should done by sample basic edit and change the consent form
@donor.route("/LIMBDON-<id>/associate/sample", methods=["GET", "POST"])
Expand Down
Loading

0 comments on commit 2e3c777

Please sign in to comment.