def __init__(self, context, request): SE.__init__(self, context, request) if IAliquot.providedBy(context): self.icon = self.portal_url + \ "/++resource++bika.sanbi.images/aliquot_big.png" elif IBiospecimen.providedBy(context): self.icon = self.portal_url + \ "/++resource++bika.sanbi.images/biospecimen_big.png" self.allow_edit = True
def biospecimens(self): """ Return samples providing IBiospecimen of the current project """ items = [] w_tool = getToolByName(self.context, 'portal_workflow') samples = self.context.objectValues('Sample') for sample in samples: if IBiospecimen.providedBy(sample): st1 = w_tool.getStatusOf("bika_sample_workflow", sample) st2 = w_tool.getStatusOf("bika_cancellation_workflow", sample) if st1.get('review_state', None) == 'sample_received' and \ st2.get('cancellation_state', None) == 'active': items.append({'uid': sample.UID(), 'title': sample.Title()}) items.sort(lambda x, y: cmp(x['title'], y['title'])) return items
def __init__(self, context): self.context = context self.sort = 10 self.random = 4 if IAliquot.providedBy(context): self.hidden_fields = ['Kit', 'SubjectID', 'Barcode', 'Sampling Date', 'ScheduledSamplingSampler', 'PreparationWorkflow', 'SamplePoint', 'Sampler'] if IBiospecimen.providedBy(context): self.hidden_fields = ['Sampling Date', 'LinkedSample', 'ScheduledSamplingSampler', 'PreparationWorkflow', 'SamplePoint', 'Sampler']
def biospecimens(self): """ Return samples providing IBiospecimen of the current project """ items = [] w_tool = getToolByName(self.context, 'portal_workflow') samples = self.context.objectValues('Sample') for sample in samples: if IBiospecimen.providedBy(sample): st1 = w_tool.getStatusOf("bika_sample_workflow", sample) st2 = w_tool.getStatusOf("bika_cancellation_workflow", sample) if st1.get('review_state', None) == 'sample_received' and \ st2.get('cancellation_state', None) == 'active': items.append({ 'uid': sample.UID(), 'title': sample.Title() }) items.sort(lambda x, y: cmp(x['title'], y['title'])) return items
def folderitems(self, full_objects=False): items = BikaListingView.folderitems(self) bsc = getToolByName(self.context, 'bika_setup_catalog') brains = bsc(portal_type='SampleType', inactive_state='active') biospecimen_types = [{ 'ResultValue': brain.UID, 'ResultText': brain.title } for brain in brains] ret = [] for x, item in enumerate(items): if not items[x].has_key('obj'): continue obj = items[x]['obj'] if not IBiospecimen.providedBy(obj): continue items[x]['Type'] = obj.getSampleType() and obj.getSampleType( ).Title() or '' items[x]['Volume'] = obj.getField('Volume').get(obj) items[x]['Unit'] = VOLUME_UNITS[0]['ResultText'] items[x]['SubjectID'] = obj.getField('SubjectID').get(obj) kit = obj.getField('Kit').get(obj) items[x]['Kit'] = kit items[x]['Project'] = obj.aq_parent if kit: items[x]['replace']['Kit'] = \ '<a href="%s">%s</a>' % (kit.absolute_url(), kit.Title()) items[x]['replace']['Project'] = \ '<a href="%s">%s</a>' % (kit.aq_parent.absolute_url(), kit.aq_parent.Title()) items[x]['Barcode'] = obj.getField('Barcode').get(obj) items[x]['replace']['Title'] = "<a href='%s'>%s</a>" % \ (items[x]['url'], items[x]['Title']) # TODO: SPECIFY OBJ STATES WHERE USER CAN EDIT BARCODE if self.allow_edit and isActive(self.context) and \ getSecurityManager().checkPermission(ManageAliquots, obj) and \ items[x]['review_state'] == "sample_due": items[x]['allow_edit'] = [ 'Type', 'SubjectID', 'Barcode', 'Volume', 'Unit' ] items[x]['choices']['Type'] = biospecimen_types items[x]['choices']['Unit'] = VOLUME_UNITS ret.append(item) return ret
def folderitems(self, full_objects=False): items = BikaListingView.folderitems(self) bsc = getToolByName(self.context, 'bika_setup_catalog') brains = bsc(portal_type='SampleType', inactive_state='active') biospecimen_types = [ { 'ResultValue': brain.UID, 'ResultText': brain.title } for brain in brains ] ret = [] for x, item in enumerate(items): if not items[x].has_key('obj'): continue obj = items[x]['obj'] if not IBiospecimen.providedBy(obj): continue items[x]['Type'] = obj.getSampleType() and obj.getSampleType().Title() or '' items[x]['Volume'] = obj.getField('Volume').get(obj) items[x]['Unit'] = VOLUME_UNITS[0]['ResultText'] items[x]['SubjectID'] = obj.getField('SubjectID').get(obj) kit = obj.getField('Kit').get(obj) items[x]['Kit'] = kit items[x]['Project'] = obj.aq_parent if kit: items[x]['replace']['Kit'] = \ '<a href="%s">%s</a>' % (kit.absolute_url(), kit.Title()) items[x]['replace']['Project'] = \ '<a href="%s">%s</a>' % (kit.aq_parent.absolute_url(), kit.aq_parent.Title()) items[x]['Barcode'] = obj.getField('Barcode').get(obj) items[x]['replace']['Title'] = "<a href='%s'>%s</a>" % \ (items[x]['url'], items[x]['Title']) # TODO: SPECIFY OBJ STATES WHERE USER CAN EDIT BARCODE if self.allow_edit and isActive(self.context) and \ getSecurityManager().checkPermission(ManageAliquots, obj) and \ items[x]['review_state'] == "sample_due": items[x]['allow_edit'] = ['Type', 'SubjectID', 'Barcode', 'Volume', 'Unit'] items[x]['choices']['Type'] = biospecimen_types items[x]['choices']['Unit'] = VOLUME_UNITS ret.append(item) return ret
def objects_between_two_uids(context, uid_1, uid_2, portal_type, wf_1, wf_2, state): """Retrieve the objects of type portal_type between two ordered objects using their uids. """ w_tool = getToolByName(context, 'portal_workflow') uc = getToolByName(context, 'uid_catalog') first_id = uc(UID=uid_1)[0].id last_id = uc(UID=uid_2)[0].id objects = context.objectValues(portal_type) # Filter objects by workflow state active items = [] for obj in objects: if IBiospecimen.providedBy(obj): st1 = w_tool.getStatusOf(wf_1, obj) st2 = w_tool.getStatusOf(wf_2, obj) if st1.get('review_state', None) == state and \ st2.get('cancellation_state', None) == 'active' and \ first_id <= obj.getId() <= last_id: items.append(obj) return items