def test_simple_equals(self): expected = { "fieldName": "cntn_id", "operator": "equals", "value": "test" } self.assertEqual(expected, equals("cntn_id", "test").to_dict())
def test_fetch_advanced(self): def request_callback(request): body = json.loads(request.body) self.assertEqual(body["startRow"], 0) self.assertEqual(body["endRow"], 1) self.assertEqual(body["sortBy"], ["cntn_createdOn"]) self.assertEqual(body["criteria"]["operator"], "equals") self.assertEqual(body["criteria"]["fieldName"], "cntn_id") self.assertEqual(body["criteria"]["value"], "test") return (200, {}, json.dumps({"entities": []})) responses.add_callback( responses.GET, 'http://localhost:9999/rest/Content/advanced', callback=request_callback, content_type='application/json', ) slims = Slims("testSlims", "http://localhost:9999", "admin", "admin") entities = slims.fetch("Content", equals("cntn_id", "test"), sort=["cntn_createdOn"], start=0, end=1) self.assertEquals(entities, [])
def test_not(self): expected = { "operator": "not", "criteria": [ { "fieldName": "cntn_id", "operator": "equals", "value": "test" }, ] } criteria = is_not(equals("cntn_id", "test")) self.assertEqual(expected, criteria.to_dict())
def test_conjunction(self): expected = { "operator": "and", "criteria": [ { "fieldName": "cntn_id", "operator": "equals", "value": "test" }, { "fieldName": "cntn_barCode", "operator": "iStartsWith", "value": "blah" }, ] } criteria = conjunction().add(equals("cntn_id", "test")).add( starts_with("cntn_barCode", "blah")) self.assertEqual(expected, criteria.to_dict())
# Example N_1: # We fetch Content records without criteria # This means that the fetch includes all the contents in the database # By giving start and end parameters the output is limited to the 10th to the # 30th record to be returned print("Example 1") records = slims.fetch("Content", None, start=10, end=30) # The fields cntn_id and cntn_barCode of the content records will be displayed display_results(records, ["cntn_id", "cntn_barCode"]) # Example N_2: # Fetching content records with the equals criteria; # The parameters are the field on which to filter and the value. This way the # filter only returns contents whose cntn_id is equal to "fish" print("\n\nExample 2") records = slims.fetch("Content", equals("cntn_id", "fish")) display_results(records, ["cntn_id", "cntn_createdOn"]) # Example N_3: # Fetching content records with a conjunction (and). This filters # on content records for which the cntn_id is not null and the cntn_id starts # with fish print("\n\nExample 3") records = slims.fetch( "Content", conjunction().add(is_not_null("cntn_id")).add( starts_with("cntn_id", "fish"))) # display_results has three arguments, the list of records, the list of fields # to display and finally the number of results to display display_results(records, ["cntn_id"], 10)
from __future__ import print_function import web from web import form from slims.slims import Slims from slims.criteria import is_not from slims.criteria import equals from slims.content import Status render = web.template.render('templates/') slims = Slims("slims", "http://localhost:9999", "admin", "admin") # Populate the comboboxes # Searching for data by fetching order_types = slims.fetch("OrderType", None) content_types = slims.fetch("ContentType", equals("cntp_useBarcodeAsId", True)) locations = slims.fetch("Location", None) requestables = slims.fetch("Requestable", is_not(equals("rqbl_type", "WORKFLOW"))) dic_order_type = {} for order_type in order_types: dic_order_type.update({order_type.rdtp_name.value: order_type}) dic_content_type = {} for content_type in content_types: dic_content_type.update({content_type.cntp_name.value: content_type}) dic_location = {} for location in locations: dic_location.update({location.lctn_name.value: location})
A BMI Calculation is done based on both. The plotting requires matplotlib (pip install matplotlib) run this script using the underneath command in the folder plotting python main.py """ from __future__ import division from slims.slims import Slims from slims.criteria import equals, is_one_of import matplotlib.pyplot as plt slims = Slims("slims", "http://localhost:9999", "admin", "admin") # Data fetch -> selection of patients and their results patients = slims.fetch("Content", equals("cntp_name", "Patient")) patient_pks = map(lambda patient: patient.pk(), patients) results = slims.fetch("Result", is_one_of("rslt_fk_content", patient_pks)) lengths = [] weights = [] BMI = [] x_axis_values = [] # Identification of the result per test print("Fetching necessary data...") for result in results: # first identification the length Test results if result.rslt_fk_test.displayValue in "length Test": lengths.append(result.rslt_value.value)
from __future__ import print_function from slims.slims import Slims from slims.criteria import equals from slims.content import Status import sys slims = Slims("slims", "http://localhost:9999", "admin", "admin") # Example N_1: Creating a content record; here a Content of content type DNA # in the location Building Test. Requires a location called # "Building test" (of location type Building) and a content type # "DNA" (with use barcode as id) print("Example 1") # Fetch DNA content type dna_type = slims.fetch("ContentType", equals("cntp_name", "DNA")) if not dna_type: sys.exit("No DNA Content type found, can not continue") # Fetch Building Test location (ideally with location type Building, # but this is not mandatory) locations = slims.fetch("Location", equals("lctn_name", "Building Test")) if not locations: sys.exit("No location called Building Test found, can not continue") print("Creating DNA Record...") created_dna = slims.add( "Content", { 'cntn_fk_contentType': dna_type[0].pk(),