eLabSDK.Experiment

Members

NameDescription
sectionsArray of eLabSDK.Experiment.Section

Sections of experiment

Functions

NameDescription
getExperimentID()Get the ID of this experiment.

This retrieves the numeric experiment ID from the experiment object. The experiment ID
is either the ID that was loaded during initialization or the ID that was assigned when
a new experiment was created. Use this to reference the experiment in API calls, links,
or other operations that require the experiment ID.
getStudyID() | Get the study ID that this experiment belongs to.

This retrieves the numeric study ID associated with this experiment. Every experiment
belongs to a study (project), and this method returns that parent study's ID. The study
ID is loaded from the experiment data or set during experiment creation. Use this to
navigate to the parent study, filter experiments by study, or perform study-level
operations.
addSection(config) | Add a new section to this experiment.

This creates and adds a new section to the experiment with the specified header text
and section type. Sections are the building blocks of experiments, containing different
types of content like paragraphs, images, data tables, samples, or files. The section
is automatically added to the experiment's sections array when created. Use this to
programmatically build experiment content or add sections during automated workflows.
getSection(sectionID) | Get a specific section from this experiment by its section ID.

This searches through the experiment's sections array and returns the section object
matching the specified section ID. Returns null if no section with that ID is found.
Use this to access and manipulate specific sections, such as updating content, reading
data, or performing operations on individual sections within an experiment.

Events

NameDescription
"onLoaded"Use this to access class
"onCreated"Use this to access class

sections

Array of eLabSDK.Experiment.Section
Sections of experiment

Kind: global variable
Properties

NameType
sectionsarray

getExperimentID()

Get the ID of this experiment.

This retrieves the numeric experiment ID from the experiment object. The experiment ID
is either the ID that was loaded during initialization or the ID that was assigned when
a new experiment was created. Use this to reference the experiment in API calls, links,
or other operations that require the experiment ID.

Kind: global function
Returns: number - The numeric experiment ID
Example

// Get experiment ID after loading
var experiment = new eLabSDK.Experiment({
  experimentID: 123,
  onLoaded: function() {
    var expId = this.getExperimentID();
    console.log('Loaded experiment ID: ' + expId);
  }
});

Example

// Get ID after creating new experiment
var newExperiment = new eLabSDK.Experiment({
  name: 'My New Experiment',
  studyID: 456,
  onCreated: function() {
    var expId = this.getExperimentID();
    console.log('Created experiment ID: ' + expId);
    window.location.href = '/members/experiments/journal/?view=' + expId;
  }
});

Example

// Use in custom action
var experiment = new eLabSDK.Experiment({
  experimentID: 789,
  onLoaded: function() {
    var expId = this.getExperimentID();
    
    var exportBtn = new eLabSDK.GUI.Button({
      label: 'Export',
      action: function() {
        exportExperiment(expId);
      }
    });
  }
});

getStudyID()

Get the study ID that this experiment belongs to.

This retrieves the numeric study ID associated with this experiment. Every experiment
belongs to a study (project), and this method returns that parent study's ID. The study
ID is loaded from the experiment data or set during experiment creation. Use this to
navigate to the parent study, filter experiments by study, or perform study-level
operations.

Kind: global function
Returns: number - The numeric study ID that this experiment belongs to
Example

// Get study ID from loaded experiment
var experiment = new eLabSDK.Experiment({
  experimentID: 123,
  onLoaded: function() {
    var studyId = this.getStudyID();
    console.log('Experiment belongs to study: ' + studyId);
  }
});

Example

// Navigate to parent study
var experiment = new eLabSDK.Experiment({
  experimentID: 456,
  onLoaded: function() {
    var studyId = this.getStudyID();
    
    var goToStudyBtn = new eLabSDK.GUI.Button({
      label: 'View Parent Study',
      icon: 'fa-folder',
      action: function() {
        window.location.href = '/members/projects/studies/edit/?studyID=' + studyId;
      }
    });
  }
});

Example

// Check if experiments are in same study
var exp1 = new eLabSDK.Experiment({ experimentID: 101 });
var exp2 = new eLabSDK.Experiment({ experimentID: 102 });

exp1.onLoaded(function() {
  exp2.onLoaded(function() {
    if (exp1.getStudyID() === exp2.getStudyID()) {
      console.log('Both experiments are in the same study');
    }
  });
});

addSection(config)

Add a new section to this experiment.

This creates and adds a new section to the experiment with the specified header text
and section type. Sections are the building blocks of experiments, containing different
types of content like paragraphs, images, data tables, samples, or files. The section
is automatically added to the experiment's sections array when created. Use this to
programmatically build experiment content or add sections during automated workflows.

Kind: global function

ParamTypeDescription
configObjectConfiguration object for the new section
config.sectionHeaderstringThe header text to display at the top of the section
config.sectionTypestringThe type of section to create (e.g., 'PARAGRAPH', 'IMAGE', 'FILE', 'SAMPLESIN', 'SAMPLESOUT', 'DATATABLE')
[config.onCreated]functionOptional callback executed when the section is created. Receives the section object as 'this'.

Example

// Add a paragraph section to an experiment
var experiment = new eLabSDK.Experiment({
  experimentID: 123,
  onLoaded: function() {
    this.addSection({
      sectionHeader: 'Experimental Procedure',
      sectionType: 'PARAGRAPH',
      onCreated: function() {
        console.log('Section created with ID: ' + this.options.sectionID);
      }
    });
  }
});

Example

// Add multiple sections
var experiment = new eLabSDK.Experiment({
  experimentID: 456,
  onLoaded: function() {
    // Add methods section
    this.addSection({
      sectionHeader: 'Methods',
      sectionType: 'PARAGRAPH'
    });
    
    // Add results section
    this.addSection({
      sectionHeader: 'Results',
      sectionType: 'DATATABLE'
    });
    
    // Add samples section
    this.addSection({
      sectionHeader: 'Input Samples',
      sectionType: 'SAMPLESIN'
    });
  }
});

Example

// Create experiment with sections programmatically
var newExp = new eLabSDK.Experiment({
  name: 'Automated Experiment',
  studyID: 789,
  onCreated: function() {
    var exp = this;
    exp.addSection({
      sectionHeader: 'Protocol',
      sectionType: 'PARAGRAPH',
      onCreated: function() {
        console.log('Experiment ' + exp.getExperimentID() + ' created with protocol section');
      }
    });
  }
});

getSection(sectionID)

Get a specific section from this experiment by its section ID.

This searches through the experiment's sections array and returns the section object
matching the specified section ID. Returns null if no section with that ID is found.
Use this to access and manipulate specific sections, such as updating content, reading
data, or performing operations on individual sections within an experiment.

Kind: global function
Returns: eLabSDK.Experiment.Sectionnull - The section object if found, or null if it doesn't exist

ParamTypeDescription
sectionIDnumberThe numeric ID of the section to retrieve

Example

// Get a specific section and log its data
var experiment = new eLabSDK.Experiment({
  experimentID: 123,
  onLoaded: function() {
    var section = this.getSection(456);
    if (section) {
      console.log('Section header: ' + section.data.header);
      console.log('Section type: ' + section.data.sectionType);
    } else {
      console.log('Section not found');
    }
  }
});

Example

// Update specific section content
var experiment = new eLabSDK.Experiment({
  experimentID: 789,
  onLoaded: function() {
    var section = this.getSection(101);
    if (section && section instanceof eLabSDK.Experiment.Section.Text) {
      section.updateContent('Updated section text');
    }
  }
});

Example

// Check if section exists before operating on it
var experiment = new eLabSDK.Experiment({
  experimentID: 321,
  onLoaded: function() {
    var sectionId = 555;
    var section = this.getSection(sectionId);
    
    if (section === null) {
      console.log('Section ' + sectionId + ' does not exist');
      return;
    }
    
    // Proceed with section operations
    processSectionData(section);
  }
});

"onLoaded"

Use this to access class

Kind: event emitted
Example

var ev = experimentObject.onLoaded(function () { 
          alert('Experiment onLoaded'); 
      });

"onCreated"

Use this to access class

Kind: event emitted
Example

var ev = experimentObject.onCreated(function () { 
          alert('Experiment created'); 
      });

© 2023 eLabNext