eLabSDK.SampleType

getSampleTypeMeta(sampleTypeID, callback)

Retrieve metadata for a specific sample type.

This fetches comprehensive metadata information for the specified sample type, including
custom fields (meta fields), field definitions, validation rules, and other sample type
configuration. The metadata is returned via callback and includes all custom field
definitions that are configured for the sample type. Use this to dynamically build forms,
display sample type information, or validate sample data against type requirements.

Kind: global function

ParamTypeDescription
sampleTypeIDnumberThe numeric ID of the sample type to retrieve metadata for
callbackfunctionCallback function executed with the metadata response
callback.responseObjectThe sample type metadata object containing field definitions

Example

// Get and display sample type metadata
eLabSDK.ready(function() {
  var sampleType = new eLabSDK.SampleType();
  
  sampleType.getSampleTypeMeta(123, function(metadata) {
    console.log('Sample Type Metadata:', metadata);
    console.log('Custom fields:', metadata.metaFields);
    
    // Display field information
    metadata.metaFields.forEach(function(field) {
      console.log('Field: ' + field.name + ' (Type: ' + field.type + ')');
    });
  });
});

Example

// Build dynamic form based on sample type
eLabSDK.ready(function() {
  var sampleType = new eLabSDK.SampleType();
  var sampleTypeID = 456;
  
  sampleType.getSampleTypeMeta(sampleTypeID, function(metadata) {
    var $form = $('#customSampleForm');
    
    // Create input for each custom field
    metadata.metaFields.forEach(function(field) {
      var $field = $('<div class="form-field"></div>');
      $field.append('<label>' + field.name + '</label>');
      
      if (field.type === 'text') {
        $field.append('<input type="text" name="' + field.id + '" />');
      } else if (field.type === 'number') {
        $field.append('<input type="number" name="' + field.id + '" />');
      }
      // ... handle other field types
      
      $form.append($field);
    });
  });
});

Example

// Validate sample data against sample type metadata
eLabSDK.ready(function() {
  var sampleType = new eLabSDK.SampleType();
  
  function validateSampleData(sampleTypeID, sampleData) {
    sampleType.getSampleTypeMeta(sampleTypeID, function(metadata) {
      var errors = [];
      
      metadata.metaFields.forEach(function(field) {
        if (field.required && !sampleData[field.id]) {
          errors.push('Required field missing: ' + field.name);
        }
        
        if (field.type === 'number' && isNaN(sampleData[field.id])) {
          errors.push('Invalid number for field: ' + field.name);
        }
      });
      
      if (errors.length > 0) {
        console.error('Validation errors:', errors);
        alert('Please fix the following errors:\n' + errors.join('\n'));
      } else {
        console.log('Data valid - ready to create sample');
        createSample(sampleData);
      }
    });
  }
  
  validateSampleData(789, { field1: 'value1', field2: 123 });
});

© 2023 eLabNext