Example #1
0
    def gridData(self):
        columns=self.rptCfg.uicolumns
        idName=self.rptCfg.getId()
        results = []
        reqs = DBSession().query(Request).select_from(outerjoin(Request,RequestItem))     
        childrenDisp = []
        dispense = reqs.filter(RequestItem.request_item_dispense_date == None).order_by(Request.request_id).all() 
        for row in dispense:
#            if row.hasOpenItems() or len(row.items)==0:
            rowData = []
            for col in columns:
                val = getattr(row,col.id,None)
                if isinstance(val,datetime):
                    val = val.strftime('%m/%d/%Y')
                rowData.append(val)
           
            childrenDisp.append({'id':row.__dict__[idName], 'data':rowData})

        childrenComplete = []
        complete = reqs.filter(RequestItem.request_item_dispense_date > (datetime.now()-timedelta(days=1))).order_by(Request.request_id).all() 
        for row in complete:
            if not row.hasOpenItems():
                rowData = []
                for col in columns:
                    val = getattr(row,col.id,None)
                    if isinstance(val,datetime):
                        val = val.strftime('%m/%d/%Y')
                    rowData.append(val)
                childrenComplete.append({'id':row.__dict__[idName], 'data':rowData})

        results.append(dict(id='open',data=['Open Requests'],children=childrenDisp))
        results.append(dict(id='closed',data=['Recently Closed'],children=childrenComplete))
        results.append(dict(id='search',data=['Search']))
        return results
Example #2
0
    def register(self,pbarId,uid,request_id=None,prefix=None):
        pbar = getTaskMonitor(pbarId)
        log.debug('in register')
        pbar.setText('Loading dispense data...')
        file = self.getFile()
        pbar.startProgress(len(file.rows))
        rpt=Report(self.rptCfg)
        failures=[]
        successes=[]
        for fileRow in file.rows:
            rowValue = fileRow.unpickle()
            try:
                transaction.begin()
                srcVialBarcode = rowValue['src_vial_barcode']
                srcVialWell = rowValue['src_vial_rack_well']
                srcRackBarcode = rowValue.get('src_rack_barcode', None)
                
                # Track down the src vial
                if srcVialBarcode:
                    srcVial = Vial.byBarcode(srcVialBarcode)
                elif srcRackBarcode:
                    srcRack = Rack.byBarcode(srcRackBarcode)
                    srcVial = Vial.byRackAndWellName(srcRack, srcVialWell)
                    
                if srcVial is None:
                    raise ClientException("Could not find source vial in database")
                
                lot=srcVial.lot
                vial = Vial()
                if rowValue['vial_barcode']:
                    vial.vial_barcode = rowValue['vial_barcode']
                vial.vial_lot_aliquot_no = lot.getVialCount()+1
                amount = rowValue.get('amount', None)
                amountUnits = rowValue.get('amountUnits', None)
                vial.vial_amt = calcValueFromDisp(amount, amountUnits)
                vial.vial_amt_units = amountUnits
                
                conc = rowValue.get('conc', None)
                concUnits = rowValue.get('concUnits', None)
                vial.vial_conc = calcValueFromDisp(conc, concUnits)
                vial.vial_conc_units = concUnits
                
                srcAmount = rowValue.get('srcAmount', None)
                srcAmountUnits = rowValue.get('srcAmountUnits', None)
                srcAmtChange = calcValueFromDisp(srcAmount, srcAmountUnits)
                srcVial.dispense(srcAmtChange)

                lot.vials.append(vial)
                rackBarcode = None
                rackBarcode = rowValue['rack_barcode']
                rackTypeId = rowValue['rack_type_id']
                rackWellName = rowValue['vial_rack_well']
                on_hand=rowValue['on_hand']
                if on_hand not in ['Y', 'N']:
                    on_hand = None
                dbRack = None
                if rackTypeId:
                    if rackBarcode:
                        dbRack = Rack.byBarcode(rackBarcode)
                    if dbRack is None:
                        dbRack = Rack()
                        dbRack.rack_type_id = rackTypeId
                        if rackBarcode:
                            dbRack.rack_barcode = rackBarcode
                        DBSession().add(dbRack)
                        DBSession().flush()
                    dbRack.rack_isactive = on_hand
                if dbRack and len(dbRack.type.wells) >0:
                    vial.rack = dbRack
                    rackWell=RackWell.byTypeAndName(dbRack.type, rackWellName)
                    vial.vial_rack_well_id = rackWell.rack_well_id
                elif rackWellName:
                    raise ClientException('Well %s was specified but no valid rack or plate was given' % rackWellName)
                vial.parent = srcVial
                if request_id is not None:
                    req=DBSession().query(Request).get(request_id)
                    if req is None:
                        raise ClientException('Unable to find corresponding compound request')
                    itemQuery=DBSession().query(RequestItem).filter(RequestItem.request == req)
                    itemQuery=itemQuery.filter(RequestItem.mol==lot.mol)
                    itemQuery=itemQuery.filter(RequestItem.request_item_dispense_date == None)
                    item=None
                    for i in itemQuery:
                        if i.request_item_lot_number == lot.lot_number or i.request_item_lot_number is None:
                            item=i
                            break
                    if item is None:
                        item=RequestItem()
                        item.request=req
                        item.mol = lot.mol
                        item.request_item_lot_number = lot.lot_number
                    item.request_item_dispense_date = datetime.now()
                    item.request_item_dispense_from_vial_id = srcVial.vial_id
                    item.request_item_dispense_to_vial_id = vial.vial_id
                    item.request_item_dispense_amt = srcAmount
                    item.request_item_dispense_amt_units = srcAmountUnits

                transaction.commit()
                pbar.incProgress()
                successes.append(fileRow)
            except Exception,e:
                log.exception(e)
                rec=fileRow.unpickle()
                rec['msg'] = "<div style='color:red'>" + str(e[0]) + "</div>"
                fileRow.pickle(rec)
                fileRow.has_error=1
                failures.append(fileRow)
                transaction.abort()