Add Patients to Cohort
curl --request POST \
--url https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"patientIds": [
"<string>"
],
"allPatients": true
}
'import requests
url = "https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient"
payload = {
"patientIds": ["<string>"],
"allPatients": True
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({patientIds: ['<string>'], allPatients: true})
};
fetch('https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'patientIds' => [
'<string>'
],
'allPatients' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient"
payload := strings.NewReader("{\n \"patientIds\": [\n \"<string>\"\n ],\n \"allPatients\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"patientIds\": [\n \"<string>\"\n ],\n \"allPatients\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"patientIds\": [\n \"<string>\"\n ],\n \"allPatients\": true\n}"
response = http.request(request)
puts response.read_bodyimport { MetriportMedicalApi } from "@metriport/api-sdk";
const metriport = new MetriportMedicalApi("YOUR_API_KEY");
// Add specific patients to cohort
const cohortWithPatients = await metriport.addPatientsToCohort({
cohortId: "00000000-0000-0000-0000-000000000000",
patientIds: [
"11111111-1111-1111-1111-111111111111",
"22222222-2222-2222-2222-222222222222"
]
});
// Add all patients to cohort
const cohortWithAllPatients = await metriport.addPatientsToCohort({
cohortId: "00000000-0000-0000-0000-000000000000",
allPatients: true
});
Cohort
Add Patients to Cohort
Bulk assign multiple patients to a cohort.
POST
/
medical
/
v1
/
cohort
/
{id}
/
patient
Add Patients to Cohort
curl --request POST \
--url https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"patientIds": [
"<string>"
],
"allPatients": true
}
'import requests
url = "https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient"
payload = {
"patientIds": ["<string>"],
"allPatients": True
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({patientIds: ['<string>'], allPatients: true})
};
fetch('https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'patientIds' => [
'<string>'
],
'allPatients' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient"
payload := strings.NewReader("{\n \"patientIds\": [\n \"<string>\"\n ],\n \"allPatients\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"patientIds\": [\n \"<string>\"\n ],\n \"allPatients\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.sandbox.metriport.com/medical/v1/cohort/{id}/patient")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"patientIds\": [\n \"<string>\"\n ],\n \"allPatients\": true\n}"
response = http.request(request)
puts response.read_bodyimport { MetriportMedicalApi } from "@metriport/api-sdk";
const metriport = new MetriportMedicalApi("YOUR_API_KEY");
// Add specific patients to cohort
const cohortWithPatients = await metriport.addPatientsToCohort({
cohortId: "00000000-0000-0000-0000-000000000000",
patientIds: [
"11111111-1111-1111-1111-111111111111",
"22222222-2222-2222-2222-222222222222"
]
});
// Add all patients to cohort
const cohortWithAllPatients = await metriport.addPatientsToCohort({
cohortId: "00000000-0000-0000-0000-000000000000",
allPatients: true
});
For more information, see the guide about Cohorts
Path Params
The ID of the cohort to assign patients to.
Body
You must provide eitherpatientIds or allPatients, but not both.
Array of patient IDs to assign to the cohort. Mutually exclusive with the
allPatients property.Property to confirm you want to assign all patients in your metriport
instance to the cohort. Mutually exclusive with the
patientIds array.Response
Confirmation message indicating the operation was successful.
The cohort details.
Show Cohort properties
Show Cohort properties
The unique identifier for the cohort (UUID format, e.g.,
00000000-0000-0000-0000-000000000000).The entity tag for optimistic concurrency control.
The unique name of the cohort within your organization.
The description of the cohort.
The color associated with the cohort.
The cohort's purpose of use:
treatment or operations.Configuration settings for the cohort.
Show Settings properties
Show Settings properties
Hide monitoring object properties
Hide monitoring object properties
HIE-based document monitoring - subscribes patients to HIE-based
document monitoring (non-ADT) / medical record refresh based on the cadence.
Show hie object properties
Show hie object properties
Enable or disable scheduled data pulls for HIE monitoring. Defaults to disabled.
When disabled, no scheduled pulls will occur regardless of the frequency setting.
How often scheduled data pulls should occur, can be one of
daily, weekly, biweekly or monthly. Defaults to monthly.See scheduled queries
for timing details.
ADT (Admission, Discharge, Transfer) monitoring - subscribes patients to ADT notifications
based on their primary address.
Show adt object properties
Show adt object properties
Enable or disable ADT monitoring notifications. Defaults to disabled.
Pharmacy / medication history monitoring - enables retail fill data monitoring where available.
Show pharmacy object properties
Show pharmacy object properties
Enable/disable pharmacy monitoring notifications. Defaults to disabled.
Pharmacy notifications are coming soon! While this feature is not yet live, you can configure
your Pharmacy notification settings now. These settings will automatically take effect when the feature launches.
Enable pharmacy data pulls at scheduled dates.
Show schedule object properties
Show schedule object properties
Enable or disable scheduled data pulls for pharmacy monitoring. When disabled, no
scheduled pulls will occur regardless of the frequency setting. Defaults to disabled.
How often scheduled data pulls should occur, can be one of
weekly, biweekly or monthly. Defaults to monthly.See scheduled queries
for timing details.
The number of patients assigned to this cohort.
import { MetriportMedicalApi } from "@metriport/api-sdk";
const metriport = new MetriportMedicalApi("YOUR_API_KEY");
// Add specific patients to cohort
const cohortWithPatients = await metriport.addPatientsToCohort({
cohortId: "00000000-0000-0000-0000-000000000000",
patientIds: [
"11111111-1111-1111-1111-111111111111",
"22222222-2222-2222-2222-222222222222"
]
});
// Add all patients to cohort
const cohortWithAllPatients = await metriport.addPatientsToCohort({
cohortId: "00000000-0000-0000-0000-000000000000",
allPatients: true
});
{
"message": "Patient(s) successfully added to cohort",
"cohort": {
"id": "00000000-0000-0000-0000-000000000000",
"eTag": "1",
"name": "High Risk",
"description": "Patients that need frequent and robust monitoring.",
"color": "red",
"purposeOfUse": "treatment",
"settings": {
"monitoring": {
"hie": {
"enabled": true,
"frequency": "weekly"
},
"adt": {
"enabled": true
},
"pharmacy": {
"notifications": true,
"schedule": {
"enabled": false,
"frequency": "monthly"
}
},
"laboratory": {
"notifications": true
}
}
},
"size": 250
}
}
Notes
- When assigning specific
patientIdsto a treatment cohort, patients withtreatmentRelationship: falsecannot be added. Use the Treatment Relationship endpoint to update consent before assigning those patients to treatment cohorts. - When using
allPatients: trueon a treatment cohort, patients withtreatmentRelationship: falseare not added. The request still succeeds for all other patients.
⌘I

