Skip to main content
POST
/
medical
/
v1
/
patient
/
{id}
/
cohort
Add Patient to Cohorts
curl --request POST \
  --url https://api.sandbox.metriport.com/medical/v1/patient/{id}/cohort \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "cohortIds": [
    "<string>"
  ]
}
'
import requests

url = "https://api.sandbox.metriport.com/medical/v1/patient/{id}/cohort"

payload = { "cohortIds": ["<string>"] }
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({cohortIds: ['<string>']})
};

fetch('https://api.sandbox.metriport.com/medical/v1/patient/{id}/cohort', 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/patient/{id}/cohort",
  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([
    'cohortIds' => [
        '<string>'
    ]
  ]),
  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/patient/{id}/cohort"

	payload := strings.NewReader("{\n  \"cohortIds\": [\n    \"<string>\"\n  ]\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/patient/{id}/cohort")
  .header("x-api-key", "<api-key>")
  .header("Content-Type", "application/json")
  .body("{\n  \"cohortIds\": [\n    \"<string>\"\n  ]\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://api.sandbox.metriport.com/medical/v1/patient/{id}/cohort")

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  \"cohortIds\": [\n    \"<string>\"\n  ]\n}"

response = http.request(request)
puts response.read_body
import { MetriportMedicalApi } from "@metriport/api-sdk";

const metriport = new MetriportMedicalApi("YOUR_API_KEY");

const patientId = "00000000-0000-0000-0000-000000000000";
const result = await metriport.addPatientToCohorts(patientId, {
  cohortIds: [
    "00000000-0000-0000-0000-000000000000", 
    "11111111-1111-1111-1111-111111111111"
  ]
});
For more information, see the guide about Cohorts

Path Params

id
string
required
The ID of the patient to add to cohorts.

Body

cohortIds
string[]
required
Array of cohort IDs to add the patient to.

Response

cohorts
Cohort[]
required
Array of cohorts the patient is currently associated with.
import { MetriportMedicalApi } from "@metriport/api-sdk";

const metriport = new MetriportMedicalApi("YOUR_API_KEY");

const patientId = "00000000-0000-0000-0000-000000000000";
const result = await metriport.addPatientToCohorts(patientId, {
  cohortIds: [
    "00000000-0000-0000-0000-000000000000", 
    "11111111-1111-1111-1111-111111111111"
  ]
});
{
  "cohorts": [
    {
      "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": 150
    },
    {
      "id": "11111111-1111-1111-1111-111111111111",
      "eTag": "1",
      "name": "Cardiac Care Cohort",
      "description": "Patients receiving cardiac care and monitoring",
      "color": "blue",
      "purposeOfUse": "treatment",
      "settings": {
        "monitoring": {
          "hie": {
            "enabled": true,
            "frequency": "weekly"
          },
          "adt": {
            "enabled": true
          },
          "pharmacy": {
            "notifications": true,
            "schedule": {
              "enabled": false,
              "frequency": "monthly"
            }
          },
          "laboratory": {
            "notifications": false
          }
        }
      },
      "size": 75
    }
  ]
}

Notes

  • If the patient is already in some of the specified cohorts, those will be skipped (no error thrown)
  • Patients with treatmentRelationship: false cannot be added to treatment cohorts. Use the Treatment Relationship endpoint to update consent before assigning the patient to treatment cohorts.