From f66935698c43d7d638bccbc5a52d59b4a5971442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Marr=C3=B3?= Date: Fri, 23 Nov 2018 14:55:18 -0300 Subject: [PATCH] Add injection date to file upload results --- lims_instrument/locale/es.po | 4 ++++ lims_instrument/resultsimport.py | 18 ++++++++++++++++++ ...ook_load_results_file_result_lines_list.xml | 1 + .../generic_form_xls.py | 18 ++++++++++++++---- .../generic_service_xls.py | 17 +++++++++++++++++ 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/lims_instrument/locale/es.po b/lims_instrument/locale/es.po index 3cf92ef0..d37d86d2 100644 --- a/lims_instrument/locale/es.po +++ b/lims_instrument/locale/es.po @@ -253,3 +253,7 @@ msgstr "Cancelar" msgctxt "wizard_button:lims.notebook.load_results_file,warning,close:" msgid "Ok" msgstr "Aceptar" + +msgctxt "field:lims.notebook.line,imported_inj_date:" +msgid "Injection date" +msgstr "Fecha de Inyección" \ No newline at end of file diff --git a/lims_instrument/resultsimport.py b/lims_instrument/resultsimport.py index 4bebff49..acc1edc1 100644 --- a/lims_instrument/resultsimport.py +++ b/lims_instrument/resultsimport.py @@ -35,6 +35,7 @@ class NotebookLine: imported_device = fields.Many2One('lims.lab.device', 'Device') imported_dilution_factor = fields.Float('Dilution factor') imported_rm_correction_formula = fields.Char('RM Correction Formula') + imported_inj_date = fields.Date('Inject date') class ResultsImport(ModelSQL, ModelView): @@ -267,6 +268,8 @@ class NotebookLoadResultsFile(Wizard): res['imported_literal_result'] = data['literal_result'] res['imported_end_date'] = (data['end_date'] if 'end_date' in data else line.end_date) + res['imported_inj_date'] = (data['injection_date'] + if 'injection_date' in data else None) if 'professionals' in data: res['imported_professionals'] = data['professionals'] if 'chromatogram' in data: @@ -359,6 +362,7 @@ class NotebookLoadResultsFile(Wizard): 'imported_device': None, 'imported_dilution_factor': None, 'imported_rm_correction_formula': None, + 'imported_inj_date': None, } prevent_line = False @@ -386,6 +390,18 @@ class NotebookLoadResultsFile(Wizard): outcome = 'End date cannot be lower than Start date' else: notebook_line_write['end_date'] = None + if line.injection_date != line.imported_inj_date: + if line.imported_result != '-1000.0': + if (line.start_date and + line.start_date <= line.imported_inj_date): + notebook_line_write['injection_date'] = ( + line.imported_inj_date) + else: + prevent_line = True + outcome = \ + 'Injection date cannot be lower than Start date' + else: + notebook_line_write['injection_date'] = None if line.chromatogram != line.imported_chromatogram: notebook_line_write['chromatogram'] = ( line.imported_chromatogram) @@ -438,6 +454,7 @@ class NotebookLoadResultsFile(Wizard): 'device': line.device, 'dilution_factor': line.dilution_factor, 'rm_correction_formula': line.rm_correction_formula, + 'injection_date': line.injection_date, } NotebookLine.write( [line], notebook_line_original_values) @@ -482,6 +499,7 @@ class NotebookLoadResultsFile(Wizard): 'imported_device': None, 'imported_dilution_factor': None, 'imported_rm_correction_formula': None, + 'imported_inj_date': None, } NotebookLine.write( list(self.result.result_lines), notebook_line_clean) diff --git a/lims_instrument/view/notebook_load_results_file_result_lines_list.xml b/lims_instrument/view/notebook_load_results_file_result_lines_list.xml index 080b0eaa..1f8fe4d7 100644 --- a/lims_instrument/view/notebook_load_results_file_result_lines_list.xml +++ b/lims_instrument/view/notebook_load_results_file_result_lines_list.xml @@ -12,4 +12,5 @@ + diff --git a/lims_instrument_generic_form/generic_form_xls.py b/lims_instrument_generic_form/generic_form_xls.py index fc4976ac..79f8aa09 100644 --- a/lims_instrument_generic_form/generic_form_xls.py +++ b/lims_instrument_generic_form/generic_form_xls.py @@ -101,8 +101,18 @@ def parse(self, infile): device = str(int(row[COL['C']].value)) elif row[COL['C']].ctype == xlrd.XL_CELL_TEXT: device = row[COL['C']].value - rm_correction_formula = row[COL['L']].value if ( - row[COL['L']].ctype == xlrd.XL_CELL_TEXT) else None + inj_date_raw = row[COL['L']].value + if row[COL['L']].ctype == xlrd.XL_CELL_TEXT: + try: + it = inj_date_raw.split('/') + inj_date = date(int(it[2]), int(it[1]), int(it[0])) + except: + inj_date = None + elif row[COL['L']].ctype == xlrd.XL_CELL_DATE: + it = xlrd.xldate_as_tuple(inj_date_raw, workbook.datemode) + inj_date = date(it[0], it[1], it[2]) + else: + inj_date = None if result is not None: values['result'] = result @@ -111,14 +121,14 @@ def parse(self, infile): worksheet.number, curr_row, STATUS_COLUMN] if end_date: values['end_date'] = end_date + if inj_date: + values['injection_date'] = inj_date if professionals: values['professionals'] = professionals if chromatogram: values['chromatogram'] = chromatogram if device: values['device'] = device - if rm_correction_formula: - values['rm_correction_formula'] = rm_correction_formula values['row_number'] = curr_row + 1 if fraction in self.rawresults: diff --git a/lims_instrument_generic_service/generic_service_xls.py b/lims_instrument_generic_service/generic_service_xls.py index d899d4ec..d56bd37a 100644 --- a/lims_instrument_generic_service/generic_service_xls.py +++ b/lims_instrument_generic_service/generic_service_xls.py @@ -51,6 +51,21 @@ def parse(self, infile): chromatogram = row2nd[COL['G']].value if ( row2nd[COL['G']].ctype == xlrd.XL_CELL_TEXT) else None + # 3rd row: injection date + row3nd = worksheet.row(2) + inj_date_raw = row3nd[COL['E']].value + if row3nd[COL['E']].ctype == xlrd.XL_CELL_TEXT: + try: + it = inj_date_raw.split('/') + inj_date = date(int(it[2]), int(it[1]), int(it[0])) + except: + inj_date = None + elif row3nd[COL['E']].ctype == xlrd.XL_CELL_DATE: + it = xlrd.xldate_as_tuple(inj_date_raw, workbook.datemode) + inj_date = date(it[0], it[1], it[2]) + else: + inj_date = None + # 4th row: sample, year, fraction, repetition, # professional and dilution factor row4th = worksheet.row(3) @@ -125,6 +140,8 @@ def parse(self, infile): values['device'] = device if end_date: values['end_date'] = end_date + if inj_date: + values['injection_date'] = inj_date if professionals: values['professionals'] = professionals if chromatogram: