From 35d1ee6d8be55e4862c2996f22c93c1fd14e9393 Mon Sep 17 00:00:00 2001 From: luissian Date: Fri, 28 Jul 2023 15:56:18 +0200 Subject: [PATCH] Added only recorded in optional type of samples and save opt values as names --- conf/0002_core_migration_v2.3.1.py | 5 ++ core/core_config.py | 5 +- core/models.py | 4 +- core/utils/samples.py | 30 +++----- .../wetlab/define_type_of_samples.html | 2 +- .../wetlab/display_type_of_sample.html | 76 ++++++++++--------- wetlab/views.py | 6 ++ 7 files changed, 69 insertions(+), 59 deletions(-) diff --git a/conf/0002_core_migration_v2.3.1.py b/conf/0002_core_migration_v2.3.1.py index 3560a58de..67241e1b7 100644 --- a/conf/0002_core_migration_v2.3.1.py +++ b/conf/0002_core_migration_v2.3.1.py @@ -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", diff --git a/core/core_config.py b/core/core_config.py index 9d986de27..ae07341e0 100644 --- a/core/core_config.py +++ b/core/core_config.py @@ -20,6 +20,7 @@ "Date sample reception", "Collection Sample Date", "Sample Storage Location", + "Only recorded", ] HEADING_FOR_DISPLAY_RECORDED_SAMPLES = [ @@ -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"] diff --git a/core/models.py b/core/models.py index 666bf1a12..15edb4f5e 100644 --- a/core/models.py +++ b/core/models.py @@ -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: @@ -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() diff --git a/core/utils/samples.py b/core/utils/samples.py index 4b4f0b89d..f38ff9b45 100644 --- a/core/utils/samples.py +++ b/core/utils/samples.py @@ -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" @@ -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 = {} diff --git a/wetlab/templates/wetlab/define_type_of_samples.html b/wetlab/templates/wetlab/define_type_of_samples.html index f5be6735a..4466b0461 100644 --- a/wetlab/templates/wetlab/define_type_of_samples.html +++ b/wetlab/templates/wetlab/define_type_of_samples.html @@ -59,7 +59,7 @@ {% endfor %} -

Fields marked with * are mandatory

+

Fields marked in Red are mandatory

diff --git a/wetlab/templates/wetlab/display_type_of_sample.html b/wetlab/templates/wetlab/display_type_of_sample.html index 53fcc3576..357e2b407 100644 --- a/wetlab/templates/wetlab/display_type_of_sample.html +++ b/wetlab/templates/wetlab/display_type_of_sample.html @@ -4,41 +4,49 @@ {% include "wetlab/menu.html" %} {% include 'registration/login_inline.html' %}
- {% if sample_types.error_message %} -
-
-
-

Unable to display your Sample Type

-
-

- {% for value in sample_types.ERROR %} - {{ value }}
- {% endfor %} -

-
+
+ {% if error_message %} +
+
+
+

Unable to display your Sample Type

+
+

{{ error_message }}

+
+
+
+ {% else %} +
+
+
+

Type of Sample : {{type_of_sample_data.sample_type_name}}

+
+

Information below describes which fields are set to mandatory when recording samples

+
+
+
Field name
+
+
+
Mandatory
+
+
+ + {% for field, requested in type_of_sample_data.optional_data %} +
+ + {% if requested == 'Mandatory' %} + + {% else %} + + {% endif %} +
+ {% endfor %} +
+
+
-
- {% endif %} -
-
-
-

Type of Sample : {{type_of_sample_data.sample_type_name}}

-
-

Information below describes which fields are mandatory or optional when recording new sample

- {% for field, requested in type_of_sample_data.optional_data %} -
- - {% if requested == 'Mandatory' %} - - {% else %} - - {% endif %} -
- {% endfor %} -
-
-
-
+ {% endif %} +
{% endblock %} diff --git a/wetlab/views.py b/wetlab/views.py index a7476ae7c..2e6b1f4bc 100644 --- a/wetlab/views.py +++ b/wetlab/views.py @@ -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",