Skip to content

Commit

Permalink
Merge pull request #111 from Lightmatter/develop
Browse files Browse the repository at this point in the history
v0.1.5
  • Loading branch information
samamorgan authored May 16, 2024
2 parents 30da940 + 35c4648 commit 471c87e
Show file tree
Hide file tree
Showing 7 changed files with 100,293 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "welkin"
version = "0.1.4"
version = "0.1.5"
description = "Python Welkin Health API Wrapper."
authors = ["Sam Morgan <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down
100,233 changes: 100,233 additions & 0 deletions test/cassettes/test_cdt_records_export_read.yaml

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions test/test_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import annotations

import pytest


@pytest.mark.vcr
def test_cdt_records_export_read(client, vcr_cassette):
export = client.CDTRecordsExport()

exports = list(export.get(paginate=True, size=1000))

assert len(exports) > 1
assert len(vcr_cassette) == 6
5 changes: 3 additions & 2 deletions welkin/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Client(Session):
CarePlan = models.CarePlan
CarePlanOverview = models.CarePlanOverview
CDT = models.CDT
CDTRecordsExport = models.CDTRecordsExport
CDTs = models.CDTs
Chat = models.Chat
Chats = models.Chats
Expand All @@ -96,11 +97,11 @@ class Client(Session):
Encounters = models.Encounters
Formation = models.Formation
Patient = models.Patient
Patients = models.Patients
PatientProgram = models.PatientProgram
PatientPrograms = models.PatientPrograms
Patients = models.Patients
ProgramPhase = models.ProgramPhase
ProgramPhases = models.ProgramPhases
PatientPrograms = models.PatientPrograms
Schedules = models.Schedules
SearchChats = models.SearchChats
SMS = models.SMS
Expand Down
6 changes: 4 additions & 2 deletions welkin/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from welkin.models.email import Email, Emails
from welkin.models.encounter import Encounter, EncounterDisposition, Encounters
from welkin.models.export import CDTRecordsExport
from welkin.models.formation import Formation
from welkin.models.patient import Patient, Patients
from welkin.models.program import (
Expand All @@ -39,6 +40,7 @@
"CarePlan",
"CarePlanOverview",
"CDT",
"CDTRecordsExport",
"CDTs",
"Chat",
"Chats",
Expand All @@ -53,11 +55,11 @@
"Encounters",
"Formation",
"Patient",
"Patients",
"PatientProgram",
"PatientPrograms",
"Patients",
"ProgramPhase",
"ProgramPhases",
"PatientPrograms",
"Schedules",
"SearchChats",
"SMS",
Expand Down
23 changes: 23 additions & 0 deletions welkin/models/export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from __future__ import annotations

from welkin.models.base import Collection, Resource
from welkin.models.encounter import Encounters
from welkin.pagination import CursorIterator


class CDTRecordExport(Resource):
subresources = (Encounters,)

def __str__(self):
try:
return f"{self.firstName} {self.lastName}"
except AttributeError:
return self.username


class CDTRecordsExport(Collection):
resource = CDTRecordExport
iterator = CursorIterator

def get(self, *args, **kwargs):
return super().get(f"{self._client.instance}/export/CDT_RECORD", *args, **kwargs)
16 changes: 16 additions & 0 deletions welkin/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,19 @@ def _pre_request(self):
def _post_request(self, meta):
self.page_token = meta["nextPageToken"]
self.last = not meta.get("nextPageToken")


class CursorIterator(PageIterator):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.meta_key = "cursor"
self.meta_dict = {
"start": None,
"end": None,
"pageSize": self.size,
}
self.kwargs.setdefault("params", {}).update(pageSize=self.size)

def _post_request(self, meta):
self.kwargs.setdefault("params", {}).update(start=meta.get("end"))
self.last = not meta.get("hasNext")

0 comments on commit 471c87e

Please sign in to comment.