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
|
|
|
""" Thermo Scientific 'Gallery 9861x' |
9
|
|
|
""" |
10
|
|
|
from bika.lims import bikaMessageFactory as _ |
11
|
|
|
from bika.lims.utils import t |
12
|
|
|
from . import ThermoGalleryImporter, ThermoGalleryTSVParser |
13
|
|
|
import json |
14
|
|
|
import traceback |
15
|
|
|
|
16
|
|
|
title = "Thermo Scientific - Gallery 9861x" |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
def Import(context, request): |
20
|
|
|
""" Thermo Scientific - Gallery 9861x analysis results |
21
|
|
|
""" |
22
|
|
|
infile = request.form['thermoscientific_gallery_9861x_file'] |
23
|
|
|
fileformat = request.form['thermoscientific_gallery_9861x_format'] |
24
|
|
|
artoapply = request.form['thermoscientific_gallery_9861x_artoapply'] |
25
|
|
|
override = request.form['thermoscientific_gallery_9861x_override'] |
26
|
|
|
instrument = request.form.get('thermoscientific_gallery_9861x_instrument', None) |
27
|
|
|
errors = [] |
28
|
|
|
logs = [] |
29
|
|
|
|
30
|
|
|
# Load the most suitable parser according to file extension/options/etc... |
31
|
|
|
parser = None |
32
|
|
|
if not hasattr(infile, 'filename'): |
33
|
|
|
errors.append(_("No file selected")) |
34
|
|
|
if fileformat == 'tsv_40': |
35
|
|
|
parser = ThermoGallery9861xTSVParser(infile) |
36
|
|
|
else: |
37
|
|
|
errors.append(t(_("Unrecognized file format ${fileformat}", |
38
|
|
|
mapping={"fileformat": fileformat}))) |
39
|
|
|
|
40
|
|
|
if parser: |
41
|
|
|
# Load the importer |
42
|
|
|
status = ['sample_received', 'attachment_due', 'to_be_verified'] |
43
|
|
|
if artoapply == 'received': |
44
|
|
|
status = ['sample_received'] |
45
|
|
|
elif artoapply == 'received_tobeverified': |
46
|
|
|
status = ['sample_received', 'attachment_due', 'to_be_verified'] |
47
|
|
|
|
48
|
|
|
over = [False, False] |
49
|
|
|
if override == 'nooverride': |
50
|
|
|
over = [False, False] |
51
|
|
|
elif override == 'override': |
52
|
|
|
over = [True, False] |
53
|
|
|
elif override == 'overrideempty': |
54
|
|
|
over = [True, True] |
55
|
|
|
|
56
|
|
|
importer = ThermoGallery9861xImporter(parser=parser, |
57
|
|
|
context=context, |
58
|
|
|
allowed_ar_states=status, |
59
|
|
|
allowed_analysis_states=None, |
60
|
|
|
override=over, |
61
|
|
|
instrument_uid=instrument) |
62
|
|
|
tbex = '' |
63
|
|
|
try: |
64
|
|
|
importer.process() |
65
|
|
|
except: |
66
|
|
|
tbex = traceback.format_exc() |
67
|
|
|
errors = importer.errors |
68
|
|
|
logs = importer.logs |
69
|
|
|
warns = importer.warns |
70
|
|
|
if tbex: |
71
|
|
|
errors.append(tbex) |
72
|
|
|
|
73
|
|
|
results = {'errors': errors, 'log': logs, 'warns': warns} |
|
|
|
|
74
|
|
|
|
75
|
|
|
return json.dumps(results) |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
class ThermoGallery9861xTSVParser(ThermoGalleryTSVParser): |
79
|
|
|
|
80
|
|
|
def getAttachmentFileType(self): |
81
|
|
|
return "Thermo Scientific Gallery 9861x TSV/XLS" |
82
|
|
|
|
83
|
|
|
|
84
|
|
|
class ThermoGallery9861xImporter(ThermoGalleryImporter): |
85
|
|
|
|
86
|
|
|
def getKeywordsToBeExcluded(self): |
87
|
|
|
return [] |
88
|
|
|
|