8000 feat(api-sdk): added cohort methods to api-sdk by RamilGaripov · Pull Request #4089 · metriport/metriport · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(api-sdk): added cohort methods to api-sdk #4089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

RamilGaripov
Copy link
Contributor
@RamilGaripov RamilGaripov commented Jun 25, 2025

Part of ENG-526

Issues:

Description

  • Added cohort methods to the metriport.ts SDK client

Testing

  • Local
    • Use local script to test each method
      • createCohort
      • updateCohort
      • listCohorts
      • getCohort
      • deleteCohort
      • assignPatientsToCohort
      • removePatientsFromCohort
  • Staging
    • Use local script pointing to staging test each method
      • createCohort
      • updateCohort
      • listCohorts
      • getCohort
      • deleteCohort
      • assignPatientsToCohort
      • removePatientsFromCohort

Release Plan

  • Release NPM packages
  • Merge this

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive cohort management capabilities, including creating, updating, deleting, and listing cohorts.
    • Added functionality to assign or remove patients in bulk from cohorts.
    • Users can now view detailed cohort information, including patient counts and IDs.
  • Documentation

    • Added new data validation schemas and type definitions for all cohort-related operations to improve reliability and clarity.

Part of ENG-420

Signed-off-by: Ramil Garipov <ramil@metriport.com>
Copy link
linear bot commented Jun 25, 2025

Copy link
coderabbitai bot commented Jun 25, 2025

Walkthrough

This change introduces full cohort management capabilities to the MetriportMedicalApi client, including methods for creating, updating, deleting, listing, and retrieving cohorts, as well as assigning and removing patients in bulk. It also adds a new module defining cohort-related types and validation schemas using the zod library.

Changes

File(s) Change Summary
packages/api-sdk/src/medical/client/metriport.ts Added cohort management methods (create, update, delete, list, get, assign/remove patients) to the API client.
packages/api-sdk/src/medical/models/cohort.ts Introduced cohort schemas and TypeScript types for validation and data transfer, using the zod library.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant MetriportMedicalA
8000
pi
    participant BackendAPI

    Client->>MetriportMedicalApi: createCohort(data)
    MetriportMedicalApi->>BackendAPI: POST /cohort
    BackendAPI-->>MetriportMedicalApi: CohortDTO
    MetriportMedicalApi-->>Client: CohortDTO

    Client->>MetriportMedicalApi: updateCohort(cohort)
    MetriportMedicalApi->>BackendAPI: PUT /cohort/{id} (with ETag)
    BackendAPI-->>MetriportMedicalApi: CohortDTO
    MetriportMedicalApi-->>Client: CohortDTO

    Client->>MetriportMedicalApi: assignPatientsToCohort(cohortId, data)
    MetriportMedicalApi->>BackendAPI: POST /cohort/{id}/patient
    BackendAPI-->>MetriportMedicalApi: CohortWithPatientIdsAndCountDTO
    MetriportMedicalApi-->>Client: CohortWithPatientIdsAndCountDTO

    Client->>MetriportMedicalApi: removePatientsFromCohort(cohortId, data)
    MetriportMedicalApi->>BackendAPI: DELETE /cohort/{id}/patient
    BackendAPI-->>MetriportMedicalApi: PatientUnassignmentResponse
    MetriportMedicalApi-->>Client: PatientUnassignmentResponse
Loading

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error code ERR_SSL_WRONG_VERSION_NUMBER
npm error errno ERR_SSL_WRONG_VERSION_NUMBER
npm error request to https://10.0.0.28:4873/punycode/-/punycode-2.3.1.tgz failed, reason: C09CCB88657F0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:354:
npm error
npm error A complete log of this run can be found in: /.npm/_logs/2025-06-25T14_49_33_504Z-debug-0.log

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@RamilGaripov RamilGaripov changed the title feat(api-sdk): added cohort methods to sdk feat(api-sdk): added cohort methods to api-sdk Jun 25, 2025
@RamilGaripov RamilGaripov marked this pull request as ready for review June 25, 2025 14:48
Copy link
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/api-sdk/src/medical/client/metriport.ts (2)

680-680: Remove debugging console.log statement.

This console.log appears to be leftover from development and should be removed according to the coding guidelines which state to avoid using console.log in packages other than utils, infra and shared.

-    console.log("RESP DATA IS", resp.data);

715-715: Remove debugging console.log statement.

This console.log appears to be leftover from development and should be removed according to the coding guidelines.

-    console.log("RESP DATA IS", resp.data);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6df7d19 and f055315.

📒 Files selected for processing (2)
  • packages/api-sdk/src/medical/client/metriport.ts (3 hunks)
  • packages/api-sdk/src/medical/models/cohort.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`**/*`: Use eslint to enforce code style Use prettier to format code Max column ...

**/*: Use eslint to enforce code style
Use prettier to format code
Max column length is 100 chars
Multi-line comments use /** */
Top-level comments go after the import (save pre-import to basic file header, like license)
Move literals to constants declared after imports when possible
File names: kebab-case

📄 Source: CodeRabbit Inference Engine (.cursorrules)

List of files the instruction was applied to:

  • packages/api-sdk/src/medical/models/cohort.ts
  • packages/api-sdk/src/medical/client/metriport.ts
`**/*.ts`: - Use the Onion Pattern to organize a package's code in layers - Try ...

**/*.ts: - Use the Onion Pattern to organize a package's code in layers

  • Try to use immutable code and avoid sharing state across different functions, objects, and systems
  • Try to build code that's idempotent whenever possible
  • Prefer functional programming style functions: small, deterministic, 1 input, 1 output
  • Minimize coupling / dependencies
  • Avoid modifying objects received as parameter
  • Only add comments to code to explain why something was done, not how it works
  • Naming
    • classes, enums: PascalCase
    • constants, variables, functions: camelCase
    • file names: kebab-case
    • table and column names: snake_case
    • Use meaningful names, so whoever is reading the code understands what it means
    • Don’t use negative names, like notEnabled, prefer isDisabled
    • For numeric values, if the type doesn’t convey the unit, add the unit to the name
  • Typescript
    • Use types
    • Prefer const instead of let
    • Avoid any and casting from any to other types
    • Type predicates: only applicable to narrow down the type, not to force a complete type conversion
    • Prefer deconstructing parameters for functions instead of multiple parameters that might be of
      the same type
    • Don’t use null inside the app, only on code interacting with external interfaces/services,
      like DB and HTTP; convert to undefined before sending inwards into the code
    • Use async/await instead of .then()
    • Use the strict equality operator ===, don’t use abstract equality operator ==
    • When calling a Promise-returning function asynchronously (i.e., not awaiting), use .catch() to
      handle errors (see processAsyncError and emptyFunction depending on the case)
    • Date and Time
      • Always use buildDayjs() to create dayjs instances
      • Prefer dayjs.duration(...) to create duration consts and keep them as duration
  • Prefer Nullish Coalesce (??) than the OR operator (||) to provide a default value
  • Avoid creating arrow functions
  • Use truthy syntax instead of in - i.e., if (data.link) not if ('link' in data)
  • Error handling
    • Pass the original error as the new one’s cause so the stack trace is persisted
    • Error messages should have a static message - add dynamic data to MetriportError's additionalInfo prop
    • Avoid sending multiple events to Sentry for a single error
  • Global constants and variables
    • Move literals to constants declared after imports when possible (avoid magic numbers)
    • Avoid shared, global objects
  • Avoid using console.log and console.error in packages other than utils, infra and shared,
    and try to use out().log instead
  • Avoid multi-line logs
    • don't send objects as a second parameter to console.log() or out().log()
    • don't create multi-line strings when using JSON.stringify()
  • Use eslint to enforce code style
  • Use prettier to format code
  • max column length is 100 chars
  • multi-line comments use /** */
  • scripts: top-level comments go after the import

⚙️ Source: CodeRabbit Configuration File

List of files the instruction was applied to:

  • packages/api-sdk/src/medical/models/cohort.ts
  • packages/api-sdk/src/medical/client/metriport.ts
🧠 Learnings (1)
packages/api-sdk/src/medical/models/cohort.ts (1)
Learnt from: RamilGaripov
PR: metriport/metriport#3976
File: packages/api/src/routes/medical/patient.ts:541-543
Timestamp: 2025-06-18T21:05:22.256Z
Learning: In packages/api/src/routes/medical/patient.ts, inline schema definitions like cohortIdSchema are acceptable and don't need to be moved to separate schema files when the user prefers to keep them inline.
🔇 Additional comments (10)
packages/api-sdk/src/medical/models/cohort.ts (1)

1-61: LGTM! Well-structured schema definitions with good type safety.

The cohort model file follows excellent patterns with comprehensive Zod schema definitions and proper TypeScript type exports. The schema hierarchy progresses logically from basic cohort data to composite types including patient counts and IDs. The manual PatientAssignmentRequest type provides appropriate flexibility for either specific patient IDs or bulk operations.

packages/api-sdk/src/medical/client/metriport.ts (9)

20-32: LGTM! Proper imports for cohort functionality.

The new imports are well-organized and include all necessary types and schemas for the cohort management methods.


70-70: LGTM! Consistent URL constant pattern.

The COHORT_URL constant follows the established naming convention and pattern used by other endpoint constants in the file.


670-682: LGTM! Well-implemented createCohort method.

The method follows established patterns with proper error handling, response validation using Zod schema, and comprehensive JSDoc documentation. The implementation is consistent with other create methods in the class.


684-696: LGTM! Proper updateCohort implementation with ETag support.

The method correctly implements the update pattern with ETag header support for optimistic locking, following the same approach used by other update methods in the codebase.


698-705: LGTM! Simple and correct deleteCohort implementation.

The delete method follows the established pattern for deletion operations with appropriate documentation about the prerequisite of unassigning patients first.


707-717: LGTM! Well-implemented listCohorts method.

The method properly handles the list operation with appropriate fallback for empty responses and proper schema validation. The implementation follows established patterns for list methods.


719-729: LGTM! Comprehensive getCohort implementation.

The method correctly retrieves detailed cohort information including patient IDs and count, with proper error handling and schema validation.


731-745: LGTM! Well-designed patient assignment method.

The method properly handles bulk patient assignment with flexible input options (specific patient IDs or all patients) and returns comprehensive cohort information after the operation.


747-763: LGTM! Proper patient removal implementation.

The method correctly uses DELETE with request body via the data property for bulk patient removal operations, following HTTP best practices and providing appropriate response information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0