Beispiel #1
0
    def extract_error(self, errors, row_buffer, step_schema):
        for error in errors:
            if isinstance(
                    error,
                    tuple) and errors[0][1].__class__.__name__ == 'Invalid':
                error_doc = error[1].message
                error_doc = translate(_(error_doc), context=self.request)
                field_title = 'Invalid'
                field_name = 'Invalid'

            elif isinstance(
                    error,
                    tuple) and errors[0][1].__class__.__name__ != 'Invalid':
                error_doc = error[1].doc()
                error_doc = translate(_(error_doc), context=self.request)
                field_title = step_schema[error[0]].title
                field_title = translate(_(field_title), context=self.request)
                field_name = error[1].args[0]
            else:
                error_doc = error.doc()
                error_doc = translate(_(error_doc), context=self.request)
                field_title = ''
                field_name = error.args[0]
            error_message = ''
            if not isinstance(field_name, list):
                error_message = translate(_(field_name), context=self.request)
            msg = u'{0}: {1} {2}; '.format(error_doc, field_title,
                                           error_message)
            row_buffer[0] = logging.ERROR
            row_buffer[2] += msg

            if isinstance(field_name, list):
                self.extract_error(field_name, row_buffer, step_schema)
 def __call__(self, context):
     steps_vocabulary = SimpleVocabulary(
         [SimpleTerm(value=u'step2', title=_(u'NA Extraction')),
          SimpleTerm(value=u'step3', title=_(u'Library Construction')),
          SimpleTerm(value=u'step4', title=_(u'Computer Detecting'))]
     )
     return steps_vocabulary
Beispiel #3
0
 def fetch_data(self, field_obj, field_value, _obj, row_buffer):
     field_type = field_obj[1].__class__.__name__
     field_title = field_obj[1].title
     field_name = field_obj[0]
     if field_type in ('NamedBlobImage', 'NamedBlobFile'):
         request = urllib2.Request(url=field_value)
         try:
             response = urllib2.urlopen(request)
             filename = os.path.basename(response.url)
             if field_type == 'NamedBlobFile':
                 blob_file = NamedBlobFile(data=response.read(),
                                           filename=safe_unicode(filename))
             elif field_type == 'NamedBlobImage':
                 blob_file = NamedBlobImage(data=response.read(),
                                            filename=safe_unicode(filename))
             setattr(_obj, field_name, blob_file)
             return True
         except Exception:
             field_title = translate(_(field_title), context=self.request)
             error_doc = translate(
                 _("""The URL you have provided could not be reached."""),
                 context=self.request)
             msg = u'{0}: {1}; '.format(error_doc, field_title)
             row_buffer[2] += msg
             return False
def progress_steps(context):
    steps_vocabulary = SimpleVocabulary(
        [SimpleTerm(value=u'step1', title=_(u'Blood Sample')),
         SimpleTerm(value=u'step2', title=_(u'NA Extraction')),
         SimpleTerm(value=u'step3', title=_(u'Library Construction')),
         SimpleTerm(value=u'step4', title=_(u'Computer Detecting')),
         SimpleTerm(value=u'step5', title=_(u'Analysis Results'))]
    )
    return steps_vocabulary
Beispiel #5
0
    def dumpOutput(self, data):
        """
        """
        batch_list = data.get('batch_list', [])
        add_count = 0

        for entry in batch_list:
            uuid = entry['uuid']
            obj = api.content.uuidToObject(uuid)
            change_note = entry['changeNote']
            valid_steps = (u'step2', u'step3', u'step4')
            steps = entry['steps']
            try:
                index = valid_steps.index(steps)
            except ValueError:
                index = 0
            start, end = 0, utils.steps_start_end[index][1]
            step_field = utils.fields_name()[start:end]
            step_field.extend(['gid', 'creation_date', 'title'])

            if obj:
                container = obj.aq_parent
                new_obj = createContentInContainer(container,
                                                   portal_type='Tumour')
                [
                    setattr(new_obj, name, getattr(obj, name, ''))
                    for name in step_field
                ]
                [setattr(new_obj, k, v) for k, v in entry.items()]
                new_obj.steps = utils.progress_steps[index]
                add_count += 1
                change_note = u"{0} - {1}: {2}.".format(
                    translate(self.label, context=api.portal.getRequest()),
                    translate(_(steps), context=api.portal.getRequest()),
                    change_note if change_note else '')
                annotation = IAnnotations(self.context.REQUEST)
                annotation['plone.app.versioningbehavior' +
                           '-changeNote'] = change_note
                modified(new_obj)

        if add_count:
            api.portal.show_message(
                _(u'${count} Item created', mapping={'count': add_count}),
                self.request, 'info')
            logger.info(
                '{count} item(s) added successfully.'.format(count=add_count))

        return add_count
Beispiel #6
0
    def dumpOutput(self, data):
        batch_list = data.get('batch_list', [])
        add_count = 0

        generator = getUtility(IUUIDGenerator)
        gid = generator()

        today = datetime.datetime.today()
        year, month, day = today.year, today.month, today.day
        container = make_folder(self.aq_parent, (year, month, day))

        for entry in batch_list:
            obj = createContentInContainer(container,
                                           portal_type='Tumour',
                                           gid=gid)
            if obj:
                add_count += 1
                fields = dict((field[0], field[1])
                              for field in getFieldsInOrder(self._list_schema))
                for name, value in entry.items():
                    if name in fields and fields[name].readonly is False:
                        setattr(obj, name, value)
                obj.steps = 'step1'
                if 'sample_no' in entry:
                    obj.title = entry['sample_no']
                modified(obj)

        api.portal.show_message(
            _(u'${count} Item created', mapping={'count': add_count}),
            self.request, 'info')
        logger.info(
            '{count} item(s) added successfully.'.format(count=add_count))

        return add_count
Beispiel #7
0
    def dumpOutput(self, data):
        """
        """
        batch_list = data.get('batch_list', [])
        edit_count = 0

        for entry in batch_list:
            uuid = entry['uuid']
            obj = api.content.uuidToObject(uuid)
            if obj:
                transition = entry['transition_state']
                change_note = entry['changeNote']
                if transition:
                    api.content.transition(obj=obj,
                                           transition=transition,
                                           comment=change_note)
                    edit_count += 1
                    obj.reindexObject(idxs=['review_state'])
        if edit_count:
            api.portal.show_message(
                _(u'${count} Item state changed',
                  mapping={'count': edit_count}), self.request, 'info')
            logger.info(
                '{count} item(s) state changed.'.format(count=edit_count))

        return edit_count
def validate_url(value):
    if value != '' and not url_exists(value):
        raise InvalidURL(
            _(u"The URL you have provided could not be reached. "
              u"Please verify the URL is correct "
              u"and that the network location is reachable.")
        )
    return True
class ILibraryConstruction(model.Schema):

    uuid = schema.TextLine(
        title=_(u"UUID"),
        required=True,
        readonly=False,
    )

    sample_no = schema.TextLine(
        title=_(u"Sample number"),
        required=False,
        readonly=False,
    )

    library_time = schema.Datetime(
        title=_(u"Library construction time"),
        constraint=validate_time,
        required=True,
    )

    library_barcode = schema.TextLine(
        title=_(u"Library barcode"),
        required=False,
    )

    library_concentration = schema.Float(
        title=_(u"Library concentration (NG/UL)"),
        min=0.0,
        required=False,
    )

    library_operator = schema.TextLine(
        title=_(u"Library construction operator"),
        required=False,
    )

    library_kit_no = schema.TextLine(
        title=_(u"Library kit lot number"),
        required=False,
    )

    library_location = schema.TextLine(
        title=_(u"Library location"),
        required=False,
    )

    capture_concentration = schema.Float(
        title=_(u"Post capture concentration (NG/UL)"),
        min=0.0,
        required=False,
    )
Beispiel #10
0
class AnalysisResultsEditForm(NAExtractionEditForm):
    """"""
    _add_permission = 'gene.tumour: Add AnalysisResults'
    _list_schema = IAnalysisResultsEdit

    label = _(u'Analysis Results')
    prefix = 'form.tumour.results'

    fields = field.Fields(IAnalysisResultsList)
    fields['batch_list'].widgetFactory = DataGridFieldFactory
Beispiel #11
0
class ComputerDetectingEditForm(NAExtractionEditForm):
    """"""
    _add_permission = 'gene.tumour: Add ComputerDetecting'
    _list_schema = IComputerDetecting

    label = _(u'Computer Detecting')
    prefix = 'form.tumour.detecting'

    fields = field.Fields(IComputerDetectingList)
    fields['batch_list'].widgetFactory = DataGridFieldFactory
Beispiel #12
0
class LibraryConstructionEditForm(NAExtractionEditForm):
    """"""
    _add_permission = 'gene.tumour: Add LibraryConstruction'
    _list_schema = ILibraryConstruction

    label = _(u'Library Construction')
    prefix = 'form.tumour.library'

    fields = field.Fields(ILibraryConstructionList)
    fields['batch_list'].widgetFactory = DataGridFieldFactory
Beispiel #13
0
class IAnalysisResultsEdit(model.Schema):
    uuid = schema.TextLine(
        title=_(u"UUID"),
        required=True,
        readonly=False,
    )

    sample_no = schema.TextLine(
        title=_(u"Sample number"),
        required=False,
        readonly=False,
    )

    result = schema.Choice(
        title=_(u"Result"),
        required=False,
        vocabulary=u"gene.tumour.vocabulary.analysis_result",
    )

    result_info = schema.TextLine(
        title=_(u"Result information"),
        required=False,
    )

    quality_file = field.NamedBlobFile(
        title=_(u"Quality control document"),
        required=False,
    )

    result_file = field.NamedBlobFile(
        title=_(u"Result detail"),
        required=False,
    )
Beispiel #14
0
class ChangeNoteForm(AutoExtensibleForm, form.EditForm):
    schema = IVersionable
    name = 'ChangeNoteForm'

    label = _(u"Add change notes")
    description = _(u"Add change notes, note the notes cannot be changed.")

    def update(self):
        self.request.set('disable_border', True)

        super(ChangeNoteForm, self).update()

    @button.buttonAndHandler(_(u'Save'))
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        changes = {}
        if 'changeNote' in data and data['changeNote'] is not None and \
                len(data) == 1:
            obj = self.getContent()
            obj.description += data['changeNote'] + u'\n'
            changes = self.applyChanges(data)

        if changes:
            api.portal.show_message(
                _(u"Note has been added."), self.request, 'info')
        else:
            api.portal.show_message(
                _(u"Note has not been added."), self.request, 'warn')
        self.status = 'form status'
        contextURL = self.context.absolute_url()
        self.request.response.redirect(contextURL)

    @button.buttonAndHandler(_(u"Cancel"))
    def handleCancel(self, action):
        contextURL = self.context.absolute_url()
        self.request.response.redirect(contextURL)
Beispiel #15
0
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        changes = {}
        if 'changeNote' in data and data['changeNote'] is not None and \
                len(data) == 1:
            obj = self.getContent()
            obj.description += data['changeNote'] + u'\n'
            changes = self.applyChanges(data)

        if changes:
            api.portal.show_message(
                _(u"Note has been added."), self.request, 'info')
        else:
            api.portal.show_message(
                _(u"Note has not been added."), self.request, 'warn')
        self.status = 'form status'
        contextURL = self.context.absolute_url()
        self.request.response.redirect(contextURL)
Beispiel #16
0
    def dumpOutput(self, data):
        batch_list = data.get('batch_list', [])
        add_count = 0
        edit_count = 0

        for entry in batch_list:
            uuid = entry['uuid']
            obj = api.content.uuidToObject(uuid)
            if obj:
                edit_count += 1
                fields = dict((field[0], field[1])
                              for field in getFieldsInOrder(self._list_schema))
                for name, value in entry.items():
                    if name in fields and fields[name].readonly is False:
                        setattr(obj, name, value)

                if 'sample_no' in entry:
                    obj.title = entry['sample_no']
                if self.new_steps and self.new_steps != u'step*':
                    old_steps = obj.steps
                    obj.steps = self.new_steps
                    notify(StepsChangedEvent(obj, old_steps, self.new_steps))
                modified(obj)

        if add_count:
            api.portal.show_message(
                _(u'${count} Item created', mapping={'count': add_count}),
                self.request, 'info')
            logger.info(
                '{count} item(s) added successfully.'.format(count=add_count))
        if edit_count:
            api.portal.show_message(
                _(u'${count} Item edited', mapping={'count': edit_count}),
                self.request, 'info')
            logger.info(
                '{count} items edited successfully.'.format(count=edit_count))

        return add_count or edit_count
Beispiel #17
0
 def __init__(self, context, request):
     super(ImportExcel, self).__init__(context, request)
     self.context = context
     self.request = request
     add_bundle_on_request(self.request, 'gene-tumour-main')
     self.request['disable_border'] = True
     for trans, invert in [
         (invert_situation_local, invert_situation_dict),
         (invert_na_types_local, invert_na_types_dict),
         (invert_result_local, invert_result_dict),
     ]:
         if not trans:
             for key in invert:
                 trans[translate(_(key), context=request)] = invert[key]
Beispiel #18
0
 def pre_older_after(obj):
     prev = 'sampling_time'
     after = 'received_time'
    
     prev_value = getattr(obj, prev, None)
     after_value = getattr(obj, after, None)
     if after_value is not None:
         if (prev_value is not None 
             and isinstance(prev_value, datetime.datetime)
             and isinstance(after_value, datetime.datetime)
             and prev_value > after_value):
             raise Invalid(
                             _(u'After steps time must be greater than '
                               u'or equal to the previous steps time'))
Beispiel #19
0
    def getContent(self):
        data = {'batch_list': []}
        names = getFieldNamesInOrder(self._list_schema)

        for obj in self.items:
            record = {}
            for name in names:
                record[name] = getattr(obj, name, None)
            record['uuid'] = obj.UID()
            record['review_state'] = translate(_(
                api.content.get_state(obj).title()),
                                               context=api.portal.getRequest())
            data['batch_list'].append(record)

        return data
Beispiel #20
0
    def __call__(self, context):
        if isinstance(context, dict) and 'uuid' in context:
            obj = api.content.uuidToObject(context['uuid'])
            workflow = api.portal.get_tool('portal_workflow')
            actions = workflow.listActions(object=obj)

            states_vocabulary = SimpleVocabulary(
                [SimpleTerm(value=action['id'],
                            title=translate(_(action['name']),
                                            context=api.portal.getRequest()))
                 for action in actions]
            )
        else:
            states_vocabulary = SimpleVocabulary([])
        return states_vocabulary
Beispiel #21
0
    def dumpOutput(self, data):
        """
        """
        batch_list = data.get('batch_list', [])
        edit_count = 0

        for entry in batch_list:
            uuid = entry['uuid']
            obj = api.content.uuidToObject(uuid)
            change_note = entry['changeNote']
            if obj:
                old_steps = obj.steps
                if old_steps != entry['steps']:
                    obj.steps = entry['steps']
                    edit_count += 1
                    notify(StepsChangedEvent(obj, old_steps, entry['steps']))
                    change_note = u"{0} - {1}->{2}: {3}.".format(
                        translate(self.label, context=api.portal.getRequest()),
                        translate(_(old_steps),
                                  context=api.portal.getRequest()),
                        translate(_(obj.steps),
                                  context=api.portal.getRequest()),
                        change_note if change_note else '')
                    annotation = IAnnotations(self.context.REQUEST)
                    annotation['plone.app.versioningbehavior' +
                               '-changeNote'] = change_note
                    modified(obj)

        if edit_count:
            api.portal.show_message(
                _(u'${count} Item edited', mapping={'count': edit_count}),
                self.request, 'info')
            logger.info('{count} item(s) edited successfully.'.format(
                count=edit_count))

        return edit_count
Beispiel #22
0
class WorkflowStateTransitionForm(ChangeStepsEditForm):
    """"""
    _add_permission = 'Review portal content'
    _edit_permission = 'Review portal content'
    _finishedAdd = False
    _list_schema = IWorkflowStateTransition

    label = _(u'Workflow state transition')
    prefix = 'form.tumour.state'

    fields = field.Fields(IWorkflowStateTransitionList)
    fields['batch_list'].widgetFactory = DataGridFieldFactory
    fields_readonly = [
        'sample_no', 'barcode', 'name', 'steps', 'review_state', 'result',
        'result_info'
    ]

    def datagridInitialise(self, subform, widget):
        pass

    def dumpOutput(self, data):
        """
        """
        batch_list = data.get('batch_list', [])
        edit_count = 0

        for entry in batch_list:
            uuid = entry['uuid']
            obj = api.content.uuidToObject(uuid)
            if obj:
                transition = entry['transition_state']
                change_note = entry['changeNote']
                if transition:
                    api.content.transition(obj=obj,
                                           transition=transition,
                                           comment=change_note)
                    edit_count += 1
                    obj.reindexObject(idxs=['review_state'])
        if edit_count:
            api.portal.show_message(
                _(u'${count} Item state changed',
                  mapping={'count': edit_count}), self.request, 'info')
            logger.info(
                '{count} item(s) state changed.'.format(count=edit_count))

        return edit_count
Beispiel #23
0
class IChangeSteps(model.Schema):
    uuid = schema.TextLine(
        title=_(u"UUID"),
        required=True,
        readonly=False,
    )

    sample_no = schema.TextLine(
        title=_(u"Sample number"),
        required=False,
        readonly=False,
    )

    barcode = schema.TextLine(
        title=_(u"Barcode"),
        required=False,
        readonly=False,
    )

    name = schema.TextLine(
        title=_(u"Name"),
        required=False,
        readonly=False,
    )

    review_state = schema.TextLine(
        title=_(u"Review state"),
        required=False,
        readonly=False,
    )

    steps = schema.Choice(
        title=_(u"Steps"),
        required=True,
        vocabulary=u"gene.tumour.vocabulary.progress_steps"
    )

    changeNote = schema.TextLine(
        title=_(u'label_change_note', default=u'Change Note'),
        description=_(u'help_change_note',
                      default=u'Enter a comment that describes the changes '
                              u'you made.'),
        required=False)
Beispiel #24
0
    def fields_name_title(self):

        split_point = 3
        step5_start, step5_end = utils.steps_start_end[4]

        fields_name = utils.fields_name()[-1:]
        fields_name += ['review_state']
        fields_name += utils.fields_name()[:split_point]
        fields_name += utils.fields_name()[step5_start:step5_end]
        fields_name += utils.fields_name()[split_point:step5_start]

        fields_title = utils.fields_title()[-1:]
        fields_title += [translate(_('Review state'), context=self.request)]
        fields_title += utils.fields_title()[:split_point]
        fields_title += utils.fields_title()[step5_start:step5_end]
        fields_title += utils.fields_title()[split_point:step5_start]

        return zip(fields_name, fields_title)
Beispiel #25
0
class NAExtractionEditForm(BloodSampleEditForm):
    """"""
    _add_permission = 'gene.tumour: Add NAExtraction'
    _list_schema = INAExtraction

    label = _(u'NA Extraction')
    prefix = 'form.tumour.na'

    fields = field.Fields(INAExtractionList)
    fields['batch_list'].widgetFactory = DataGridFieldFactory
    fields_readonly = [
        'sample_no',
    ]

    def updateWidgets(self, prefix=None):
        super(NAExtractionEditForm, self).updateWidgets()
        self.widgets['batch_list'].allow_insert = False
        self.widgets['batch_list'].allow_delete = False
        self.widgets['batch_list'].auto_append = False
Beispiel #26
0
 def steps_date_valid(obj):
     steps_date = [('sampling_time', 'received_time'),
                   ('separation_time', 'extraction_time'),
                   ('library_time',),
                   ('template_time', 'sequencing_time')]
     steps_date.reverse()
     for index, names in enumerate(steps_date):
         prev_date = []
         [prev_date.extend(item) for item in steps_date[index + 1:]]
         for after in names:
             after_value = getattr(obj, after, None)
             if after_value is not None:
                 for prev in prev_date:
                     prev_value = getattr(obj, prev, None)
                     if (prev_value is not None
                         and isinstance(prev_value, datetime.date)
                         and isinstance(after_value, datetime.date)
                         and prev_value > after_value):
                         raise Invalid(
                             _(u'After steps time must be greater than '
                               u'or equal to the previous steps time'))
Beispiel #27
0
class IComputerDetecting(model.Schema):
    uuid = schema.TextLine(
        title=_(u"UUID"),
        required=True,
        readonly=False,
    )

    sample_no = schema.TextLine(
        title=_(u"Sample number"),
        required=False,
        readonly=False,
    )

    template_time = schema.Datetime(
        title=_(u"Template preparation time"),
        constraint=validate_time,
        required=True,
    )

    template_operator = schema.TextLine(
        title=_(u"Template preparation operator"),
        required=False,
    )

    template_kit_no = schema.TextLine(
        title=_(u"Template kit lot number"),
        required=False,
    )

    ot_instrument_no = schema.TextLine(
        title=_(u"OT instrument number"),
        required=False,
    )

    es_instrument_no = schema.TextLine(
        title=_(u"ES instrument number"),
        required=False,
    )

    sequencing_time = schema.Datetime(
        title=_(u"Sequencing time"),
        constraint=validate_time,
        required=True,
    )

    sequencing_operator = schema.TextLine(
        title=_(u"Sequencing operator"),
        required=False,
    )

    sequencing_server = schema.TextLine(
        title=_(u"Sequencer number"),
        required=False,
    )

    sequencing_ip = schema.TextLine(
        title=_(u"Sequencing IP"),
        required=False,
    )

    sequencing_filename = schema.TextLine(
        title=_(u"Sequencing filename"),
        required=False,
    )
Beispiel #28
0
class INAExtraction(model.Schema):
    uuid = schema.TextLine(
        title=_(u"UUID"),
        required=True,
        readonly=False,
    )

    sample_no = schema.TextLine(
        title=_(u"Sample number"),
        required=False,
        readonly=False,
    )

    task_no = schema.TextLine(
        title=_(u"Task no"),
        required=False,
    )

    separation_time = schema.Datetime(
        title=_(u"Separation time"),
        constraint=validate_time,
        required=False,
    )

    separation_operator = schema.TextLine(
        title=_(u"Separation operator"),
        required=False,
    )

    plasma_location = schema.TextLine(
        title=_(u"Plasma location"),
        required=False,
    )

    separation_note = schema.TextLine(
        title=_(u"Plasma separation note"),
        required=False,
    )

    extraction_time = schema.Datetime(
        title=_(u"Extraction time"),
        constraint=validate_time,
        required=True,
    )

    na_extraction_type = schema.List(
        title=_(u"NA Extraction Type"),
        required=True,
        value_type=schema.Choice(
            title=_(u"NA type"),
            vocabulary="gene.tumour.vocabulary.na_types",
            required=True),
    )

    na_plasma_volume = schema.Float(
        title=_(u"NA plasma volume(ml)"),
        min=0.0,
        required=False,
    )

    na_concentration = schema.Float(
        title=_(u"NA concentration (NG/UL)"),
        min=0.0,
        required=False,
    )

    absorbance = schema.Float(
        title=_(u"Absorbance 260/280"),
        min=0.0,
        required=False,
    )

    na_kit_no = schema.TextLine(
        title=_(u"NA extraction kit lot number"),
        required=False,
    )

    na_operator = schema.TextLine(
        title=_(u"NA extracting operator"),
        required=False,
    )
Beispiel #29
0
class IGeneTumourSettings(Interface):
    sms_notify_enabled = schema.Bool(
        title=_(u"SMS notification"),
        description=_(u"If selected, the sent SMS notification to user."),
        default=False
    )

    sms_notify_message = schema.Text(
        title=_(u"SMS text"),
        description=_(u"You need to send the text."),
        default=u'',
        required=False,
    )

    email_notify_enabled = schema.Bool(
        title=_(u"Email notification"),
        description=_(u"If selected, "
                      u"enabled step change Email message notifications."),
        default=False
    )

    record_expire_days = schema.Int(
        title=_(u"Record Expiration days"),
        description=_(u"Please fill out an integer range: 1-365"),
        min=0,
        max=365,
        default=0,
        required=False)

    record_expire_notify = schema.Choice(
        title=_(u"Record expiration notification user group"),
        description=_(u"When the entry has expired, "
                      u"send an email message to inform the user"),
        vocabulary="plone.app.vocabularies.Groups",
        required=False)

    user_search_filter = schema.Dict(
        title=_(u"User search filter"),
        description=_(u"User search filter additional conditions"),
        required=False,
        key_type=schema.Choice(
            title=_(u"User group"),
            vocabulary="plone.app.vocabularies.Groups",
            required=True),
        value_type=schema.TextLine(
            title=_(u"Filter condition"),
            description=_(u"Users search additional filtering criteria. "
                          u"Reference usage: Advanced search instructions"),
            required=True)
    )
Beispiel #30
0
class IBloodSample(model.Schema):
    uuid = schema.TextLine(
        title=_(u"UUID"),
        required=True,
        readonly=False,
    )

    sample_no = schema.TextLine(
        title=_(u"Sample number"),
        required=True,
    )

    barcode = schema.TextLine(
        title=_(u"Barcode"),
        required=False,
    )

    name = schema.TextLine(
        title=_(u"Name"),
        required=True,
    )

    sex = schema.TextLine(
        title=_(u"Sex"),
        required=True,
    )

    age = schema.Int(
        title=_(u"Age"),
        min=0,
        max=200,
        required=True,
    )

    inspection_item = schema.TextLine(
        title=_(u"Inspection item"),
        required=True,
    )

    inspection_method = schema.TextLine(
        title=_(u"Inspection method"),
        required=True,
    )

    submission_hospital = schema.TextLine(
        title=_(u"Submission hospital"),
        required=False,
    )

    submission_department = schema.TextLine(
        title=_(u"Submission department"),
        required=False,
    )

    submission_doctor = schema.TextLine(
        title=_(u"Submission doctor"),
        required=False,
    )

    pathological_diagnosis = schema.TextLine(
        title=_(u"Pathological diagnosis"),
        required=False,
    )

    pathological_no = schema.TextLine(
        title=_(u"Pathological number"),
        required=False,
    )

    treatment_situation = schema.List(
        title=_(u"Treatment situation"),
        required=False,
        value_type=schema.Choice(
            title=_(u"Treatment"),
            vocabulary="gene.tumour.vocabulary.treatment_situation",
            required=True),
    )

    received_operator = schema.TextLine(
        title=_(u"Received operator"),
        required=False,
    )

    received_phone = schema.TextLine(
        title=_(u"Received phone"),
        required=False,
    )

    received_address = schema.TextLine(
        title=_(u"Received address"),
        required=False,
    )

    sample_type = schema.TextLine(
        title=_(u"Sample type"),
        required=True,
    )

    sampling_time = schema.Datetime(
        title=_(u"Sampling time"),
        constraint=validate_time,
        required=False,
    )

    received_time = schema.Datetime(
        title=_(u"Received time"),
        constraint=validate_time,
        required=False,
    )

    sample_size = schema.TextLine(
        title=_(u"Sample size "),
        required=False,
    )

    sample_note = schema.TextLine(
        title=_(u"Sample note"),
        required=False,
    )

    sample_source = schema.TextLine(
        title=_(u"Sample source"),
        required=False,
    )

    tcc_tcp = schema.Float(
        title=_(u"TCC/TCP"),
        description=_(u"Glass inspection"
                      u"(Percentage of tumor cells/tumor cells)"),
        required=False,
        min=0.0,
        max=1.00,
    )

    @invariant
    def pre_older_after(obj):
        prev = 'sampling_time'
        after = 'received_time'
       
        prev_value = getattr(obj, prev, None)
        after_value = getattr(obj, after, None)
        if after_value is not None:
            if (prev_value is not None 
                and isinstance(prev_value, datetime.datetime)
                and isinstance(after_value, datetime.datetime)
                and prev_value > after_value):
                raise Invalid(
                                _(u'After steps time must be greater than '
                                  u'or equal to the previous steps time'))