Esempio n. 1
0
class Sample(Entity):
    "Customer's sample to be analyzed; associated with a project."

    _URI = 'samples'
    _PREFIX = 'smp'

    name = StringDescriptor('name')
    date_received = StringDescriptor('date-received')
    date_completed = StringDescriptor('date-completed')
    project = EntityDescriptor('project', Project)
    submitter = EntityDescriptor('submitter', Researcher)
    # artifact: defined below
    udf = UdfDictionaryDescriptor()
    udt = UdtDictionaryDescriptor()
    notes = EntityListDescriptor('note', Note)
    files = EntityListDescriptor(nsmap('file:file'), File)
    externalids = ExternalidListDescriptor()
    # biosource XXX

    @classmethod
    def create(cls, lims, container, position, **kwargs):
        """Create an instance of Sample from attributes then post it to the LIMS

        Udfs can be sent in with the kwarg `udfs`. It should be a dictionary-like.
        """
        if not isinstance(container, Container):
            raise TypeError('%s is not of type Container' % container)
        udfs = kwargs.pop("udfs", None)
        instance = super(Sample, cls)._create(lims,
                                              creation_tag='samplecreation',
                                              **kwargs)

        location = ElementTree.SubElement(instance.root, 'location')
        ElementTree.SubElement(location, 'container', dict(uri=container.uri))
        position_element = ElementTree.SubElement(location, 'value')
        position_element.text = position

        # NOTE: This is a quick fix. I assume that it must be possible to initialize samples
        # with UDFs
        for key, value in udfs.items():
            attrib = {
                "name": key,
                "xmlns:udf": "http://genologics.com/ri/userdefined",
            }
            udf = ElementTree.SubElement(instance.root,
                                         'udf:field',
                                         attrib=attrib)
            udf.text = value

        data = lims.tostring(ElementTree.ElementTree(instance.root))
        instance.root = lims.post(uri=lims.get_uri(cls._URI), data=data)
        instance._uri = instance.root.attrib['uri']
        return instance
Esempio n. 2
0
class Lab(Entity):
    "Lab; container of researchers."

    _URI = 'labs'
    _PREFIX = 'lab'

    name = StringDescriptor('name')
    billing_address = StringDictionaryDescriptor('billing-address')
    shipping_address = StringDictionaryDescriptor('shipping-address')
    udf = UdfDictionaryDescriptor()
    udt = UdtDictionaryDescriptor()
    externalids = ExternalidListDescriptor()
    website = StringDescriptor('website')
Esempio n. 3
0
class Project(Entity):
    "Project concerning a number of samples; associated with a researcher."

    _URI = 'projects'
    _PREFIX = 'prj'

    name = StringDescriptor('name')
    open_date = StringDescriptor('open-date')
    close_date = StringDescriptor('close-date')
    invoice_date = StringDescriptor('invoice-date')
    researcher = EntityDescriptor('researcher', Researcher)
    udf = UdfDictionaryDescriptor()
    udt = UdtDictionaryDescriptor()
    files = EntityListDescriptor(nsmap('file:file'), File)
    externalids = ExternalidListDescriptor()
class Sample(Entity):
    "Customer's sample to be analyzed; associated with a project."

    _URI = 'samples'
    _TAG = 'sample'
    _PREFIX = 'smp'

    name = StringDescriptor('name')
    date_received = StringDescriptor('date-received')
    date_completed = StringDescriptor('date-completed')
    project = EntityDescriptor('project', Project)
    submitter = EntityDescriptor('submitter', Researcher)
    # artifact: defined below
    udf = UdfDictionaryDescriptor()
    udt = UdtDictionaryDescriptor()
    notes = EntityListDescriptor('note', Note)
    files = EntityListDescriptor(nsmap('file:file'), File)
    externalids = ExternalidListDescriptor()
    # biosource XXX
    control_type = EntityDescriptor('control-type', Controltype)

    @classmethod
    def create(cls, lims, container, position, udfs=None, **kwargs):
        """Create an instance of Sample from attributes then post it to the LIMS"""
        if udfs is None:
            udfs = {}
        if not isinstance(container, Container):
            raise TypeError('%s is not of type Container' % container)
        instance = super(Sample, cls)._create(lims,
                                              creation_tag='samplecreation',
                                              udfs=udfs,
                                              **kwargs)

        location = ElementTree.SubElement(instance.root, 'location')
        ElementTree.SubElement(location, 'container', dict(uri=container.uri))
        position_element = ElementTree.SubElement(location, 'value')
        position_element.text = position
        data = lims.tostring(ElementTree.ElementTree(instance.root))
        instance.root = lims.post(uri=lims.get_uri(cls._URI), data=data)
        instance._uri = instance.root.attrib['uri']
        return instance
Esempio n. 5
0
class Researcher(Entity):
    "Person; client scientist or lab personnel. Associated with a lab."

    _URI = 'researchers'
    _PREFIX = 'res'

    first_name = StringDescriptor('first-name')
    last_name = StringDescriptor('last-name')
    phone = StringDescriptor('phone')
    fax = StringDescriptor('fax')
    email = StringDescriptor('email')
    initials = StringDescriptor('initials')
    lab = EntityDescriptor('lab', Lab)
    udf = UdfDictionaryDescriptor()
    udt = UdtDictionaryDescriptor()
    externalids = ExternalidListDescriptor()

    # credentials XXX

    @property
    def name(self):
        return "%s %s" % (self.first_name, self.last_name)