Skip to main content

Create Lab Test

POST 

/api/v1/lab-tests

Lab Test Creation Modes

Create a new Lab Test. When status is not sent (or is null), the system decides between three creation modes based on provided data:

Submitted Test Creation:

  • Provide all required test result fields: sampleReceiptDate, reportIssueDate, reportNumber, testProperties, and overallResult
  • Creates a lab test with "submitted" status, or "completed" when the Lab Test Form completes tests automatically
  • All provided data is saved

New Test Creation:

  • Omit test result fields but provide all required fields specified in the Lab Test Form
  • Creates a lab test with "new" status. When the Lab Test Form confirms tests automatically, the status is "confirmed"
  • Test Packages and Test Properties are kept as described in "Test Packages and Test Properties on New and Draft Creation" below
  • The following data is discarded: sampleReceiptDate, reportIssueDate, reportNumber, originalReportNumber, revisionNumber, overallResult, and testReport type attachments
  • Non-report attachments are preserved

Draft Test Creation:

  • Omit test result fields AND one or more required fields from the Lab Test Form
  • Creates a lab test with "draft" status
  • Test Packages and Test Properties are kept as described in "Test Packages and Test Properties on New and Draft Creation" below
  • The following data is discarded: sampleReceiptDate, reportIssueDate, reportNumber, originalReportNumber, revisionNumber, overallResult, and testReport type attachments
  • Non-report attachments are preserved

Test Packages and Test Properties on New and Draft Creation:

  • They are kept only when the Test Requirements component is active on the creation tab of the Lab Test Form. Otherwise every Test Package and Test Property in the request is discarded
  • A Test Package or Test Property (matched by id) is kept when it is enabled on the platform and is available to the organization that sends the creation API request
  • A kept Test Package adds all of its current Test Properties, at their latest version
  • Kept Test Packages stay on the lab test even when testProperties is empty or not sent, so a request with Test Packages only keeps them
  • A kept Test Property is linked to its latest version and all of that version's Test Conditions. It is shown under its testPackageId when that is a kept Test Package containing it, and under "Additional Test Properties" otherwise
  • Test results are not saved: result, reviewResult, and the testConditions of a Test Property's items / materials / styles are ignored. When status is sent, the Test Property's own testConditions is applied (see "Test Conditions of a Test Property")
  • Test Packages and Test Properties that are not kept are discarded, and the lab test is still created with the kept ones
  • Whether the Test Requirements component is mandatory does not change the creation mode

Discarded data in the response:

  • On New and Draft creation, message lists only the fields that were sent and discarded. Discarded Test Packages and Test Properties are listed with their IDs, for example testPackages (PKG-9), testProperties (TP-3, TP-7). Kept ones are not listed
  • message is omitted when nothing that was sent was discarded
Explicit Creation Status

Send status to choose the creation mode instead of letting the system decide it. labTestStatus in the response is the status of the lab test once it is created, after the Lab Test Form's automatic confirmation or completion.

status = submitted:

  • sampleReceiptDate, reportIssueDate, reportNumber, testProperties and overallResult are required, as are all mandatory creation fields of the Lab Test Form
  • Creates a lab test with "submitted" status, or "completed" when the Lab Test Form completes tests automatically
  • All provided data is saved

status = new:

  • All mandatory creation fields of the Lab Test Form are required
  • Creates a lab test with "new" status, or "confirmed" when the Lab Test Form confirms tests automatically
  • Data is kept and discarded as on New Test Creation above, and Test Packages and Test Properties are kept as described in "Test Packages and Test Properties on New and Draft Creation"

status = draft:

  • Mandatory creation fields of the Lab Test Form are not required
  • Creates a lab test with "draft" status. Data is kept and discarded as on Draft Test Creation above

When something required is missing:

  • The request is rejected with HTTP 400 and the lab test is not created. Nothing is discarded
  • missingFields lists every missing field: field is where it belongs in the request (for example factories[0].contacts[0].email or items[1].itemName), and formField is the Lab Test Form field that makes it mandatory (for example stakeholderInformation (factory) > mainContactStakeholder > email). The test result fields have no formField
  • Format errors, such as an invalid date, are reported first. missingFields is checked only once there are none

Any value other than draft, new or submitted is rejected with HTTP 400.

Test Conditions of a Test Property

testProperties[].testConditions lists which Test Conditions of a Test Property the lab test keeps. It is read only when status is sent; without status it is ignored and not checked. When it is left out or null, nothing changes: on Draft and New the Test Property keeps every Test Condition of its latest version, and on Submitted the Test Conditions come from items / materials / styles.

Matching:

  • Every entry must have a Test Condition ID (id). Entries are matched by id only (exact match)
  • A Test Property created on the platform: each id must be a Test Condition of its latest version. name is not used. A Test Condition with no Test Condition ID cannot be listed
  • A Test Property that is not on the platform (status = submitted only): an id that is a Test Condition of the Test Property's latest version keeps that Test Condition. Any other id creates a Test Condition for this lab test with that id and the entry's name, which is then required. It is created Required, with input method Test Result
  • The kept Test Conditions keep their catalog order and settings (Required / Optional, input method, value range, follow-up actions), whatever the order of the request. The choice applies to every item, material or style

status = draft or new:

  • Only the listed Test Conditions are kept, also for a Test Property that a kept Test Package brings. When the lab test is started, every item gets only those Test Conditions
  • A Test Property that is discarded is reported as discarded and its testConditions is ignored

status = submitted:

  • Every Test Condition under items / materials / styles of that Test Property must match a listed one by id
  • Every listed Test Condition must have a result for each item / material / style of that Test Property. Partial results are not accepted

Rejected with HTTP 400, and the lab test is not created, when for a kept Test Property:

  • testConditions is []
  • an entry has no id
  • an id is not a Test Condition of the latest version, on a Test Property created on the platform, or without a name to create it on a Test Property that is not on the platform
  • the same id is listed twice
  • status = submitted: a Test Condition under items / materials / styles is not in testConditions, or a listed Test Condition has no result for an item / material / style

invalidTestConditions lists every error with the Test Property ID, the Test Condition ID or name, and the item, material or style ID for a Test Condition under items / materials / styles. When fields are also missing, missingFields is in the same response.

When the Lab Test Form selects tests Automatically with an active Test Program, the Test Program decides the tests instead of testConditions. See "Tests Set by the Test Program".

The Upload/Update Pre-Created Lab Test API (PUT) does not read testConditions on a Test Property.

Tests Set by the Test Program

When status is sent and the Lab Test Form selects tests Automatically with an active Test Program, the Test Program decides the lab test's Test Packages, Test Properties and Test Conditions. This replaces the rules for Test Packages and Test Properties above, for every status.

What the lab test gets:

  • The Test Packages and Test Properties the Test Program picks, each Test Property at its latest version with only the picked Test Conditions, and each condition's Required and Locked as the Test Program sets them
  • testPackages, testProperties and the testConditions of each Test Property are only compared with the Test Program's tests. They are not checked against the catalog and nothing is created from them

status = submitted:

  • A Test Property's result and reviewResult, and a Test Condition result under its items / materials / styles, are saved when the Test Program picks that Test Property and that Test Condition
  • Any other result is rejected with HTTP 400 and the lab test is not created. refusedResults lists every refused result: the Test Property ID, and for a condition result the item / material / style ID and the Test Condition ID
  • Every Test Property the Test Program picks must have a result, and every Test Condition it picks for that Test Property must have a result for each item / material / style of the lab test. If any of them has no result in the request, the request is rejected with HTTP 400 and the lab test is not created
  • missingResults lists each test without a result: the Test Property ID, and for a Test Condition the item / material / style ID and the Test Condition ID. For example { "testPropertyId": "PHYS-SPR-01", "field": "result" } and { "testPropertyId": "PHYS-SPR-01", "itemId": "ITEM-1", "testConditionId": "C-01", "field": "result" }
  • When the request has both refused results and tests without a result, one HTTP 400 lists both, in refusedResults and missingResults

Response:

  • discarded lists each Test Package, Test Property and Test Condition of the request that the Test Program did not pick. The conditions of a discarded Test Property are not listed again
  • message then ends with "The tests were set by the Test Program of the Lab Test Form. Tests in the request that it did not pick were discarded. See discarded."

Requests without status, forms that select tests Manually, forms without the test selection setting, and forms whose Test Program is deactivated or not set are not affected.

Request​

Responses​

Lab Test Created Successfully