Skip to content

Instantly share code, notes, and snippets.

@johnnyji
Last active July 28, 2022 23:05
Show Gist options
  • Save johnnyji/ff25192bc03724a20be9371eb5114149 to your computer and use it in GitHub Desktop.
Save johnnyji/ff25192bc03724a20be9371eb5114149 to your computer and use it in GitHub Desktop.

User from Company ID: 197968 is not seeing test results auto-populated, despite package saying "TestPassed" on June 13th, package was imported in Distru on July 17th

SELECT metrc_id FROM packages WHERE id = 2713720;

 metrc_id
----------
  6543105
(1 row)

Now we want to see if there are any test results associated:

SELECT * FROM metrc_package_test_results WHERE metrc_package_id = 6543105 AND company_id = 197968;

 company_id | metrc_package_id | metrc_test_result_id |        inserted_at         |         updated_at
------------+------------------+----------------------+----------------------------+----------------------------
     197968 |          6543105 |              1143119 | 2022-06-13 19:27:05.140764 | 2022-06-13 19:27:05.140764
(1 row)

Okay so there is actually a test result mapping, but we see no test result in the UI, let's see if there is a test result record from cache and if it matches the metrc_test_result_id on the mapping:

SELECT c.metrc_id FROM metrc_test_result_caches c WHERE c.archived_at IS NULL AND c.id = 1143119;

 metrc_id
----------
(0 rows)

So it turns out the mapping is there, but there is no cache record for the test result the mapping is mapped to. Next I'm going to send a cURL request (via Postman) to see if trying to fetch the test results for that package even returns anything from Metrc:

curl --location --request GET 'https://api-mi.metrc.com/labtests/v1/results?packageId=6543105&licenseNumber=AU-P-000237' \
--header 'Authorization: Basic [INSERT AUTH TOKEN]"

This returned a bunch of test results, here's a couple for example:

[
    {
        "PackageId": 6543105,
        "LabTestResultId": 1143119,
        "LabFacilityLicenseNumber": "AU-SC-000110",
        "LabFacilityName": "Therapeutic Health Choice, LLC",
        "SourcePackageLabel": "1A4050300026481000002973",
        "ProductName": "Smokiez | 100MGTHC 1:1 CBG | Sour Peach Fruit Chews | AU - Retail",
        "ProductCategoryName": "Infused-Edible",
        "TestPerformedDate": "2022-06-13",
        "OverallPassed": true,
        "RevokedDate": null,
        "ResultReleased": true,
        "ResultReleaseDateTime": "2022-06-13T19:25:03+00:00",
        "TestTypeName": "Trifloxystrobin (ppm) Infused Edible",
        "TestPassed": true,
        "TestResultLevel": 0.0000,
        "TestComment": "Non Detect",
        "TestInformationalOnly": false,
        "LabTestDetailRevokedDate": null
    },
    {
        "PackageId": 6543105,
        "LabTestResultId": 1143119,
        "LabFacilityLicenseNumber": "AU-SC-000110",
        "LabFacilityName": "Therapeutic Health Choice, LLC",
        "SourcePackageLabel": "1A4050300026481000002973",
        "ProductName": "Smokiez | 100MGTHC 1:1 CBG | Sour Peach Fruit Chews | AU - Retail",
        "ProductCategoryName": "Infused-Edible",
        "TestPerformedDate": "2022-06-13",
        "OverallPassed": true,
        "RevokedDate": null,
        "ResultReleased": true,
        "ResultReleaseDateTime": "2022-06-13T19:25:03+00:00",
        "TestTypeName": "Thiamethoxam (ppm) Infused Edible",
        "TestPassed": true,
        "TestResultLevel": 0.0000,
        "TestComment": "Non Detect",
        "TestInformationalOnly": false,
        "LabTestDetailRevokedDate": null
    },
    ...
  ]

I noticed that this test has a TestTypeName of Thiamethoxam (ppm) Infused Edible which is something we don't auto-import. So that's why the cache is empty in Distru and why we did not auto import the test. The only types we auto import are THC, CBD, mg, total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment