Skip to content

Commit

Permalink
Merge pull request #238 from AberystwythSystemsBiology/feature/csv-im…
Browse files Browse the repository at this point in the history
…port1

Feature/csv import1
  • Loading branch information
KeironO authored Dec 8, 2022
2 parents 2fde349 + 9128afa commit 9cb48eb
Show file tree
Hide file tree
Showing 17 changed files with 750 additions and 160 deletions.
101 changes: 101 additions & 0 deletions services/web/app/sample/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@
SampleConsent,
DonorToSample,
SampleToCustomAttributeData,
TemporaryStore,
)

from ..views import (
new_fluid_sample_schema,
new_cell_sample_schema,
new_molecular_sample_schema,
new_sample_protocol_event_schema,
sample_protocol_event_schema,
)
from ...tmpstore.views import new_store_schema
from ..enums import SampleSource


Expand Down Expand Up @@ -540,6 +543,104 @@ def func_deep_remove_subsampletosample_children(
return (success, msgs)


def func_root_sample_acquision_protocol_event(sample_id):
sample = Sample.query.filter_by(id=sample_id).first()
pe_acq = None
if sample is None:
success = False
msg = "Sample (id=%d) not found" % sample_id
return pe_acq, msg

while sample.source != "NEW":
sample = SubSampleToSample.query.filter_by(subsample_id=sample.id).first()
if sample is None:
success = False
msg = "Root sample (id=%d) not found" % sample_id
return pe_acq, msg

pe_acq = SampleProtocolEvent.query.filter_by(sample_id=sample.id).join(
ProtocolTemplate, ProtocolTemplate.type == "ACQ"
)

if pe_acq is None:
msg = "Root sample (id=%d) acquisition event found!" % sample.id
else:
msg = "Root sample acquisition event found!"
return pe_acq, msg


# def func_update_sample_tmpstore_info(uuid=None, sample=None, tokenuser: UserAccount):
# # Update temporarystore
# if uuid:
# if sample is None:
# sample = Sample.query.filter_by(uuid=uuid).first()
# elif sample.uuid != uuid:
# return {"success": False, "message": "sample and uuid not matched!"}
# elif not sample:
# return not_found("Sample object or uuid!")
# else:
# uuid = sample.uuid
#
# # Update sample collection date
# pe_acq, msg = func_root_sample_acquision_protocol_event(sample.id)
# if not pe_acq:
# return not_found("Sample acquisition event for sample %s" %uuid)
#
# info = sample_protocol_event_schema.dump(pe_acq)
# return info

# @api.route("/sample/<uuid>/extra", methods=["DELETE", "GET", "POST"])
# @token_required
# def sample_update_sample_tmpstore_info(uuid: str, tokenuser: UserAccount):
# # if uuid:
# # if sample is None:
# # sample = Sample.query.filter_by(uuid=uuid).first()
# # elif sample.uuid != uuid:
# # return {"success": False, "message": "sample and uuid not matched!"}
# # elif not sample:
# # return not_found("Sample object or uuid!")
# # else:
# # uuid = sample.uuid
# if uuid:
# sample = Sample.query.filter_by(uuid=uuid).first()
# if not sample:
# return not_found("sample %s " % uuid)
#
# tmpstore = temporarystore.query.filter_by(uuid=uuid, type='smp').first()
# if tmpstore:
# # Update entry
# tmpstore.data["root_sample_collection_date"] = info
# tmpstore.update({"editor_id": tokenuser.id})
# else:
# # new entry
# values = {}
# values["uuid"] = uuid
# values["type"] = 'smp'
#
# try:
# result = new_store_schema.load(values)
# except ValidationError as err:
# return validation_error_response(err)
#
# tmpstore = TemporaryStore(**result)
# tmpstore.author_id = tokenuser.id
#
# return {"success": True, "tempstore": tmpstore}
#
# (success, msgs) = func_remove_sample(sample, tokenuser, [])
# if not success:
# return msgs[-1]
#
# try:
# db.session.commit()
# msgs.append("Committed successfully!")
# message = " | ".join(msgs)
# return success_with_content_message_response(uuid, message)
# except Exception as err:
# db.session.rollback()
# return transaction_error_response(err)


@api.route("/sample/<uuid>/remove", methods=["DELETE", "GET", "POST"])
@token_required
def sample_remove_sample(uuid: str, tokenuser: UserAccount):
Expand Down
7 changes: 6 additions & 1 deletion services/web/app/sample/routes/shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ def shipment_new_step_one():
sites_ext = [[0, "None"]]

sites_response = requests.get(
url_for("api.site_home", _external=True), headers=get_internal_api_header()
url_for("api.site_home", _external=True),
headers=get_internal_api_header(),
)
external_sites_response = requests.get(
url_for("api.site_external_home", _external=True),
Expand All @@ -313,6 +314,8 @@ def shipment_new_step_one():
addresses = {}
if external_sites_response.status_code == 200:
for site in external_sites_response.json()["content"]:
if site["is_locked"]:
continue
sites_ext.append(
[site["id"], "LIMBSIT-%i: %s" % (site["id"], site["name"])]
)
Expand All @@ -322,6 +325,8 @@ def shipment_new_step_one():

if sites_response.status_code == 200:
for site in sites_response.json()["content"]:
if site["is_locked"]:
continue
sites.append([site["id"], "LIMBSIT-%i: %s" % (site["id"], site["name"])])
address = site["address"]
addresses[site["id"]] = [[address["id"], address_label(address)]]
Expand Down
4 changes: 2 additions & 2 deletions services/web/app/static/js/donor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function calc_age(date0, date1) {
date0 = new Date(date0 + "Z");
date1 = new Date(date1 + "Z");
var timeDiff = Math.abs(date0.getTime() - date1.getTime());
var age = Math.ceil(timeDiff / (1000 * 3600 * 24)/ 365);
var age = Math.floor(timeDiff / (1000 * 3600 * 24)/ 365.25);
return age;
}

Expand All @@ -62,7 +62,7 @@ function render_table(query) {
buttons: [ 'print', 'csv', 'colvis' ],
columnDefs: [
{targets: '_all', defaultContent: '-'},
{targets: [2, 3, 4, 6, 7, 12, 13, 16], visible: false, "defaultContent": "-"},
{targets: [0, 2, 3, 4, 6, 7, 12, 13, 16], visible: false, "defaultContent": "-"},
//{width: 200, targets: 6 }
],
//fixedColumns: true,
Expand Down
10 changes: 9 additions & 1 deletion services/web/app/static/js/donor/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function fill_sample_table(samples) {

columnDefs: [
{targets: '_all', defaultContent: ''},
{targets: [2, 3, 6], visible: false, "defaultContent": ""},
{targets: [2, 3, 6, 11], visible: false, "defaultContent": ""},
{
targets: -1,
orderable: false,
Expand Down Expand Up @@ -207,6 +207,14 @@ function fill_sample_table(samples) {
}
},

{
"mData": {},
"mRender": function (data, type, row) {
//console.log("--", data)
return data["collected_on"];
}
},

{
"mData": {},
"mRender": function (data, type, row) {
Expand Down
3 changes: 2 additions & 1 deletion services/web/app/static/js/sample/aliquot/derive.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ function generate_container_select(indx) {
return select_html;
}


function generate_fixation_select(indx) {
var cbt = containerbasetypes[0][0]; //"PRM"
var fixation_list = containertypes[cbt]["fixation_type"];
Expand Down Expand Up @@ -463,7 +464,7 @@ function make_new_form(indx) {
lastvals = {sample_basetype: $("#samplebasetype_select_"+ indx).val(),
sample_type: $("#sampletype_select_"+ indx).val(),
container_basetype: $("#containerbasetype_select_"+indx).val(),
container_type: $("#containertye_select_" + indx).val(),
container_type: $("#containertype_select_" + indx).val(),
volume: $("#volume_" + indx).val()
}

Expand Down
32 changes: 28 additions & 4 deletions services/web/app/static/js/storage/rack/sampletorack_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,9 @@ function dragndrop_rack_view() {
$("#submit_sampletorack").fadeTo(1000, 0.3, function() { $(this).fadeTo(500, 1.0); });
$("#submit_sampletorack").show();



var dispopt = $("input[name='dispopt']:checked").val();
var changed = [];

document.ondragstart = function (event) {
//event.dataTransfer.setData("text/plain", event.target.id);
event.dataTransfer.setData('target_id', event.target.id);
Expand Down Expand Up @@ -814,6 +813,15 @@ $(document).ready(function () {
var new_rack = false;
}

if ("update_storage" in sampletostore) {
var update_storage = sampletostore["update_storage"];
} else {
var update_storage = true;
}

if (update_storage == false) {
$("#submit_sampletorack").text("Update Sample in Rack");
}

$("input[id='qr_on']").attr('hidden', true);

Expand All @@ -829,17 +837,21 @@ $(document).ready(function () {
render_subtitle(rack_information);
render_information(rack_information);
}


var dispopt = $("input[name='dispopt']:checked").val();

if (from_file==true) {
//console.log("rack_information[view]", rack_information["view"]);
var samples = render_view_from_file(rack_information["view"],
rack_information["_links"]["assign_sample"], dispopt);

} else {
var samples = render_view(rack_information["view"],
rack_information["_links"]["assign_sample"], dispopt);
}


$("input[name='dispopt']").change(function(){
var dispopt = $("input[name='dispopt']:checked").val();
$("#view_area").empty()
Expand All @@ -855,8 +867,9 @@ $(document).ready(function () {
render_sample_table(samples);


if (from_file==true)
if (from_file == true) {
$("#cancel_change").show();
}
else {
$("#cancel_change").show();
dragndrop_rack_view();
Expand All @@ -874,8 +887,12 @@ $(document).ready(function () {

});

if (update_storage) {
alert("Note: Please check the storage info before pressing STORE-SAMPLE-TO-RACK button to confirm!!")
} else {
alert("Note: Please check the storage info before pressing UPDATE-SAMPLE-IN-RACK button to confirm!!")
}

alert("Note: Please check the storage info before pressing STORE-SAMPLE-TO-RACK button to confirm!!")

$("#submit_sampletorack").click(function (event) {
if (from_file) {
Expand All @@ -884,6 +901,13 @@ $(document).ready(function () {

else
var api_url = window.location.origin + "/storage/rack/refill_with_samples";

if (update_storage) {
var api_url = window.location.origin + "/storage/rack/refill_with_samples";
} else {
var api_url = window.location.origin + "/storage/rack/update_sample_info";
}

}
else if (!update_only)
var api_url = window.location.origin + "/storage/rack/fill_with_samples"
Expand Down
5 changes: 5 additions & 0 deletions services/web/app/static/js/storage/rack/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ $(document).ready(function () {
var sampletostore = fill_sample_pos(api_url, rack_id, {}, commit=false)
})

$("#update-sample-from-file-btn").click(function() {
var api_url = window.location.href = rack_information["_links"]["update_sample_info"];
var sampletostore = fill_sample_pos(api_url, rack_id, {}, commit=false)
})

$("#loading-screen").fadeOut();
$("#content").delay(500).fadeIn();

Expand Down
Loading

0 comments on commit 9cb48eb

Please sign in to comment.