Create or update a lab test result

distru-mutate-test-resultWrite

Creates or updates one lab test result (a COA potency record) on a package or batch: its header and its cannabinoid and terpene values.

Inputs

Every tool also takes the common inputs.

FieldTypeRequiredDescription
actionenum
CREATEUPDATE
Yes
idstringNoRequired for UPDATE. Resolve via distru-search-test-results.
packageIdstringNoCREATE only, or batchId: the package the result is uploaded to. Resolve via distru-search-packages.
batchIdstringNoCREATE only, or packageId: the batch the result is uploaded to. Resolve via distru-search-batches.
namestringNoRequired for CREATE. Without one from the user, the COA's sample or report ID; ask only if the COA has none.
labNamestring or nullNoSend null to clear it.
labLicenseNumberstring or nullNoSend null to clear it.
releaseDatestring or nullNoYYYY-MM-DD. Send null to clear it.
mgUnitenum
MG_PER_GMG_PER_ML
NoWhat the mg fields are per. Required whenever an mg value is sent; must match the COA.
makePrimarybooleanNotrue makes it the primary result of the item it was uploaded to and the items that inherit it. On CREATE a result becomes primary anyway when the item has none.
valuesobject[]NoRequired for CREATE. Values to set; only cannabinoid and terpene fields are accepted.
values[].fieldIdstringYesFrom testResultFields of distru-get-package / distru-get-batch (includeTestResultFields), e.g. thc_percentage, beta_myrcene_mg_per_unit.
values[].valuestring or number or nullYesIn the field's unit.

Output

Presence on a nested field assumes its parent exists.

FieldTypePresenceDescription
testResultobjectAlways
testResult.idstringAlways
testResult.namestringAlways
testResult.labNamestringCan be null
testResult.labLicenseNumberstringCan be null
testResult.releaseDatestringCan be null
testResult.batchobjectCan be null
testResult.batch.idstringAlways
testResult.batch.namestringAlways
testResult.batch.batchNumberstringCan be null
testResult.packageobjectCan be null
testResult.package.idstringAlways
testResult.package.metrcLabelstringAlways
testResult.appliesToobjectAlways
testResult.appliesTo.packagesobject[]Always
testResult.appliesTo.packages[].idstringAlways
testResult.appliesTo.packages[].metrcLabelstringAlways
testResult.appliesTo.packages[].productobjectAlways
testResult.appliesTo.packages[].product.namestringAlways
testResult.appliesTo.packagesCountnumberAlways
testResult.appliesTo.batchesobject[]Always
testResult.appliesTo.batches[].idstringAlways
testResult.appliesTo.batches[].namestringAlways
testResult.appliesTo.batches[].batchNumberstringCan be null
testResult.appliesTo.batchesCountnumberAlways
testResult.valuesobject[]Always
testResult.values[].fieldIdstringAlways
testResult.values[].namestringAlways
testResult.values[].unitstringCan be null"%", "mg/g" or "mg/mL".
testResult.values[].valuestringAlwaysDecimal string.
What the AI reads

Creates or updates one lab test result (a COA potency record) on a package or batch: its header and its cannabinoid and terpene values. Before writing, read the results that already apply to the item (distru-search-test-results with packageIds / batchIds). If any does, list them plus "new result" and ask the user which to write to; never pick one yourself. Only fields turned on for the product category of the item a result is uploaded to are accepted. Read them with distru-get-package or distru-get-batch (includeTestResultFields): for CREATE on the item, for UPDATE on the package or batch of the result's search row, which may differ from the item the user named when the result is inherited. "Package or batch not found" also comes back for an inactive package or deleted batch, and on UPDATE when every item the result applies to is inactive or hidden from your teams. Write each value in the unit the COA states, a % value in its % field and an mg value in its mg field; never convert. Save a value the COA reports as ND or <LOQ as 0, and say so in your summary. Values that look misread are refused, naming the field: recheck the COA, never adjust a value to pass. Sparse update: on UPDATE only the fields and values passed change; one sent as null is cleared. A change shows on every package and batch the result applies to: after writing, summarize appliesTo, inactive items included. It lists the first 50 of each plus counts; say "and N more" past that. Results can't be deleted here; the user deletes one in Distru. Returns the result as distru-search-test-results does, plus appliesTo.