1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE |
4
|
|
|
# |
5
|
|
|
# Copyright 2018 by it's authors. |
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
7
|
|
|
|
8
|
|
|
"""Multiskan GO Microplate Spectrophotometer |
9
|
|
|
""" |
10
|
|
|
from bika.lims import bikaMessageFactory as _ |
11
|
|
|
from bika.lims.utils import t |
12
|
|
|
from . import ThermoScientificMultiskanCSVParser, ThermoScientificMultiskanImporter |
13
|
|
|
import json |
14
|
|
|
import traceback |
15
|
|
|
|
16
|
|
|
title = "Thermo Scientific Multiskan - GO Microplate Spectrophotometer" |
17
|
|
|
|
18
|
|
|
|
19
|
|
View Code Duplication |
def Import(context, request): |
|
|
|
|
20
|
|
|
""" Thermo Scientific Multiskan GO analysis results |
21
|
|
|
""" |
22
|
|
|
infile = request.form['data_file'] |
23
|
|
|
fileformat = request.form['format'] |
24
|
|
|
artoapply = request.form['artoapply'] |
25
|
|
|
override = request.form['override'] |
26
|
|
|
instrument = request.form.get('instrument', None) |
27
|
|
|
analysis = request.form.get('analysis', None) |
28
|
|
|
errors = [] |
29
|
|
|
logs = [] |
30
|
|
|
warns = [] |
31
|
|
|
|
32
|
|
|
# Load the most suitable parser according to file extension/options/etc... |
33
|
|
|
parser = None |
34
|
|
|
if not hasattr(infile, 'filename'): |
35
|
|
|
errors.append(_("No file selected")) |
36
|
|
|
if fileformat == 'csv': |
37
|
|
|
if not analysis: |
38
|
|
|
errors.append(_("No analysis service selected")) |
39
|
|
|
parser = ThermoScientificMultiskanGOCSVParser(infile, analysis) |
40
|
|
|
else: |
41
|
|
|
errors.append(t(_("Unrecognized file format ${fileformat}", |
42
|
|
|
mapping={"fileformat": fileformat}))) |
43
|
|
|
|
44
|
|
|
if parser: |
45
|
|
|
# Load the importer |
46
|
|
|
status = ['sample_received', 'attachment_due', 'to_be_verified'] |
47
|
|
|
if artoapply == 'received': |
48
|
|
|
status = ['sample_received'] |
49
|
|
|
elif artoapply == 'received_tobeverified': |
50
|
|
|
status = ['sample_received', 'attachment_due', 'to_be_verified'] |
51
|
|
|
|
52
|
|
|
over = [False, False] |
53
|
|
|
if override == 'nooverride': |
54
|
|
|
over = [False, False] |
55
|
|
|
elif override == 'override': |
56
|
|
|
over = [True, False] |
57
|
|
|
elif override == 'overrideempty': |
58
|
|
|
over = [True, True] |
59
|
|
|
|
60
|
|
|
importer = ThermoScientificMultiskanGOImporter(parser=parser, |
61
|
|
|
context=context, |
62
|
|
|
allowed_ar_states=status, |
63
|
|
|
allowed_analysis_states=None, |
64
|
|
|
override=over, |
65
|
|
|
instrument_uid=instrument) |
66
|
|
|
tbex = '' |
67
|
|
|
try: |
68
|
|
|
importer.process() |
69
|
|
|
except: |
70
|
|
|
tbex = traceback.format_exc() |
71
|
|
|
errors = importer.errors |
72
|
|
|
logs = importer.logs |
73
|
|
|
warns = importer.warns |
74
|
|
|
if tbex: |
75
|
|
|
errors.append(tbex) |
76
|
|
|
|
77
|
|
|
results = {'errors': errors, 'log': logs, 'warns': warns} |
78
|
|
|
|
79
|
|
|
return json.dumps(results) |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
class ThermoScientificMultiskanGOCSVParser(ThermoScientificMultiskanCSVParser): |
83
|
|
|
|
84
|
|
|
def getAttachmentFileType(self): |
85
|
|
|
return "Thermo Scientific Multiskan - GO Microplate Spectrophotometer" |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
class ThermoScientificMultiskanGOImporter(ThermoScientificMultiskanImporter): |
89
|
|
|
|
90
|
|
|
def getKeywordsToBeExcluded(self): |
91
|
|
|
return [] |
92
|
|
|
|