def Import(self): folder = self.context.bika_setup.bika_products rows = self.get_rows(3) bsc = getToolByName(self.context, 'bika_setup_catalog') suppliers = [o.getObject() for o in bsc(portal_type="Supplier")] for row in rows: title = row.get('Title') description = row.get('description', '') obj = _createObjectByType('Product', folder, tmpID()) obj.edit( title=title, description=description, Hazardous=self.to_bool(row.get('Hazardous', '')), Quantity=self.to_int(row.get('Quantity', 0)), Unit=row.get('Unit', ''), Price=str(row.get('Price', '0.00')) ) for supplier in suppliers: if supplier.Title() == row.get('Suppliers', ''): obj.setSupplier(supplier) break obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): pc = getToolByName(self.context, 'portal_catalog') rows = self.get_rows(3) for row in rows: # get the client object client_list = pc(portal_type="Client", Title=row.get('Client')) folder = client_list and client_list[0].getObject() or None if not folder: continue s_types = row.get('SampleTypes') a_services = row.get('AnalysisServices') st_objects = get_project_multi_items(self.context, s_types, 'SampleType', 'bika_setup_catalog') as_objects = get_project_multi_items(self.context, a_services, 'AnalysisService', 'bika_setup_catalog') obj = _createObjectByType('Project', folder, tmpID()) obj.edit( title=row.get('title'), description=row.get('description'), StudyType=row.get('StudyType', ''), AgeHigh=self.to_int(row.get('AgeHigh', 0)), AgeLow=self.to_int(row.get('AgeLow', 0)), NumParticipants=self.to_int(row.get('NumParticipants', 0)), SampleType=st_objects, Service=as_objects, DateCreated=row.get('DateCreated', ''), ) obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): folder = self.context.donors rows = self.get_rows(3) pc = getToolByName(self.context, 'portal_catalog') for row in rows: sample_donor_id = row.get('SampleDonorID') selected_project = row.get('SelectedProject', '') info_link = row.get('InfoLink') sex = row.get('Sex') age = row.get('Age') age_unit = row.get('AgeUnit') obj = _createObjectByType('SampleDonor', folder, tmpID()) # get the project project_list = pc(portal_type="Project", Title=selected_project) project = project_list and project_list[0].getObject() or None obj.edit(SampleDonorID=sample_donor_id, SelectedProject=project, InfoLink=info_link, Age=age, AgeUnit=age_unit) obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): pc = getToolByName(self.context, 'bika_catalog') folder = self.context.freezers rows = self.get_rows(3) for row in rows: if not row['CurrentReading']: continue deviceTitle = row.get('MonitoringDevice', None) mon_device = pc(portal_type='MonitoringDevice', title=deviceTitle) dev_obj = mon_device[0].getObject() if mon_device else None if not dev_obj: continue # Device reading de_reading = _createObjectByType('DeviceReading', dev_obj, tmpID()) de_reading.setCurrentReading(row['CurrentReading']) de_reading.setLabel(row['Label']) de_reading.setUnit(row['Unit']) de_reading.unmarkCreationFlag() renameAfterCreation(de_reading) # Freezer reading freezer = pc(portal_type="Freezer", Title=row.get('Freezer', None)) fr_obj = freezer[0].getObject() if freezer else None fr_reading = _createObjectByType('DeviceReading', fr_obj, tmpID()) fr_reading.setCurrentReading(row['CurrentReading']) fr_reading.setDatetimeRecorded(row['DatetimeRecorded']) fr_reading.setLabel(row['Label']) fr_reading.setUnit(row['Unit']) fr_reading.unmarkCreationFlag() fr_reading.unmarkCreationFlag() renameAfterCreation(fr_reading)
def create_sample(context, request, values): obj = _createObjectByType('Sample', context, tmpID()) # st_loc_list = pc(portal_type='StoragePosition', Title=values.get('StorageLocation')) # storage_location = st_loc_list and st_loc_list[0].getObject() or None obj.edit( title=values['title'], description=values['description'], Project=values['Project'], AllowSharing=values['AllowSharing'], SampleType=values['SampleType'], StorageLocation=values['StorageLocation'], SubjectID=values['SubjectID'], Barcode=values['Barcode'], Volume=values['Volume'], Unit=values['Unit'], LinkedSample=values['LinkedSample'], DateCreated=values['DateCreated'], ) obj.unmarkCreationFlag() renameAfterCreation(obj) if values.has_key('APISource'): obj.api_source = values['APISource'] from baobab.lims.subscribers.sample import ObjectInitializedEventHandler ObjectInitializedEventHandler(obj, None) return obj
def Import(self): folder = self.context.bika_setup.bika_stockitems rows = self.get_rows(3) bsc = getToolByName(self.context, 'bika_setup_catalog') pc = getToolByName(self.context, 'portal_catalog') for row in rows: products = bsc(portal_type="Product", title=row.get('Product')) product = products and products[0].getObject() or None description = row.get('description', '') st_loc_list = pc(portal_type='UnmanagedStorage', Title=row.get('StorageLocation')) storage_location = st_loc_list and st_loc_list[0].getObject( ) or None obj = _createObjectByType('StockItem', folder, tmpID()) obj.edit( Product=product, StorageLocation=storage_location, description=description, Quantity=self.to_int(row.get('Quantity', 0)), orderId=row.get('InvoiceNzr', ''), batchId=row.get('BatchNr', ''), receivedBy=row.get('ReceivedBy'), dateReceived=row.get('DateReceived', ''), ) new_quantity = int(product.getQuantity()) + int( row.get('Quantity')) product.setQuantity(new_quantity) product.reindexObject() obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): folder = self.context.bika_setup.bika_storagetypes rows = self.get_rows(3) for row in rows: title = row.get('title') description = row.get('description', '') obj = _createObjectByType('StorageType', folder, tmpID()) obj.edit(title=title, description=description) obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): folder = self.context.monitoring_devices rows = self.get_rows(3) for row in rows: title = row.get('title', '') if not title: continue description = row.get('description', '') obj = _createObjectByType('MonitoringDevice', folder, tmpID()) obj.edit(title=title, description=description, MACAddress=row.get('MACAddress')) obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): folder = self.context.lab_hosts rows = self.get_rows(3) for row in rows: if self.isExistingTitle('LabHost', row.get('title')): continue title = row.get('title') description = row.get('description', '') obj = _createObjectByType('LabHost', folder, tmpID()) obj.edit( title=title, description=description, ) obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): folder = self.context.bika_setup.bika_kittemplates rows = self.get_rows(3) catalog = getToolByName(self.context, 'bika_setup_catalog') for row in rows: template_name = row.get('templateName') kit_component = Kit_Components(self, self.workbook, self.dataset_project, self.dataset_name, template_name, catalog) product_list = kit_component.get_product_list() obj = _createObjectByType('KitTemplate', folder, tmpID()) obj.edit(title=template_name, ProductList=product_list) obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): folder = self.context.disease_ontologies rows = self.get_rows(3) for row in rows: title = row.get('title') description = row.get('description', '') version = row.get('Version') code = row.get('Code') free_text = row.get('FreeText') obj = _createObjectByType('DiseaseOntology', folder, tmpID()) obj.edit(title=title, description=description, Version=version, Code=code, FreeText=free_text) obj.unmarkCreationFlag() renameAfterCreation(obj)
def create_biospecimen(self, row): barcode = str(row.get('Barcode')) project = self.get_project(row.get('Project', '')) sample_type = self.get_sample_type(row.get('SampleType', '')) volume = self.get_volume(row.get('Volume', '')) title = row.get('title', barcode) self.confirm_unique_title(barcode) storage_location = self.get_storage_location(row.get('StorageLocation', '')) sampling_date = row.get('SamplingDate', '') if storage_location: storage_wf_state = self._wf.getInfoFor(storage_location, 'review_state') if storage_wf_state == 'occupied': raise ExcelSheetError('Import Error Sample %s: Storage %s already occupied.' % (title, storage_location.Title())) date_created = row.get('DateCreated', datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M')) if not date_created: date_created = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M') member = self.get_member() obj = _createObjectByType('Sample', project, tmpID()) obj.edit( title=title, description=row.get('description'), Project=project, SampleType=sample_type, StorageLocation=storage_location, SubjectID=row.get('SubjectID'), Barcode=barcode, Volume=volume, Unit=row.get('Unit'), BabyNumber=row.get('BabyNo', ''), DateCreated=date_created, SamplingDate=sampling_date, # FrozenTime=row.get('FrozenTime'), ChangeUserName=member, ChangeDateTime=date_created, ) obj.reindexObject() obj.unmarkCreationFlag() renameAfterCreation(obj) from baobab.lims.subscribers.sample import ObjectInitializedEventHandler ObjectInitializedEventHandler(obj, None)
def Import(self): folder = self.context.organisms rows = self.get_rows(3) for row in rows: if self.isExistingTitle('Organism', row.get('title')): continue title = row.get('title') genus = row.get('genus', '') species = row.get('species', '') obj = _createObjectByType('Organism', folder, tmpID()) obj.edit( title=title, Genus=genus, Species=species, ) obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): pc = getToolByName(self.context, 'portal_catalog') rows = self.get_rows(3) for row in rows: # get the project project_list = pc(portal_type="Project", Title=row.get('Project')) if project_list: project = project_list[0].getObject() else: continue # get the kit template if it exists bsc = getToolByName(self.context, 'bika_setup_catalog') kit_template_list = bsc(portal_type="KitTemplate", title=row.get('KitTemplate')) kit_template = kit_template_list and kit_template_list[ 0].getObject() or None stock_items = [] try: if kit_template: stock_items = self.assign_stock_items( kit_template, row, bsc, pc) except ValueError as e: continue obj = _createObjectByType('Kit', project, tmpID()) obj.edit( title=row.get('title'), description=row.get('description'), Project=project, KitTemplate=kit_template, FormsThere=row.get('FormsThere'), DateCreated=row.get('DateCreated', ''), ) if kit_template: obj.setStockItems(stock_items) update_quantity_products(obj, bsc) obj.unmarkCreationFlag() renameAfterCreation(obj)
def Import(self): folder = self.context.freezers rows = self.get_rows(3) pc = getToolByName(self.context, 'bika_catalog') for row in rows: title = row.get('title', '') if not title: continue description = row.get('description', '') deviceTitle = row.get('MonitoringDevice', '') device = pc(portal_type='MonitoringDevice', title=deviceTitle) device_obj = device[0].getObject() if device else None obj = _createObjectByType('Freezer', folder, tmpID()) obj.edit( title=title, description=description, MonitoringDevice=device_obj, ) obj.unmarkCreationFlag() renameAfterCreation(obj) notify(ObjectInitializedEvent(obj))
def create_freezer_readings(self, readings, freezer): # Device Reading # slice out \xb0C on the result because it throws an ascii error # unit defaults to °C so we can avoid the ascii error current_reading = readings['channels'][0] # Date comes back as u'/Date(1619779624000+0000)/' record_date = readings['datetime'] record_date = dt.fromtimestamp( int(re.findall(r"\d+", record_date)[0]) / 1000) freezer_reading = _createObjectByType('DeviceReading', freezer, tmpID()) freezer_reading.setCurrentReading(float(current_reading[0:-2])) freezer_reading.setDatetimeRecorded(DT(record_date)) unit = freezer_reading.getUnit() + str(current_reading[-1]) freezer_reading.setUnit(unit) freezer_reading.unmarkCreationFlag() renameAfterCreation(freezer_reading) return 'Done'
def create_sample_type(context, request, values): obj = _createObjectByType('SampleType', context, tmpID()) # st_loc_list = pc(portal_type='StoragePosition', Title=values.get('StorageLocation')) # storage_location = st_loc_list and st_loc_list[0].getObject() or None obj.edit( title=values['title'], description=values['description'], RetentionPeriod=values['RetentionPeriod'], Hazardous=to_bool(values['Hazardous']), #SampleMatrix=samplematrix, Prefix=values['Prefix'], MinimumVolume=values['MinimumVolume'], #ContainerType=containertype ) obj.unmarkCreationFlag() renameAfterCreation(obj) return obj
def create_biospecimen(self, row): barcode = str(row.get('Barcode')) batch_id = str(row.get('BatchID', '')) brains = self._bc(portal_type='SampleBatch', title=batch_id) if brains: batch = brains[0].getObject() else: raise ExcelSheetError('Import Error Sample %s: Batch %s not found.' % (barcode, batch_id)) parent = self.get_linked_sample(str(row.get('Parent', ''))) if not parent: raise ExcelSheetError('Import Error Sample %s: Parent %s not found.' % (barcode, row.get('Parent', ''))) project_obj = batch.getProject() sample_type = self.get_sample_type(row.get('SampleType', '')) volume = self.get_volume(row.get('Volume', '')) sampling_date = row.get('SamplingTime', '') title = row.get('Title', barcode) self.confirm_unique_title(barcode) storage_location = self.get_storage_location(row.get('StorageLocation', '')) if storage_location: storage_wf_state = analysis_state = self._wf.getInfoFor(storage_location, 'review_state') if storage_wf_state == 'occupied': raise ExcelSheetError('Import Error Sample %s: Storage %s already occupied.' % (barcode, storage_location.Title())) obj = _createObjectByType('Sample', project_obj, tmpID()) field_b = obj.getField('Batch') field_b.set(obj, batch) date_created = row.get('DateCreated', datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M')) if not date_created: date_created = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M') unit = row.get('Unit', '') if not unit: raise ExcelSheetError( 'Import Error Sample %s: Unit is a compulsory field.' % barcode) member = self.get_member() obj.edit( title=title, description=row.get('description'), Project=project_obj, SampleType=sample_type, StorageLocation=storage_location, SubjectID=row.get('SubjectID'), Barcode=barcode, Volume=volume, Unit=row.get('Unit'), # BabyNumber=row.get('BabyNo', ''), DateCreated=date_created, LinkedSample=parent, SamplingDate=sampling_date, FrozenTime=row.get('FrozenTime'), ChangeUserName=member, ChangeDateTime=date_created, ) obj.reindexObject() obj.unmarkCreationFlag() renameAfterCreation(obj) from baobab.lims.subscribers.sample import ObjectInitializedEventHandler ObjectInitializedEventHandler(obj, None)
def create_biospecimen(self, row): pc = getToolByName(self.context, 'portal_catalog') bc = getToolByName(self.context, 'bika_catalog') # get the project project_list = pc(portal_type="Project", Title=row.get('Project')) project = project_list and project_list[0].getObject() or None if not project: raise sampletype_list = pc(portal_type="SampleType", Title=row.get('SampleType')) sample_type = sampletype_list and sampletype_list[0].getObject( ) or None if not sample_type: raise linked_sample_list = pc(portal_type="Sample", Title=row.get('LinkedSample', '')) linked_sample = linked_sample_list and linked_sample_list[0].getObject( ) or None sample_donor_list = bc(portal_type="SampleDonor", SampleDonorID=row.get('SampleDonor', '')) sample_donor = sample_donor_list and sample_donor_list[0].getObject( ) or None disease_ontology_list = bc(portal_type="DiseaseOntology", Title=row.get('DiseaseOntology', '')) disease_ontology = disease_ontology_list and disease_ontology_list[ 0].getObject() or None barcode = row.get('Barcode') if not barcode: raise try: volume = str(row.get('Volume')) float_volume = float(volume) if not float_volume: raise except: raise obj = _createObjectByType('Sample', project, tmpID()) st_loc_list = pc(portal_type='StoragePosition', Title=row.get('StorageLocation')) storage_location = st_loc_list and st_loc_list[0].getObject() or None obj.edit( title=row.get('title'), description=row.get('description'), Project=project, DiseaseOntology=disease_ontology, AllowSharing=row.get('AllowSharing'), Donor=sample_donor, SampleType=sample_type, StorageLocation=storage_location, SubjectID=row.get('SubjectID'), Barcode=barcode, Volume=volume, Unit=row.get('Unit'), LinkedSample=linked_sample, DateCreated=row.get('DateCreated'), AnatomicalSiteTerm=row.get('AnatomicalSiteTerm'), AnatomicalSiteDescription=row.get('AnatomicalSiteDescription'), ) obj.unmarkCreationFlag() renameAfterCreation(obj) from baobab.lims.subscribers.sample import ObjectInitializedEventHandler ObjectInitializedEventHandler(obj, None)
def create_virus_sample(self, row): folder = self.context.virus_samples project = self.getObject('Project', row.get('Project')) sample_type = self.getObject('SampleType', row.get('SampleType')) storage_location = self.getObject('StoragePosition', row.get('StorageLocation')) anatomical_material = self.getObject('AnatomicalMaterial', row.get('AnatomicalMaterial')) organism = self.getObject('Organism', row.get('Organism')) collection_device = self.getObject('CollectionDevice', row.get('CollectionDevice')) host = self.getObject('Host', row.get('Host')) host_disease = self.getObject('HostDisease', row.get('HostDisease')) lab_host = self.getObject('LabHost', row.get('LabHost')) instrument_type = self.getObject('InstrumentType', row.get('InstrumentType')) instrument = self.getObject('Instrument', row.get('Instrument')) host_age = row.get('HostAge', '') try: volume = str(row.get('Volume')) float_volume = str(float(volume)) if not float_volume: raise Exception('Volume %s not found' % row.get('Volume')) except Exception as e: print('-----Exception in %s' % str(e)) obj = _createObjectByType('VirusSample', folder, tmpID()) # st_loc_list = pc(portal_type='StoragePosition', Title=row.get('StorageLocation')) # storage_location = st_loc_list and st_loc_list[0].getObject() or None obj.edit( title=row.get('title'), Barcode=row.get('barcode'), Project=project, SampleType=sample_type, StorageLocation=storage_location, Volume=float_volume, Unit=row.get('Unit'), AnatomicalMaterial=anatomical_material, AllowSharing=row.get('AllowSharing'), WillReturnFromShipment=row.get('WillReturnFromShipment'), # Repository Accession Numbers BioSampleAccession=row.get('BioSampleAccession'), # Sample Collector and Processing SampleCollectedBy=row.get('SampleCollectedBy'), SampleCollectionDate=row.get('SampleCollectionDate'), SampleReceivedDate=row.get('SampleReceivedDate'), GeoLocDate=row.get('GeoLocDate'), GeoLocState=row.get('GeoLocState'), Organism=organism, Isolate=row.get('Isolate'), PurposeOfSampling=row.get('PurposeOfSampling'), CollectionDevice=collection_device, # hhh CollectionProtocol=row.get('CollectionProtocol'), SpecimenProcessing=row.get('SpecimenProcessing'), LabHost=lab_host, PassageNumber=row.get('PassageNumber'), PassageMethod=row.get('PassageMethod'), # Host Information HostSubjectID=row.get('HostSubjectID'), Host=host, HostDisease=host_disease, HostGender=row.get('HostGender'), HostAge=str(host_age), HostAgeUnit=row.get('HostAgeUnit'), # Host Exposure Information ExposureCountry=row.get('ExposureCountry'), ExposureEvent=row.get('ExposureEvent'), # Sequencing Information LibraryID=row.get('LibraryID'), InstrumentType=instrument_type, Instrument=instrument, SequencingProtocolName=row.get('SequencingProtocolName'), ) obj.unmarkCreationFlag() renameAfterCreation(obj) from baobab.lims.subscribers.sample import ObjectInitializedEventHandler ObjectInitializedEventHandler(obj, None)
def Import(self): folder = self.context.samplebatches rows = self.get_rows(3) self._errors = [] self._pc = getToolByName(self.context, 'portal_catalog') for row in rows: selected_project = row.get('Project', '') #import pdb;pdb.set_trace() if selected_project: project_list = self._pc(portal_type="Project", Title=selected_project) project = project_list and project_list[0].getObject() or None else: continue subject_id = row.get('SubjectID') # sheet_parent_biospecimen = row.get('ParentBiospecimen', '') # parent_biospecimen = None # if sheet_parent_biospecimen: parent_biospecimen_text = str(row.get('ParentBiospecimen', '')) if parent_biospecimen_text: parent_biospecimen_list = self._pc(portal_type="Sample", Title=parent_biospecimen_text) parent_biospecimen = parent_biospecimen_list and parent_biospecimen_list[0].getObject() or None if not parent_biospecimen: self._errors.append('Import batch error: Parent %s was not found' % parent_biospecimen_text) continue else: self._errors.append('Import batch error: Parent sample cannot be blank.') # TODO: VERIFY IT LATER storage_locations = row.get('StorageLocations', '') boxes = self.getStorageLocations(storage_locations) batch_id = str(row.get('BatchID', '')) obj = _createObjectByType('SampleBatch', folder, tmpID()) date_created = row.get('DateCreated', datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M')) if not date_created: date_created = datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M') member = self.get_member() obj.edit( title=batch_id, Description=row.get('Description', ''), BatchId=batch_id, BatchType=row.get('BatchType', ''), Project=project, SubjectID=subject_id, StorageLocation=boxes, Quantity=row.get('Quantity', 0), ParentBiospecimen=parent_biospecimen, DateCreated=date_created, SerumColour=row.get('SerumColour', ''), CfgDateTime=row.get('CfgDateTime', ''), ChangeUserName=member, ChangeDateTime=date_created, ) # import pdb;pdb.set_trace() obj.reindexObject() obj.unmarkCreationFlag() renameAfterCreation(obj)
def _renameAfterCreation(self, check_auto_id=False): from baobab.lims.idserver import renameAfterCreation renameAfterCreation(self)