Skip to content

Commit

Permalink
error handle provider_id missing
Browse files Browse the repository at this point in the history
  • Loading branch information
irvins committed Nov 13, 2024
1 parent 027c477 commit 7da4f4e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions HTNapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -1658,21 +1658,34 @@ public function refreshOmronAccessTokens(){

// cron to pull data daily in case the notification ping fails?
public function dailyOmronDataPull($since_today = null, $testMode = false) {
// Get patients with tokens
$patients_with_tokens = $this->getPatientsWithTokens();
$since_today = $since_today ?? date("Y-m-d");
if($testMode){
if ($testMode) {
$since_today = date("Y-m-d", strtotime("-100 days"));
}
$data = [];

foreach ($patients_with_tokens as $patient) {
// Ensure provider_id and omron_client_id are valid
if (empty($patient["provider_id"]) || empty($patient["omron_client_id"])) {
$this->emDebug("Skipping record due to missing provider_id or omron_client_id for record_id: " . ($patient["record_id"] ?? 'unknown'));
continue; // Skip this patient if essential data is missing
}

// Extract required fields
$omron_client_id = $patient["omron_client_id"];
$record_id = $patient["record_id"];
$expiration_date = $patient["omron_token_expire"];

// Attempt to save Omron data and get status
$result = $this->recurseSaveOmronApiData($omron_client_id, $since_today);
$status = is_array($result) && isset($result['status']) ? $result['status'] : false;
try {
$result = $this->recurseSaveOmronApiData($omron_client_id, $since_today);
$status = is_array($result) && isset($result['status']) ? $result['status'] : false;
} catch (Exception $e) {
$this->emDebug("Error processing record_id $record_id: " . $e->getMessage());
$status = false; // Set status to false if an error occurs
}

// Collect data for display if in testMode
if ($testMode) {
Expand All @@ -1685,6 +1698,7 @@ public function dailyOmronDataPull($since_today = null, $testMode = false) {
];
}

// Log success or failure for each patient
if ($status) {
$this->emDebug("BP data for $since_today was successfully downloaded for record_id $record_id");
} else {
Expand All @@ -1698,7 +1712,6 @@ public function dailyOmronDataPull($since_today = null, $testMode = false) {
}
}


// cron to refresh omron access tokens expiring within 48 hours
public function htnAPICron() {
$projects = $this->framework->getProjectsWithModuleEnabled();
Expand Down

0 comments on commit 7da4f4e

Please sign in to comment.