Skip to main content

thunkmetrc_client/services/
lab_tests.rs

1use crate::client::MetrcClient;
2use serde_json::Value;
3use std::error::Error;
4
5pub struct LabTestsClient<'a> {
6    pub(crate) client: &'a MetrcClient,
7}
8
9impl<'a> LabTestsClient<'a> {
10    /// POST CreateRecord
11    /// Submits Lab Test results for one or more packages. NOTE: This endpoint allows only PDF files, and uploaded files can be no more than 5 MB in size. The Label element in the request is a Package Label.
12    /// Permissions Required:
13    /// - View Packages
14    /// - Manage Packages Inventory
15    /// Parameters:
16    /// - body (Option<&Value>): Request body
17    /// - license_number (Option<String>): Filter by licenseNumber
18    pub async fn create_lab_tests_record(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
19        let mut path = format!("/labtests/v2/record");
20        let mut query_params = Vec::new();
21        if let Some(p) = license_number {
22            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
23        }
24        if !query_params.is_empty() {
25            path.push_str("?");
26            path.push_str(&query_params.join("&"));
27        }
28
29        self.client.send(reqwest::Method::POST, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
30    }
31    /// GET GetBatches
32    /// Retrieves a list of Lab Test batches.
33    /// Parameters:
34    /// - page_number (Option<String>): Filter by pageNumber
35    /// - page_size (Option<String>): Filter by pageSize
36    pub async fn get_lab_tests_batches(&self, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
37        let mut path = format!("/labtests/v2/batches");
38        let mut query_params = Vec::new();
39        if let Some(p) = page_number {
40            query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
41        }
42        if let Some(p) = page_size {
43            query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
44        }
45        if !query_params.is_empty() {
46            path.push_str("?");
47            path.push_str(&query_params.join("&"));
48        }
49
50        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
51    }
52    /// GET GetLabTestDocumentById
53    /// Retrieves a specific Lab Test result document by its Id for a given Facility.
54    /// Permissions Required:
55    /// - View Packages
56    /// - Manage Packages Inventory
57    /// Parameters:
58    /// - id (str): Path parameter id
59    /// - license_number (Option<String>): Filter by licenseNumber
60    pub async fn get_lab_tests_lab_test_document_by_id(&self, id: &str, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
61        let mut path = format!("/labtests/v2/labtestdocument/{}", urlencoding::encode(id).as_ref());
62        let mut query_params = Vec::new();
63        if let Some(p) = license_number {
64            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
65        }
66        if !query_params.is_empty() {
67            path.push_str("?");
68            path.push_str(&query_params.join("&"));
69        }
70
71        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
72    }
73    /// GET GetLabTestsTypes
74    /// Returns a list of Lab Test types.
75    /// Parameters:
76    /// - page_number (Option<String>): Filter by pageNumber
77    /// - page_size (Option<String>): Filter by pageSize
78    pub async fn get_lab_tests_types(&self, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
79        let mut path = format!("/labtests/v2/types");
80        let mut query_params = Vec::new();
81        if let Some(p) = page_number {
82            query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
83        }
84        if let Some(p) = page_size {
85            query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
86        }
87        if !query_params.is_empty() {
88            path.push_str("?");
89            path.push_str(&query_params.join("&"));
90        }
91
92        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
93    }
94    /// GET GetResults
95    /// Retrieves Lab Test results for a specified Package.
96    /// Permissions Required:
97    /// - View Packages
98    /// - Manage Packages Inventory
99    /// Parameters:
100    /// - license_number (Option<String>): Filter by licenseNumber
101    /// - package_id (Option<String>): Filter by packageId
102    /// - page_number (Option<String>): Filter by pageNumber
103    /// - page_size (Option<String>): Filter by pageSize
104    pub async fn get_lab_tests_results(&self, license_number: Option<String>, package_id: Option<String>, page_number: Option<String>, page_size: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
105        let mut path = format!("/labtests/v2/results");
106        let mut query_params = Vec::new();
107        if let Some(p) = license_number {
108            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
109        }
110        if let Some(p) = package_id {
111            query_params.push(format!("packageId={}", urlencoding::encode(&p)));
112        }
113        if let Some(p) = page_number {
114            query_params.push(format!("pageNumber={}", urlencoding::encode(&p)));
115        }
116        if let Some(p) = page_size {
117            query_params.push(format!("pageSize={}", urlencoding::encode(&p)));
118        }
119        if !query_params.is_empty() {
120            path.push_str("?");
121            path.push_str(&query_params.join("&"));
122        }
123
124        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
125    }
126    /// GET GetStates
127    /// Returns a list of all lab testing states.
128    /// Parameters:
129    pub async fn get_lab_tests_states(&self, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
130        let path = format!("/labtests/v2/states");
131
132        self.client.send(reqwest::Method::GET, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
133    }
134    /// PUT UpdateLabTestDocument
135    /// Updates one or more documents for previously submitted lab tests.
136    /// Permissions Required:
137    /// - View Packages
138    /// - Manage Packages Inventory
139    /// Parameters:
140    /// - body (Option<&Value>): Request body
141    /// - license_number (Option<String>): Filter by licenseNumber
142    pub async fn update_lab_tests_lab_test_document(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
143        let mut path = format!("/labtests/v2/labtestdocument");
144        let mut query_params = Vec::new();
145        if let Some(p) = license_number {
146            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
147        }
148        if !query_params.is_empty() {
149            path.push_str("?");
150            path.push_str(&query_params.join("&"));
151        }
152
153        self.client.send(reqwest::Method::PUT, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
154    }
155    /// PUT UpdateResultsRelease
156    /// Releases Lab Test results for one or more packages.
157    /// Permissions Required:
158    /// - View Packages
159    /// - Manage Packages Inventory
160    /// Parameters:
161    /// - body (Option<&Value>): Request body
162    /// - license_number (Option<String>): Filter by licenseNumber
163    pub async fn update_lab_tests_results_release(&self, license_number: Option<String>, body: Option<&Value>) -> Result<Option<Value>, Box<dyn Error + Send + Sync>> {
164        let mut path = format!("/labtests/v2/results/release");
165        let mut query_params = Vec::new();
166        if let Some(p) = license_number {
167            query_params.push(format!("licenseNumber={}", urlencoding::encode(&p)));
168        }
169        if !query_params.is_empty() {
170            path.push_str("?");
171            path.push_str(&query_params.join("&"));
172        }
173
174        self.client.send(reqwest::Method::PUT, &path, body.map(|b| serde_json::to_value(b).unwrap()).as_ref()).await
175    }
176}
177