Skip to content

Commit

Permalink
Added only recorded in optional type of samples and save opt values a…
Browse files Browse the repository at this point in the history
…s names
  • Loading branch information
luissian committed Jul 28, 2023
1 parent d8390e7 commit 35d1ee6
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 59 deletions.
5 changes: 5 additions & 0 deletions conf/0002_core_migration_v2.3.1.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ class Migration(migrations.Migration):
verbose_name="Species",
),
),
migrations.AlterField(
model_name="sampletype",
name="optional_fields",
field=models.CharField(blank=True, max_length=300, null=True),
),
migrations.AlterModelTable(
name="commercialkits",
table="core_commercial_kits",
Expand Down
5 changes: 3 additions & 2 deletions core/core_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"Date sample reception",
"Collection Sample Date",
"Sample Storage Location",
"Only recorded",
]

HEADING_FOR_DISPLAY_RECORDED_SAMPLES = [
Expand Down Expand Up @@ -288,9 +289,9 @@
SUCCESSFUL_JSON_SCHEMA = ["Json schema was loaded successfully"]
# #################### ERROR MESSAGES #####################
ERROR_TYPE_OF_SAMPLE_EXISTS = ["Type of sample is already recorded"]
ERROR_TYPE_OF_SAMPLE_ID_DOES_NOT_EXISTS = [
ERROR_TYPE_OF_SAMPLE_ID_DOES_NOT_EXISTS = (
"The type of sample that you request does not exist"
]
)
ERROR_MOLECULE_USE_FOR_EXISTS = ["Molecule use has been already recorded"]

ERROR_SPECIES_ALREADY_DEFINED = ["Species name is already defined"]
Expand Down
4 changes: 2 additions & 2 deletions core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def create_sample_type(self, sample_type_data):
class SampleType(models.Model):
sample_type = models.CharField(max_length=50)
apps_name = models.CharField(max_length=50)
optional_fields = models.CharField(max_length=50, null=True, blank=True)
optional_fields = models.CharField(max_length=300, null=True, blank=True)
generated_at = models.DateTimeField(auto_now_add=True, null=True)

class Meta:
Expand All @@ -415,7 +415,7 @@ def get_optional_values(self):
if self.optional_fields == "" or self.optional_fields is None:
return []
else:
return list(map(int, self.optional_fields.split(",")))
return self.optional_fields.split(",")

objects = SampleTypeManager()

Expand Down
30 changes: 10 additions & 20 deletions core/utils/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,15 +1469,11 @@ def get_type_of_sample_information(sample_type_id):
sample_type_obj = core.models.SampleType.objects.get(pk__exact=sample_type_id)
opt_list = sample_type_obj.get_optional_values()
sample_type_data["sample_type_name"] = sample_type_obj.get_name()
for i in range(len(core.core_config.HEADING_FOR_RECORD_SAMPLES)):
if i in opt_list:
sample_type_data["optional_data"].append(
[core.core_config.HEADING_FOR_RECORD_SAMPLES[i], "Not Required"]
)
for field in core.core_config.HEADING_FOR_RECORD_SAMPLES:
if field in opt_list:
sample_type_data["optional_data"].append([field, "Not Required"])
else:
sample_type_data["optional_data"].append(
[core.core_config.HEADING_FOR_RECORD_SAMPLES[i], "Mandatory"]
)
sample_type_data["optional_data"].append([field, "Mandatory"])
else:
sample_type_data[
"ERROR"
Expand Down Expand Up @@ -1909,27 +1905,21 @@ def save_type_of_sample(form_data, app_name):
save_s_type
"""
save_s_type = {}
optional_index_field_list = []
optional_fields = []
if core.models.SampleType.objects.filter(
sample_type__exact=form_data["sampleTypeName"], apps_name__exact=app_name
).exists():
save_s_type["ERROR"] = core.core_config.ERROR_TYPE_OF_SAMPLE_EXISTS
return save_s_type
# select the optional fields and get the indexes
for field in core.core_config.HEADING_FOR_RECORD_SAMPLES:
if (
field not in form_data
and field in core.core_config.HEADING_FOR_OPTIONAL_FIELD_SAMPLES
):
optional_index_field_list.append(
str(core.core_config.HEADING_FOR_RECORD_SAMPLES.index(field))
)
# add only recorded as always optional
optional_index_field_list.append("9")
for field in core.core_config.HEADING_FOR_OPTIONAL_FIELD_SAMPLES:
if field not in form_data:
optional_fields.append(field)

data = {}
data["sampleType"] = form_data["sampleTypeName"]
data["apps_name"] = app_name
data["optional_fields"] = ",".join(optional_index_field_list)
data["optional_fields"] = ",".join(optional_fields)
# Store in database
sample_type_obj = core.models.SampleType.objects.create_sample_type(data)
save_s_type = {}
Expand Down
2 changes: 1 addition & 1 deletion wetlab/templates/wetlab/define_type_of_samples.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
</div>
{% endfor %}
</div>
<p class="mt-2"> Fields marked with <FONT COLOR="Red">*</FONT> are mandatory</p>
<p class="mt-2"> Fields marked in <FONT COLOR="Red">Red</FONT> are mandatory</p>
<input class="btn float-end btn-outline-primary mb-2 me-2" type="submit" value="Submit" id="btnSubmit">
</form>
</div>
Expand Down
76 changes: 42 additions & 34 deletions wetlab/templates/wetlab/display_type_of_sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,49 @@
{% include "wetlab/menu.html" %}
{% include 'registration/login_inline.html' %}
<section class="iskylims">
{% if sample_types.error_message %}
<div class="row my-2">
<div class="col-sm-6 offset-2" >
<div class="card border-danger mb-3">
<div class="card-header text-danger"><h3>Unable to display your Sample Type</h3> </div>
<div class="card-body">
<p>
{% for value in sample_types.ERROR %}
{{ value }} <br>
{% endfor %}
</p>
</div>
<div class="container-md">
{% if error_message %}
<div class="row my-2">
<div class="col-sm-6 offset-2" >
<div class="card border-danger mb-3">
<div class="card-header text-danger"><h3>Unable to display your Sample Type</h3> </div>
<div class="card-body">
<p> {{ error_message }}</p>
</div>
</div>
</div>
</div>
{% else %}
<div class="row my-2 justify-content-center">
<div class="col-md-6">
<div class="card ">
<div class="card-header text-center"><h3>Type of Sample : {{type_of_sample_data.sample_type_name}}</h3> </div>
<div class="card-body">
<p>Information below describes which fields are set to mandatory when recording samples</p>
<div class="row mt-3">
<div class="col-md-6">
<h5 class="text-center">Field name</h5>
</div>
<div class="col-md-6">
<h5 class="float-end">Mandatory</h5>
</div>
</div>

{% for field, requested in type_of_sample_data.optional_data %}
<div class="form-check form-switch col mb-2">
<label class="form-check-label form-label" for="{{field}}">{{field}}</label>
{% if requested == 'Mandatory' %}
<input class="form-check-input float-end" type="checkbox" checked disabled>
{% else %}
<input class="form-check-input float-end" type="checkbox" disabled>
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
</div>
</div>
{% endif %}
<div class="row my-2">
<div class="col-sm-4 offset-4" >
<div class="card ">
<div class="card-header"><h3 style="text-align:center">Type of Sample : {{type_of_sample_data.sample_type_name}}</h3> </div>
<div class="card-body">
<p>Information below describes which fields are mandatory or optional when recording new sample</p>
{% for field, requested in type_of_sample_data.optional_data %}
<div class="form-check form-switch col mb-2">
<label class="form-check-label form-label" for="{{field}}">{{field}}</label>
{% if requested == 'Mandatory' %}
<input class="form-check-input float-end" type="checkbox" checked disabled>
{% else %}
<input class="form-check-input float-end" type="checkbox" disabled>
{% endif %}
</div>
{% endfor %}
</div>
</div>
</div>
</div>
{% endif %}
</div>
</section>
{% endblock %}
6 changes: 6 additions & 0 deletions wetlab/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,12 @@ def display_type_of_sample(request, sample_type_id):
type_of_sample_data = core.utils.samples.get_type_of_sample_information(
sample_type_id
)
if "ERROR" in type_of_sample_data:
return render(
request,
"wetlab/display_type_of_sample.html",
{"error_message": type_of_sample_data["ERROR"]},
)
return render(
request,
"wetlab/display_type_of_sample.html",
Expand Down

0 comments on commit 35d1ee6

Please sign in to comment.