tonic-discharge-guard / meldrxtester.py
Tonic's picture
add callback manager , model app
5372c12 unverified
raw
history blame
4.6 kB
import requests
import json
from typing import Optional, Dict, Any
from meldrx import MeldRxAPI
# Testing class
class MeldRxAPITest:
"""A class to test the functionality of the MeldRxAPI class."""
def __init__(self):
# Placeholder variables (replace with real values for live testing)
self.client_id = "04bdc9f9a23d488a868b93d594ee5a4a"
self.client_secret = "test_client_secret"
self.workspace_id = "09ed4f76-b5ac-42bf-92d5-496933203dbe"
self.test_patient_id = "05f7c0c2-ebee-44db-ab71-2113e7a70acb"
self.api = MeldRxAPI(self.client_id, self.client_secret, self.workspace_id)
def test_authenticate(self):
"""Test the authentication method."""
print("\n=== Testing Authentication ===")
result = self.api.authenticate()
print(f"Authentication Result: {result}")
if result:
print(f"Access Token: {self.api.access_token[:10]}... (truncated for brevity)")
else:
print("Authentication failed. Subsequent tests may not work as expected.")
def test_get_patients(self):
"""Test retrieving patients from the FHIR API."""
print("\n=== Testing Get Patients (FHIR) ===")
patients = self.api.get_patients()
if patients is not None:
print("Patients Retrieved Successfully:")
print(json.dumps(patients, indent=2) if patients else "No data returned (expected per docs)")
else:
print("Failed to retrieve patients.")
def test_create_virtual_workspace(self):
"""Test creating a virtual workspace."""
print("\n=== Testing Create Virtual Workspace ===")
success = self.api.create_virtual_workspace(
snapshot="patient-prefetch",
patient_id=self.test_patient_id,
hook="patient-view"
)
print(f"Virtual Workspace Creation Result: {success}")
if success:
print("Virtual workspace created successfully (no response body expected).")
else:
print("Failed to create virtual workspace.")
def test_get_mips_patients(self):
"""Test retrieving patients from the MIPS API."""
print("\n=== Testing Get MIPS Patients ===")
patients = self.api.get_mips_patients()
if patients is not None:
print("MIPS Patients Retrieved Successfully:")
print(json.dumps(patients, indent=2) if patients else "No data returned")
else:
print("Failed to retrieve MIPS patients.")
def test_get_mips_patient_by_id(self):
"""Test retrieving a specific patient by ID from the MIPS API."""
print("\n=== Testing Get MIPS Patient by ID ===")
patient = self.api.get_mips_patient_by_id(self.test_patient_id)
if patient is not None:
print(f"Patient {self.test_patient_id} Retrieved Successfully:")
print(json.dumps(patient, indent=2) if patient else "No data returned")
else:
print(f"Failed to retrieve patient {self.test_patient_id}.")
def test_get_mips_encounters(self):
"""Test retrieving encounters from the MIPS API (with and without patient filter)."""
print("\n=== Testing Get MIPS Encounters (All) ===")
encounters = self.api.get_mips_encounters()
if encounters is not None:
print("All Encounters Retrieved Successfully:")
print(json.dumps(encounters, indent=2) if encounters else "No data returned")
else:
print("Failed to retrieve all encounters.")
print("\n=== Testing Get MIPS Encounters (Filtered by Patient) ===")
encounters_filtered = self.api.get_mips_encounters(self.test_patient_id)
if encounters_filtered is not None:
print(f"Encounters for Patient {self.test_patient_id} Retrieved Successfully:")
print(json.dumps(encounters_filtered, indent=2) if encounters_filtered else "No data returned")
else:
print(f"Failed to retrieve encounters for patient {self.test_patient_id}.")
def run_all_tests(self):
"""Run all test methods in sequence."""
print("Starting MeldRx API Tests...\n")
self.test_authenticate()
self.test_get_patients()
self.test_create_virtual_workspace()
self.test_get_mips_patients()
self.test_get_mips_patient_by_id()
self.test_get_mips_encounters()
print("\nAll tests completed.")
self.api.close()
# Run the tests
if __name__ == "__main__":
tester = MeldRxAPITest()
tester.run_all_tests()