<?php
/**
 * Created by PhpStorm.
 * User: sunusi
 * Date: 2019-02-20
 * Time: 09:42
 */

session_start();

require_once getcwd() . "/../functions/db.class.php";
require_once getcwd() . "/../functions/form.data.php";
require_once getcwd() . "/../functions/robot.php";
//patient details
header('Content-Type: application/json');
function reArrangeArray1D($array)
{
    // variable declaration
    $var = "";
    $val = "";
    $arr = array();
    // loop
    foreach ($array as $var => $val) {
        $arr[$var] = $val;
    }
    return $arr;
}

$patients = $query->getAll("select * from udut_patients where patientSyncStatus = 0");

foreach ($patients as $patient) {
    //getting payment details of particular patient
    $payments = $query->getAll("select * from udut_payments where patientId = '" . $patient['patientId'] . "' ");

//    print_r($payments);
//    print("<br>");
    $arr_pat = $patient;

    $arr_pay = array();
    foreach ($payments as $payment) {
        //getting visit details
        $arr_pay[] = reArrangeArray1D($payment);
    }
    $patient["payments"] = $arr_pay;
//    unset($patient["payments"]);
//    print("<pre>");
    $obj = json_encode($patient);

}


echo $obj;
