To call the snd API from another LabKey module, use LABKEY.Ajax.request. For example:
LABKEY.Ajax.request({
url: LABKEY.ActionURL.buildURL("snd", "getEvent.api"),
method: 'POST',
success: onSuccess,
failure: onError
});
function onSuccess(results) {
alert(“Success!”);
}
function onError(errorInfo) {
alert(“Failure!”);
}
See LABKEY.Query JS API documentation.
A package is the building block of the SND schema. A package is the detailed representation of a node in the hierarchy, containing metadata about the procedure, workflow step, or other type of data the node represents. The following APIs are defined for package searching, creation, editing, viewing and deletion.
SND APIs
Input:
{
pkgId: int - only if updating or cloning,
description: string - (required),
active: boolean - (required),
repeatable: boolean - (required),
clone: boolean - (optional)
narrative: string - (required),
testIdNumberStart: int - (optional) used for testing only,
categories: [categoryId (int), ...] - (optional),
attributes: [Property Descriptors] - (optional),
extraFields: [Property Descriptors] - (optional)
subPackages: [{ - (optional)
superPkgId: int - (required),
sortOrder: int - (required),
repeatable: boolean - (required),
required: boolean - (required)
},
...]
}
Output: No JSON
Input:
{
packages:[
packageId: int,
…] (required),
excludeExtraFields: boolean (optional) - Default false. Used to speed up metadata queries for the UI.
excludeLookups: boolean (optional) - Default false. Used to speed up metadata queries for the UI.
includeFullSubpackages: boolean (optional) - Default false. Returns the full super package hierarchy.
}
Output: Package.
Updated or useful APIs to be called on snd.PkgCategories table
SND APIs
Input:
{
projectId: int - Only for project edits and revisions,
revisionNum: int - Only for project edits and revisions,
description: string (required),
Active: boolean (required),
referenceId: int (required),
startDate: string (required) (yyyy/MM/dd),
endDate: string (optional) (yyyy/MM/dd),
endDateRevised: string (optional) - End date for previous revision if doing revision (yyyy/MM/dd)
isEdit: boolean (optional) - default false,
isRevision: boolean (optional) - default false,
extraFields: [Property Descriptors] - (optional),
projectItems: [ (optional)
Active: boolean (required),
superPkgId: int (required)
]
}
Output: No JSON
Input:
{
projectId: int - (required),
revisionNum: int (required)
}
Output: Project
SND APIs
Input:
{
eventId: int (required),
getTextNarrative: boolean (optional) - default false,
getRedactedNarrative: boolean (optional) - default false,
getHtmlNarrative: boolean (optional) - default false,
getRedactedHtmlNarrative: boolean (optional) - default false
}
Output: Event.
Input:
event: {
eventId: int - (optional) only if updating an existing event,
date: date string - (required) event date (yyyy-MM-ddThh:mm:ss ISO8601),
projectIdRev: string - (required) “projectId|projectRev”,
subjectId: string - (required) ,
qcState: string - (required) ,
note: string - (optional),
extraFields: [Property Descriptors] - (optional) depends on customization,
eventData: [{ - (optional) event with no data would not have these.
eventDataId: int - (optional) for updating,
superPkgId: int - (required),
sortOrder: int - (optional)
extraFields: [Property Descriptors] - (optional) depends on customization,
attributes: [{
propertyId: int - (required) either propertyId or propertyName is required,
propertyName: string - (required),
Value: string - (required),
},
…]
}
…]
}
Output: Event.
This provides metadata about an attribute or field.
{
conceptURI: string,
defaultValue: string,
format: string,
label: string,
lookupQuery: string,
lookupSchema: string,
name: string,
propertyId: int,
rangeURI: string,
redactedText: string,
required: boolean,
scale: int,
validators: [Property Validators]
value: string
}
Validation for attributes.
{
description: string,
errorMessage: string,
expression: string - ex. “~gte=1&~lte=300”,
name: string,
type: string
}
Event, EventData or AttributeData exceptions from the event APIs.
{
severity: string - Error, Warning or Info,
message: string
}
Full Event JSON:
{
eventId: int,
date: date string - event date (yyyy-MM-ddThh:mm:ss ISO8601),
projectIdRev: string - “projectId|projectRev”,
subjectId: string,
qcState: string,
note: string,
exception: Exception - Only if there are Event level exceptions to report,
redactedHtmlNarrative: string - Only if requested,
htmlNarrative: string - Only if requested,
redactedTextNarrative: string - Only if requested,
testNarrative: string - Only if requested,
extraFields: [Property Descriptors] - ex. USDA Code,
eventData: [{
eventDataId: int,
exception: Exception - Only if there are EventData level exceptions to report
superPkgId: int,
sortOrder: int,
narrativeTemplate: string,
extraFields: [Property Descriptors],
attributes: [{
propertyId: int,
propertyName: string,
Value: string,
propertyDescriptor: Property Descriptor (not for input),
exception: Exception - Only if there are AttributeData exceptions to report
},
…]
}
…]
}
Returned from the getPackage API.
{
pkgId: int,
superPkgId: int,
description: string,
active: boolean,
repeatable: boolean,
narrative: string,
hasEvent: boolean,
hasProject: boolean,
categories: [categoryId (int), ...],
attributes: [Property Descriptors],
extraFields: [Property Descriptors] - Not when excludeExtraFields is true
subPackages: [{
superPkgId: int,
pkgId: int,
description: string,
narrative: string,
sortOrder: int,
repeatable: boolean,
required: boolean,
attributes[Property Descriptors] - Only when includeFullSubpackages is true
subPackages:[...]
...],
attributeLookups: [lookup table (string)] - Not when excludeLookups is true
}
Returned from the getProject API.
{
projectId: int,
description: string,
revisionNum: int,
active: boolean,
startDate: string - date string (yyyy/MM/dd),
endDate: string - only if set (yyyy/MM/dd),
referenceId: int,
hasEvent: boolean,
extraFields: [Property Descriptors]
projectItems: [{
projectItemId: int,
active: boolean,
superPkgId: int
...],
}
Developers can test data entry user interface by testing the creation of events and attribute data using the API Testing framework. This JavaScript API for entering and retrieving data defined by a super package and associated with an event. You can test the business rules, all the JSON properties, and error cases for these APIs.
The tests iterate through a configurable list of tests in a separate file defined in a standard format. The desired results are stored in an external file for comparison.
Examples:
The list of tests is placed in a file named tests.js. When a test compares results to an expected value, the results are defined in data.js.To run the tests, navigate to your SND project and go to "snd-test.view#" there. Click Run Tests.