Exemple #1
1
 function calculateGFRResult()
 {
     $tmpArr = array();
     $tmpArr[] = date('Y-m-d H:i:s');
     //observation time
     $tmpArr[] = 'GFR (CALC)';
     //desc
     $gender = NSDR::populate($this->_patientId . "::com.clearhealth.person.displayGender");
     $crea = NSDR::populate($this->_patientId . "::com.clearhealth.labResults[populate(@description=CREA)]");
     $genderFactor = null;
     $creaValue = null;
     $personAge = null;
     $raceFactor = 1;
     switch ($gender[key($gender)]) {
         case 'M':
             $genderFactor = 1;
             break;
         case 'F':
             $genderFactor = 0.742;
             break;
     }
     if ((int) strtotime($crea['observation_time']) >= strtotime('now - 60 days') && strtolower($crea[key($crea)]['units']) == 'mg/dl') {
         $creaValue = $crea[key($crea)]['value'];
     }
     $person = new Person();
     $person->personId = $this->_patientId;
     $person->populate();
     if ($person->age > 0) {
         $personAge = $person->age;
     }
     $personStat = new PatientStatistics();
     $personStat->personId = $this->_patientId;
     $personStat->populate();
     if ($personStat->race == "AFAM") {
         $raceFactor = 1.21;
     }
     $gfrValue = "INC";
     if ($personAge > 0 && $creaValue > 0) {
         $gfrValue = "" . (int) round(pow($creaValue, -1.154) * pow($personAge, -0.203) * $genderFactor * $raceFactor * 186);
     }
     trigger_error("gfr:: " . $gfrValue, E_USER_NOTICE);
     $tmpArr[] = $gfrValue;
     // lab value
     $tmpArr[] = 'mL/min/1.73 m2';
     //units
     $tmpArr[] = '';
     //ref range
     $tmpArr[] = '';
     //abnormal
     $tmpArr[] = 'F';
     //status
     $tmpArr[] = date('Y-m-d H:i:s') . '::' . '0';
     // observationTime::(boolean)normal; 0 = abnormal, 1 = normal
     $tmpArr[] = '0';
     //sign
     //$this->_calcLabResults[uniqid()] = $tmpArr;
     $this->_calcLabResults[1] = $tmpArr;
     // temporarily set index to one(1) to be able to include in selected lab results
     return $tmpArr;
 }
 function run()
 {
     $fp = fopen('php://output', 'w');
     header('Content-type: application/force-download');
     header("Content-Type: application/download");
     header('Content-type: text/csv');
     header('Content-Disposition: attachment; filename="jethro_' . date('Y-m-d_h:i') . '.csv"');
     $GLOBALS['system']->includeDBClass('family');
     $GLOBALS['system']->includeDBClass('person');
     switch (array_get($_REQUEST, 'merge_type')) {
         case 'family':
             $merge_data = Family::getFamilyDataByMemberIDs($_POST['personid']);
             $dummy = new Family();
             $dummy_family = NULL;
             break;
         case 'person':
         default:
             $merge_data = $GLOBALS['system']->getDBObjectData('person', array('id' => (array) $_POST['personid']));
             $dummy = new Person();
             $dummy_family = new Family();
             break;
     }
     $headerrow = array('ID');
     foreach (array_keys(reset($merge_data)) as $header) {
         if ($header == 'familyid') {
             continue;
         }
         $headerrow[] = strtoupper($dummy->getFieldLabel($header));
     }
     fputcsv($fp, $headerrow);
     foreach ($merge_data as $id => $row) {
         @$dummy->populate($id, $row);
         $outputrow = array($id);
         foreach ($row as $k => $v) {
             if ($k == 'history') {
                 continue;
             }
             if ($k == 'familyid') {
                 continue;
             }
             if ($dummy->hasField($k)) {
                 $outputrow[] = $dummy->getFormattedValue($k, $v);
                 // pass value to work around read-only fields
             } else {
                 if ($dummy_family && $dummy_family->hasField($k)) {
                     $outputrow[] = $dummy_family->getFormattedValue($k, $v);
                 } else {
                     $outputrow[] = $v;
                 }
             }
         }
         fputcsv($fp, $outputrow);
     }
     fclose($fp);
 }
 public function myAlertsAction()
 {
     $personId = Zend_Auth::getInstance()->getIdentity()->personId;
     $team = new TeamMember();
     $teamId = $team->getTeamByPersonId($personId);
     $rows = array();
     if (true) {
         $alertMsg = new GeneralAlert();
         $alertMsgIterator = $alertMsg->getIteratorByTeam($teamId);
         foreach ($alertMsgIterator as $alert) {
             $tmp = array();
             $tmp['id'] = $alert->generalAlertId;
             $tmp['data'][] = '<img src="' . $this->view->baseUrl . '/img/medium.png' . '" alt="' . $alert->urgency . '" /> ' . $alert->urgency;
             // below are temporary data
             $objectClass = $alert->objectClass;
             if (!class_exists($objectClass)) {
                 continue;
             }
             $obj = new $objectClass();
             foreach ($obj->_primaryKeys as $key) {
                 $obj->{$key} = $alert->objectId;
             }
             $obj->populate();
             $patient = new Patient();
             $patient->personId = $obj->personId;
             $patient->populate();
             $tmp['data'][] = $patient->person->getDisplayName();
             // patient
             $tmp['data'][] = '';
             // location
             $tmp['data'][] = date('m/d/Y H:i', strtotime($alert->dateTime));
             $tmp['data'][] = $alert->message;
             $forwardedBy = '';
             if ($alert->forwardedBy > 0) {
                 $person = new Person();
                 $person->personId = (int) $alert->forwardedBy;
                 $person->populate();
                 $forwardedBy = $person->displayName;
             }
             $tmp['data'][] = $forwardedBy;
             // forwarded
             $tmp['data'][] = $alert->comment;
             // comment
             $controllerName = call_user_func($objectClass . "::" . "getControllerName");
             $jumpLink = call_user_func_array($controllerName . "::" . "buildJSJumpLink", array($alert->objectId, $alert->userId, $objectClass));
             $js = "function jumpLink{$objectClass}(objectId,patientId) {\n{$jumpLink}\n}";
             $tmp['data'][] = $js;
             $tmp['data'][] = $objectClass . ':' . $alert->objectId . ':' . $patient->personId;
             $rows[] = $tmp;
         }
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }
 function run()
 {
     // Ref: http://en.wikipedia.org/wiki/VCard
     header('Content-type: text/vcf');
     header('Content-Disposition: attachment; filename="contacts_' . date('Y-m-d_h:i') . '.vcf"');
     $GLOBALS['system']->includeDBClass('person');
     $GLOBALS['system']->includeDBClass('family');
     $merge_data = $GLOBALS['system']->getDBObjectData('person', array('id' => $_REQUEST['personid']));
     $dummy = new Person();
     $family = new Family();
     foreach ($merge_data as $id => $row) {
         $dummy->populate($id, $row);
         $family->setvalue('home_tel', $row['home_tel']);
         echo "BEGIN:VCARD\n";
         echo "VERSION:3.0\n";
         echo "N:" . $row['last_name'] . ";" . $row['first_name'] . ";;;\n";
         echo "FN:" . $row['first_name'] . " " . $row['last_name'] . "\n";
         echo "EMAIL;type=INTERNET;type=HOME:" . $row['email'] . "\n";
         echo "ADR;type=HOME:;;" . $row['address_street'] . ";" . $row['address_suburb'] . ";" . $row['address_state'] . ";" . $row['address_postcode'] . ";\n";
         echo "TEL;type=HOME:" . $family->getFormattedValue('home_tel') . "\n";
         echo "TEL;type=WORK:" . $dummy->getFormattedValue('work_tel') . "\n";
         echo "TEL;type=MOBILE:" . $dummy->getFormattedValue('mobile_tel') . "\n";
         echo "TEL;type=CELL:" . $dummy->getFormattedValue('mobile_tel') . "\n";
         if ($g = $dummy->getValue('Gender')) {
             echo "GENDER:" . strtoupper($g[0]) . "\n";
         }
         echo "CATEGORIES:" . $row['congregation'] . "\n";
         echo "ORG:" . $dummy->getFormattedValue('congregationid') . "\n";
         echo "NOTES:" . $dummy->getFormattedValue('congregationid') . "\n";
         echo "ROLE:" . $dummy->getFormattedValue('status') . "\n";
         echo "TITLE:" . $dummy->getFormattedValue('status') . "\n";
         echo "SOURCE:" . build_url(array('personid' => array($id))) . "\n";
         // where to get vcard from
         echo "URL:" . build_url(array('call' => NULL, 'view' => 'persons', 'personid' => $id)) . "\n";
         // definitive location for full details
         echo "UID:" . build_url(array('call' => NULL, 'view' => 'persons', 'personid' => $id)) . "\n";
         echo "END:VCARD\n\n";
     }
 }
    function run()
    {
        $results = array();
        if (!empty($_REQUEST['search'])) {
            $name = $_REQUEST['search'];
            $GLOBALS['system']->includeDBClass('person');
            $results = Person::getPersonsByName($name, array_get($_REQUEST, 'include_archived', false));
            header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
            // Date in the past
            header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
            // always modified
            header("Cache-Control: no-cache, must-revalidate");
            // HTTP/1.1
            header("Pragma: no-cache");
            // HTTP/1.0
            header("Content-Type: application/json");
            echo "{\"results\": [";
            $arr = array();
            $GLOBALS['system']->includeDBClass('person');
            $dummy = new Person();
            $count = 0;
            foreach ($results as $i => $details) {
                if ($count++ > 12) {
                    break;
                }
                $dummy->populate($i, $details);
                $arr[] = '
					{
						id: ' . $i . ',
						value: "' . addcslashes(ents($details['first_name'] . ' ' . $details['last_name']), '"') . '",
						info: "' . addcslashes(ents($dummy->getFormattedValue('status') . ', ' . $dummy->getFormattedValue('congregationid')), '"') . '"
					}
				';
            }
            echo implode(", ", $arr);
            echo "]}";
        }
    }
 public function indexAction()
 {
     $personId = (int) $this->_getParam('personId');
     $person = new Person();
     $person->personId = $personId;
     $person->populate();
     $this->view->person = $person;
     $this->view->chartList = GrowthChartBase::listCharts();
     switch (strtolower($person->displayGender)) {
         case 'female':
             $gender = GrowthChartBase::GENDER_FEMALE;
             break;
         case 'male':
         default:
             $gender = GrowthChartBase::GENDER_MALE;
             break;
     }
     $listGrowthCharts = array();
     foreach ($this->view->chartList as $key => $value) {
         $ormClass = ucfirst($key);
         $orm = new $ormClass();
         $ormIterator = $orm->getIteratorByGender($gender);
         $xMax = 0;
         $yMax = 0;
         $xMin = 0;
         $yMin = 0;
         $percentiles = array();
         $mappings = $orm->_dataTableMappings;
         list($base, $fields) = each($mappings);
         $columns = array();
         foreach ($ormIterator as $row) {
             if ($row->{$base} > $xMax) {
                 $xMax = $row->{$base};
             }
             if ($xMin == 0 || $row->{$base} < $xMin) {
                 $xMin = $row->{$base};
             }
             foreach ($fields as $field) {
                 if ($row->{$field} > $yMax) {
                     $yMax = $row->{$field};
                 }
                 if ($yMin == 0 || $row->{$field} < $yMin) {
                     $yMin = $row->{$field};
                 }
                 $columns[$field]['name'] = substr($field, 1);
                 $columns[$field]['percentiles'][$row->{$base}] = $row->{$field};
             }
         }
         $listGrowthCharts[$key]['data'] = $orm->listVitals($person);
         // this MUST be called right after $orm->listVitals($person) is called
         $vitalSigns = array();
         foreach (GrowthChartBase::$_vitalSigns as $vitalSign) {
             $dateVitalsTime = strtotime($vitalSign['dateTime']);
             if (!isset($vitalSigns[$vitalSign['vitalSignGroupId']])) {
                 list($bYear, $bMonth, $bDay) = explode('-', date('Y-m-d', strtotime($person->dateOfBirth)));
                 list($vYear, $vMonth, $vDay) = explode('-', date('Y-m-d', $dateVitalsTime));
                 $age = $vMonth >= $bMonth && $vDay >= $bDay || $vMonth > $bMonth ? $vYear - $bYear : $vYear - $bYear - 1;
                 $vitalSigns[$vitalSign['vitalSignGroupId']]['label'] = date('m/d/Y h:iA', $dateVitalsTime) . ': Age=' . $age * 12 . ' months';
                 $vitalSigns[$vitalSign['vitalSignGroupId']]['data'] = array();
             }
             $value = $vitalSign['value'];
             $ussValue = $value;
             $metricValue = '';
             if (strlen($vitalSign['units']) > 0) {
                 if (strlen($ussValue) > 0) {
                     $ussValue .= ' ' . $vitalSign['units'];
                 }
                 $ret = VitalSignValue::convertValues($vitalSign['vital'], $value, $vitalSign['units']);
                 if ($ret !== false) {
                     $ussValue = $ret['uss'];
                     $metricValue = $ret['metric'];
                 }
             }
             $tmp['data'][] = $ussValue;
             $tmp['data'][] = $metricValue;
             $vitalSigns[$vitalSign['vitalSignGroupId']]['data'][] = $vitalSign['vital'] . '=' . $metricValue . ' (' . $ussValue . ')';
         }
         $vitalTxt = array();
         foreach ($vitalSigns as $groupId => $value) {
             $arr = array();
             foreach ($value['data'] as $val) {
                 $arr[] = $val;
             }
             $vitalTxt[] = $value['label'] . ' ' . implode(' ', $arr);
         }
         $listGrowthCharts[$key]['vitalSigns'] = implode("\n", $vitalTxt);
         $listGrowthCharts[$key]['columns'] = $columns;
         $listGrowthCharts[$key]['name'] = GrowthChartBase::prettyName($base);
         $listGrowthCharts[$key]['unit'] = constant("{$ormClass}::BASE_UNIT");
         $listGrowthCharts[$key]['percentileName'] = constant("{$ormClass}::PERCENTILE_NAME");
         $listGrowthCharts[$key]['percentileUnit'] = constant("{$ormClass}::PERCENTILE_UNIT");
         $listGrowthCharts[$key]['xMax'] = ceil($xMax);
         $listGrowthCharts[$key]['yMax'] = ceil($yMax);
         $listGrowthCharts[$key]['xMin'] = floor($xMin);
         $listGrowthCharts[$key]['yMin'] = floor($yMin);
     }
     //file_put_contents('/tmp/growth.charts',print_r($listGrowthCharts,true));
     $this->view->listGrowthCharts = $listGrowthCharts;
     $this->render();
 }
 public function getScheduleDataAction()
 {
     $dateStart = date('Y-m-d', strtotime($this->_getParam('dateStart')));
     $dateEnd = date('Y-m-d', strtotime($this->_getParam('dateEnd')));
     $providerId = (int) $this->_getParam('providerId');
     $roomId = (int) $this->_getParam('roomId');
     $data = array();
     $start = $dateStart . ' 00:00:00';
     $end = $dateEnd . ' 23:59:59';
     $numberOfEvents = ScheduleEvent::getNumberOfEvents($providerId, $roomId, $start, $end);
     $data['numberOfEvents'] = $numberOfEvents;
     $title = '';
     if ($providerId > 0) {
         $person = new Person();
         $person->personId = $providerId;
         $person->populate();
         $title .= $person->lastName . ', ' . $person->firstName . ', ' . $person->suffix;
     } else {
         if ($roomId > 0) {
             $room = new Room();
             $room->roomId = $roomId;
             $room->populate();
             $title .= $room->building->practice->name . '->' . $room->building->name . '->' . $room->name;
         }
     }
     $data['title'] = $title;
     $data['dateStart'] = date('m/d/Y', strtotime($dateStart));
     $data['dateEnd'] = date('m/d/Y', strtotime($dateEnd));
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
 function templateAction()
 {
     $clinicalNoteId = $this->_getParam('clinicalNoteId', 0);
     $revisionId = (int) $this->_getParam('revisionId');
     $cn = new ClinicalNote();
     $cn->clinicalNoteId = (int) $clinicalNoteId;
     $cn->populate();
     if ($revisionId > 0) {
         $cn->revisionId = $revisionId;
     }
     $this->_cn = $cn;
     $templateId = $cn->clinicalNoteTemplateId;
     assert("{$templateId} > 0");
     $cnTemplate = $cn->clinicalNoteDefinition->clinicalNoteTemplate;
     $this->_form = new WebVista_Form(array('name' => 'cn-template-form'));
     $this->_form->setWindow('dummyWindowId');
     $this->_form->setAction(Zend_Registry::get('baseUrl') . "clinical-notes-form.raw/process");
     $cnXML = simplexml_load_string($cnTemplate->template);
     // pre-register print element to view so that other elements can override particularly the onclick event
     $this->_buildForm($cnXML);
     $this->_form->addElement($this->_form->createElement('hidden', 'clinicalNoteId', array('value' => (int) $cn->clinicalNoteId)));
     $formData = array();
     $this->_form->removeElement('ok');
     $element = $this->_form->createElement('hidden', 'clinicalNoteOKId', array('value' => 'OK'));
     $this->_form->addElement($element);
     if ($revisionId > 0) {
         //$this->_form->removeElement('ok');
         $this->_form->removeElement('clinicalNoteOKId');
     } else {
         $revisionId = GenericData::getUnsignedRevisionId(get_class($cn), $cn->clinicalNoteId);
         //$revisionId = $cn->clinicalNoteId;
     }
     $this->_form->addElement($this->_form->createElement('hidden', 'revisionId', array('value' => (int) $revisionId)));
     $db = Zend_Registry::get('dbAdapter');
     $cndSelect = $db->select()->from('genericData')->where("objectClass = 'ClinicalNote'")->where('objectId = ?', (int) $cn->clinicalNoteId);
     if ($revisionId > 0) {
         $cndSelect->where('revisionId = ?', $revisionId);
     }
     trigger_error($cndSelect->__toString(), E_USER_NOTICE);
     foreach ($db->query($cndSelect)->fetchAll() as $row) {
         $formData[$row['name']] = $row['value'];
     }
     $eSignatureId = ESignature::retrieveSignatureId(get_class($cn), $revisionId);
     if ($eSignatureId > 0) {
         // On signed notes generic data is shown
         //$this->_form->removeElement('ok');
         $this->_form->removeElement('clinicalNoteOKId');
         $esig = new ESignature();
         $esig->eSignatureId = $eSignatureId;
         $esig->populate();
         $signPerson = new Person();
         $signPerson->personId = $esig->signingUserId;
         $signPerson->populate();
         $person = new Person();
         $person->personId = $esig->signingUserId;
         $person->populate();
         $this->view->signatureInfo = "Signed on: " . $esig->signedDateTime . " by: " . $person->firstName . ' ' . $person->lastName . ' ' . $person->suffix;
         $element = $this->_form->createElement('hidden', 'clinicalNoteSignatureId', array('value' => $this->view->signatureInfo));
         $this->_form->addElement($element);
     } else {
         // on unsigned notes NSDR is shown but a warning also needs to appear that says data has changed since last save if generic data != NSDR data
         if ((string) $cnXML->attributes()->useNSDR && (string) $cnXML->attributes()->useNSDR == 'true') {
             $nsdrData = ClinicalNote::getNSDRData($cnXML, $cn, $revisionId);
             if ($formData != $nsdrData) {
                 $msg = __('Data has been changed since last save');
                 $this->_form->addElement($this->_form->createElement('hidden', 'dataChangedId', array('value' => $msg)));
             }
             $formData = $nsdrData;
         }
     }
     $this->_form->populate($formData);
     $this->view->form = $this->_form;
     $templateRevisions = array();
     $gdIterator = GenericData::getAllRevisions(get_class($cn), $cn->clinicalNoteId);
     foreach ($gdIterator as $gd) {
         $templateRevisions[$gd->revisionId] = $gd->dateTime;
     }
     $this->view->templateRevisions = $templateRevisions;
 }
Exemple #9
0
 public function testPopulate()
 {
     $person = new Person();
     $person->personId = 1234;
     $person->populate();
     $firstName = $person->firstName;
     $person->firstName = 'John';
     $lastName = $person->lastName;
     $person->lastName = 'Doe';
     $middleName = $person->middleName;
     $person->middleName = 'C';
     $person->persist();
     // test case 1
     $result = NSDR2::populate('1234::com.clearhealth.person');
     $this->assertEquals($result['first_name'], $person->firstName, 'TEST CASE 1 failed.');
     $this->assertEquals($result['last_name'], $person->lastName, 'TEST CASE 1 failed.');
     $this->assertEquals($result['middle_name'], $person->middleName, 'TEST CASE 1 failed.');
     // test case 2
     $result = NSDR2::populate('1234::com.clearhealth.person.middleName');
     $this->assertEquals($result, 'C', 'TEST CASE 2 failed.');
     // test case 5
     $result = NSDR2::populate('1234::com.clearhealth.person[aggregateDisplay()]');
     $this->assertContains('Doe John  C', $result, 'TEST CASE 5 failed.');
     // revert the person
     $person->firstName = $firstName;
     $person->lastName = $lastName;
     $person->middleName = $middleName;
     $person->persist();
 }
    public function printForm($prefix = 0)
    {
        if (empty($this->_persons)) {
            return 0;
        }
        $GLOBALS['system']->includeDBClass('person');
        $dummy = new Person();
        ?>
		<table class="table table-condensed table-auto-width valign-middle">
		<?php 
        $is_first = TRUE;
        foreach ($this->_persons as $personid => $details) {
            $dummy->populate($personid, $details);
            ?>
			<tr>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td><?php 
                echo $personid;
                ?>
</td>
				<?php 
            }
            if ($this->show_photos) {
                ?>
				<td>
					<a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php 
                echo $personid;
                ?>
">
						<img style="width: 50px; max-width: 50px" src="?call=photo&personid=<?php 
                echo (int) $personid;
                ?>
" />
					</a>
				</td>
				<?php 
            }
            ?>
				<td>
					<?php 
            echo ents($details['first_name'] . ' ' . $details['last_name']);
            ?>
				</td>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td>
					<?php 
                if ($this->groupid) {
                    echo ents($details['membership_status']);
                } else {
                    $dummy->printFieldValue('status');
                }
                ?>
				</td>
				<?php 
            }
            ?>
				<td class="narrow">
					<?php 
            $this->printWidget($prefix, $personid);
            ?>
				</td>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td class="action-cell narrow">
					<a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-user"></i>View</a> &nbsp;
					<a class="med-popup" tabindex="-1" href="?view=_edit_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-wrench"></i>Edit</a> &nbsp;
					<a class="med-popup" tabindex="-1" href="?view=_add_note_to_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-pencil"></i>Add Note</a>
				</td>
				<?php 
            }
            ?>
			</tr>
			<?php 
            $is_first = FALSE;
        }
        ?>
		</table>
		<?php 
        return count($this->_persons);
    }
    function processView()
    {
        $GLOBALS['system']->includeDBClass('family');
        $GLOBALS['system']->includeDBClass('person');
        $GLOBALS['system']->includeDBClass('person_group');
        $GLOBALS['system']->includeDBClass('congregation');
        $GLOBALS['system']->includeDBClass('person_note');
        if (!empty($_REQUEST['done'])) {
            $this->_stage = 'done';
        } else {
            if (!empty($_POST['confirm_import'])) {
                ini_set('memory_limit', '256M');
                ini_set('max_execution_time', 60 * 10);
                ini_set('zlib.output_compression', 'Off');
                // read from session and create
                $GLOBALS['system']->doTransaction('BEGIN');
                $group = $GLOBALS['system']->getDBObject('person_group', $_SESSION['import']['groupid']);
                $this->_captureErrors();
                $done = 0;
                ?>
			<h1 style="position: absolute; text-align: center; top: 40%; color: #ccc; width: 100%">Importing...</h1>
			<div style="border: 1px solid; width: 50%; height: 30px; top: 50%; left: 25%; position: absolute"><div id="progress" style="background: blue; height: 30px; width: 2%; overflow: visible; line-height: 30px; text-align: center; color: white" /></div>
			<p style="text-align: center; color: #888">If this indicator stops making progress, your import may still be running in the background.<br />You should <a href="<?php 
                echo build_url(array('view' => 'persons__list_all'));
                ?>
">check your system for the imported persons</a> before running the import again.</p>
			<?php 
                foreach ($_SESSION['import']['families'] as $familydata) {
                    $members = $familydata['members'];
                    unset($familydata['members']);
                    $family = new Family();
                    $family->populate(0, $familydata);
                    if ($family->create()) {
                        foreach ($members as $persondata) {
                            $notetext = null;
                            if (!empty($persondata['note'])) {
                                $notetext = $persondata['note'];
                                unset($persondata['note']);
                            }
                            $person = new Person();
                            $person->populate(0, $persondata);
                            $person->setValue('familyid', $family->id);
                            if ($person->create()) {
                                $group->addMember($person->id);
                                if ($notetext) {
                                    $note = new Person_Note();
                                    $note->setValue('subject', 'Import note');
                                    $note->setvalue('details', $notetext);
                                    $note->setValue('personid', $person->id);
                                    $note->create();
                                    unset($note);
                                }
                                unset($person);
                            }
                        }
                        $done++;
                        if ($done % 20 == 0) {
                            ?>
<script>var d = document.getElementById('progress'); d.innerHTML = 'Importing family <?php 
                            echo $done . ' of ' . $_SESSION['import']['total_families'];
                            ?>
'; d.style.width = '<?php 
                            echo (int) ($done / $_SESSION['import']['total_families'] * 100);
                            ?>
%'</script><?php 
                            echo str_repeat('    ', 1024 * 4);
                        }
                        flush();
                        unset($family);
                    }
                }
                if ($errors = $this->_getErrors()) {
                    $msg = 'Errors during import - import aborted. <ul><li>' . implode('</li></li>', $errors) . '</li></ul>';
                    add_message($msg, 'failure', true);
                    $GLOBALS['system']->doTransaction('ROLLBACK');
                } else {
                    add_message('Import complete', 'success');
                    $GLOBALS['system']->doTransaction('COMMIT');
                }
                ?>
<script>document.location = '<?php 
                echo build_url(array());
                ?>
&done=1';</script>
			<?php 
                exit;
            } else {
                if (!empty($_FILES['import'])) {
                    if (empty($_REQUEST['groupid'])) {
                        add_message("You must choose a group first", 'error');
                        $this->stage = 'begin';
                        return;
                    }
                    if (empty($_FILES['import']) || empty($_FILES['import']['tmp_name'])) {
                        add_message("You must upload a file", 'error');
                        return;
                    }
                    $this->_dummy_family = new Family();
                    $this->_dummy_person = new Person();
                    // read the csv and save to session
                    $fp = fopen($_FILES['import']['tmp_name'], 'r');
                    if (!$fp) {
                        add_message("There was a problem reading your CSV file.  Please try again.", 'error');
                        $this->stage = 'begin';
                        return;
                    }
                    $map = fgetcsv($fp, 0, ",", '"');
                    $_SESSION['import']['groupid'] = (int) $_POST['groupid'];
                    $_SESSION['import']['families'] = array();
                    $_SESSION['import']['total_families'] = 0;
                    $_SESSION['import']['total_persons'] = 0;
                    $_SESSION['import']['total_notes'] = 0;
                    $row_errors = array();
                    $family = NULL;
                    $i = 1;
                    while ($rawrow = fgetcsv($fp, 0, ",", '"')) {
                        $row = array();
                        foreach ($map as $index => $fieldname) {
                            $row[$fieldname] = array_get($rawrow, $index);
                        }
                        if ($this->_isEmptyRow($row)) {
                            // Blank row = start a new family for the next row
                            unset($family);
                            continue;
                        }
                        if (!isset($family) || $this->_isNewFamily($row, $family)) {
                            // Add family
                            $this->_dummy_family->values = array();
                            $this->_dummy_family->setValue('status', 'current');
                            $this->_captureErrors();
                            $familyrow = $row;
                            unset($familyrow['status']);
                            $this->_dummy_family->fromCsvRow($familyrow);
                            if ($errors = $this->_getErrors()) {
                                $row_errors[$i] = $errors;
                            } else {
                                $_SESSION['import']['families'][] = $this->_dummy_family->values;
                                $family =& $_SESSION['import']['families'][count($_SESSION['import']['families']) - 1];
                                $_SESSION['import']['total_families']++;
                            }
                        } else {
                            // see if there's anything to update
                            // eg if the second family member has a home tel
                            foreach ($family as $fi => $fv) {
                                if ($family[$fi] === '' && $row[$fi] !== '') {
                                    $family[$fi] = $row[$fi];
                                }
                            }
                        }
                        $this->_captureErrors();
                        // Add a person and note
                        $this->_dummy_person->values = array();
                        $this->_dummy_person->setValue('familyid', '-1');
                        if (!empty($row['congregation'])) {
                            $row['congregationid'] = Congregation::findByName($row['congregation']);
                        }
                        $this->_dummy_person->fromCsvRow($row);
                        if ($errors = $this->_getErrors()) {
                            $row_errors[$i] = array_merge(array_get($row_errors, $i, array()), $errors);
                        } else {
                            $member = $this->_dummy_person->values + array('congregation' => $this->_dummy_person->getFormattedValue('congregationid'));
                            if (!empty($row['note'])) {
                                $member['note'] = $row['note'];
                                $_SESSION['import']['total_notes']++;
                            }
                            $family['members'][] = $member;
                            $_SESSION['import']['total_persons']++;
                        }
                        $i++;
                    }
                    if (!empty($row_errors)) {
                        $msg = 'Your import file is not valid.  Please correct the following errors and try again:<ul>';
                        foreach ($row_errors as $line => $errors) {
                            $msg .= '<li>Row ' . ($line + 1) . ': ' . implode('; ', $errors) . '</li>';
                        }
                        $msg .= '</ul>';
                        add_message($msg, 'failure', true);
                        $this->_stage = 'begin';
                    } else {
                        $this->_stage = 'confirm';
                    }
                }
            }
        }
    }
    function printForm($prefix = 0)
    {
        require_once 'include/size_detector.class.php';
        $order = defined('ATTENDANCE_LIST_ORDER') ? constant('ATTENDANCE_LIST_ORDER') : self::LIST_ORDER_DEFAULT;
        if ($this->congregationid) {
            $conds = array('congregationid' => $this->congregationid, '!status' => 'archived');
            if (strlen($this->age_bracket)) {
                $conds['age_bracket'] = $this->age_bracket;
            }
            $members = $GLOBALS['system']->getDBObjectData('person', $conds, 'AND', $order);
        } else {
            $group =& $GLOBALS['system']->getDBObject('person_group', $this->groupid);
            $members =& $group->getMembers(FALSE, $order);
            if (strlen($this->age_bracket)) {
                // Not the most efficient but it's a problem when it's a problem
                foreach ($members as $i => $person) {
                    if ($person['age_bracket'] != $this->age_bracket) {
                        unset($members[$i]);
                    }
                }
            }
        }
        $GLOBALS['system']->includeDBClass('person');
        $dummy = new Person();
        ?>
		<table class="table table-condensed table-auto-width valign-middle">
		<?php 
        $is_first = TRUE;
        foreach ($members as $personid => $details) {
            $v = isset($this->_attendance_records[$personid]) ? $this->_attendance_records[$personid] ? 'present' : 'absent' : (empty($this->_attendance_records) ? '' : 'unknown');
            $dummy->populate($personid, $details);
            ?>
			<tr>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td><?php 
                echo $personid;
                ?>
</td>
				<?php 
            }
            if ($this->show_photos) {
                ?>
				<td>
					<img style="width: 50px; max-width: 50px" src="?call=person_photo&personid=<?php 
                echo (int) $personid;
                ?>
" />
				</td>
				<?php 
            }
            ?>
				<td><?php 
            echo ents($details['last_name']);
            ?>
</td>
				<td><?php 
            echo ents($details['first_name']);
            ?>
</td>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td>
					<?php 
                if ($this->groupid) {
                    echo ents($details['membership_status']);
                } else {
                    $dummy->printFieldValue('status');
                }
                ?>
				</td>
				<?php 
            }
            ?>
				<td class="narrow">
					<?php 
            print_widget('attendances[' . $prefix . '][' . $personid . ']', array('options' => array('unknown' => '?', 'present' => 'Present', 'absent' => 'Absent'), 'type' => 'select', 'style' => 'colour-buttons', 'class' => $is_first ? 'autofocus' : ''), $v);
            ?>
				</td>
			<?php 
            if (!SizeDetector::isNarrow()) {
                ?>
				<td class="action-cell narrow">
					<a class="med-popup" tabindex="-1" href="?view=persons&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-user"></i>View</a> &nbsp;
					<a class="med-popup" tabindex="-1" href="?view=_edit_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-wrench"></i>Edit</a> &nbsp;
					<a class="med-popup" tabindex="-1" href="?view=_add_note_to_person&personid=<?php 
                echo $personid;
                ?>
"><i class="icon-pencil"></i>Add Note</a>
				</td>
				<?php 
            }
            ?>
			</tr>
			<?php 
            $is_first = FALSE;
        }
        ?>
		</table>
		<?php 
        return count($members);
    }
Exemple #13
0
 protected static function _generate4010A1($claimId, array $claim)
 {
     static $ctr = 0;
     static $visits = array();
     static $practices = array();
     static $insurancePrograms = array();
     static $providers = array();
     static $patients = array();
     $claimId = (int) $claimId;
     $claimLine = new ClaimLine();
     $claimLine->populateByClaimId($claimId);
     $visitId = (int) $claimLine->visitId;
     if (!isset($visits[$visitId])) {
         $visit = new Visit();
         $visit->visitId = $visitId;
         $visit->populate();
         $visits[$visitId] = $visit;
     }
     $visit = $visits[$visitId];
     $patientId = (int) $visit->patientId;
     if (!isset($patients[$patientId])) {
         $patient = new Patient();
         $patient->personId = $patientId;
         $patient->populate();
         $patients[$patientId] = $patient;
     }
     $patient = $patients[$patientId];
     $practiceId = (int) $visit->practiceId;
     if (!isset($practices[$practiceId])) {
         $practice = new Practice();
         $practice->practiceId = $practiceId;
         $practice->populate();
         $practices[$practiceId] = $practice;
     }
     $practice = $practices[$practiceId];
     $insuranceProgramId = (int) $visit->activePayerId;
     if (!isset($insurancePrograms[$insuranceProgramId])) {
         $insurance = new InsuranceProgram();
         $insurance->insuranceProgramId = $insuranceProgramId;
         $insurance->populate();
         $insurancePrograms[$insuranceProgramId] = $insurance;
     }
     $insuranceProgram = $insurancePrograms[$insuranceProgramId];
     $providerId = (int) $visit->treatingPersonId;
     if (!isset($providers[$providerId])) {
         $provider = new Provider();
         $provider->personId = $providerId;
         $provider->populate();
         $providers[$providerId] = $provider;
     }
     $provider = $providers[$providerId];
     $billAs = (int) $provider->billAs;
     if ($billAs > 0) {
         $providerId = $billAs;
         if (!isset($providers[$providerId])) {
             $provider = new Provider();
             $provider->personId = $providerId;
             $provider->populate();
             $providers[$providerId] = $provider;
         }
         $provider = $providers[$providerId];
     }
     $subscribers = array();
     $enumeration = new Enumeration();
     $enumeration->populateByUniqueName(InsuranceProgram::INSURANCE_ENUM_NAME);
     $enumerationClosure = new EnumerationClosure();
     foreach ($enumerationClosure->getAllDescendants($enumeration->enumerationId, 1, true) as $enum) {
         $rowset = $enumerationClosure->getAllDescendants($enum->enumerationId, 1, true);
         if ($enum->key == InsuranceProgram::INSURANCE_SUBSCRIBER_ENUM_KEY) {
             foreach ($rowset as $row) {
                 $subscribers[$row->key] = $row->name;
             }
             break;
         }
     }
     $insuredRelationship = new InsuredRelationship();
     $db = Zend_Registry::get('dbAdapter');
     $sqlSelect = $db->select()->from($insuredRelationship->_table)->where('insurance_program_id = ?', (int) $insuranceProgram->insuranceProgramId)->where('person_id = ?', (int) $patientId)->where('active = 1')->order('program_order')->limit(1);
     if ($row = $db->fetchRow($sqlSelect)) {
         $insuredRelationship->populateWithArray($row);
     }
     $subs = $insuredRelationship->subscriber;
     $subscriberAddr = $subs->address;
     $relationship = null;
     $relationshipCode = $insuredRelationship->subscriberToPatientRelationship;
     if (isset($subscribers[$relationshipCode])) {
         $relationship = $subscribers[$relationshipCode];
     }
     if ($relationship === null) {
         $relationship = 'Self';
         $relationshipCode = 18;
         $subs = new Person();
         $subs->personId = $insuredRelationship->personId;
         $subs->populate();
     }
     $subscriber = array('id' => (int) $subs->personId, 'relationship_code' => $relationshipCode, 'group_number' => $insuredRelationship->groupNumber, 'group_name' => $insuredRelationship->groupName, 'relationship' => $relationship, 'last_name' => $subs->lastName, 'first_name' => $subs->firstName, 'middle_name' => $subs->middleName, 'address' => array('line1' => $subscriberAddr->line1, 'line2' => $subscriberAddr->line2, 'city' => $subscriberAddr->city, 'state' => $subscriberAddr->state, 'zip' => $subscriberAddr->zipCode), 'date_of_birth' => date('Ymd', strtotime($subs->dateOfBirth)), 'gender' => $subs->gender, 'contract_type_code' => '', 'contract_amount' => '', 'contract_percent' => '', 'contract_code' => '', 'contract_discount_percent' => '', 'contract_version' => '');
     $practiceAddr = $practice->primaryAddress;
     $room = new Room();
     $room->roomId = (int) $visit->roomId;
     $room->populate();
     $facility = $room->building;
     $phoneNumber = PhoneNumber::autoFixNumber($practice->mainPhone->number);
     $phoneLen = strlen($phoneNumber);
     if ($phoneLen < 10) {
         $phoneNumber = str_pad($phoneNumber, 10, '0', STR_PAD_LEFT);
     } else {
         if ($phoneLen > 10) {
             $phoneNumber = substr($phoneNumber, -10);
         }
     }
     $identifierType = '';
     $identifier = $practice->identifier;
     if (strlen($identifier) > 0) {
         $identifierType = 'XX';
     }
     //24';
     $data = array('hlCount' => ++$ctr);
     $data['practice'] = array('name' => $practice->name, 'identifier_type' => $identifierType, 'identifier' => $identifier, 'address' => array('line1' => $practiceAddr->line1, 'line2' => $practiceAddr->line2, 'city' => $practiceAddr->city, 'state' => $practiceAddr->state, 'zip' => $practiceAddr->zipCode), 'phoneNumber' => $phoneNumber);
     $data['treating_facility'] = array('identifier' => $facility->identifier);
     $dateOfTreatment = date('Ymd', strtotime($visit->dateOfTreatment));
     $payer2Id = $insuranceProgram->insuranceProgramId;
     if (strlen($payer2Id) < 2) {
         $payer2Id = str_pad($payer2Id, 2, '0', STR_PAD_LEFT);
     }
     $identifierType = '';
     $identifier = $provider->person->identifier;
     if (strlen($identifier) > 0) {
         $identifierType = 'XX';
     }
     //34';
     $claimData = array('claim' => $claim, 'patient' => array('date_of_initial_treatment' => $dateOfTreatment, 'date_of_onset' => $dateOfTreatment, 'comment_type' => '', 'comment' => ''), 'treating_facility' => array('facility_code' => $facility->facilityCodeId, 'name' => $facility->name, 'address' => array('line1' => $facility->line1, 'line2' => $facility->line2, 'city' => $facility->city, 'state' => $facility->state, 'zip' => $facility->zipCode)), 'provider' => array('signature_on_file' => 'Y', 'accepts_assignment' => 'A', 'last_name' => $provider->person->lastName, 'first_name' => $provider->person->firstName, 'identifier_type' => $identifierType, 'identifier' => $identifier, 'identifier_2' => ''), 'billing_facility' => array('clia_number' => ''), 'subscriber' => $subscriber, 'clearing_house' => array('credit_max_amount' => '', 'repricing_method' => '', 'allowed_amount' => '', 'savings_amount' => '', 'identifier' => '', 'rate' => '', 'apg_code' => '', 'apg_amount' => '', 'reject_code' => '', 'compliance_code' => '', 'exception_code' => ''), 'referring_provider' => array('last_name' => '', 'first_name' => '', 'referral_type' => '', 'identifier_type' => '', 'identifier' => '', 'taxonomy_code' => ''), 'supervising_provider' => array('last_name' => '', 'first_name' => '', 'identifier_type' => '', 'identifier' => ''), 'payer2' => array('id' => $payer2Id, 'name' => $insuranceProgram->name));
     $clm = array();
     $iterator = new ClaimLineIterator();
     $iterator->setFilters(array('claimId' => $claimId));
     foreach ($iterator as $row) {
         $baseFee = (double) $row->baseFee;
         $adjustedFee = (double) $row->adjustedFee;
         $paid = (double) $row->paid;
         $billed = $row->totalMiscCharge;
         if ($baseFee > 0) {
             $billed += $baseFee - $adjustedFee;
         }
         $balance = abs($billed) - $paid;
         $clm[] = array('claim' => $claimData['claim'], 'patient' => $claimData['patient'], 'claim_line' => array('amount' => $balance, 'diagnosis1' => preg_replace('/[\\.]/', '', $row->diagnosisCode1), 'diagnosis2' => preg_replace('/[\\.]/', '', $row->diagnosisCode2), 'diagnosis3' => preg_replace('/[\\.]/', '', $row->diagnosisCode3), 'diagnosis4' => preg_replace('/[\\.]/', '', $row->diagnosisCode4), 'diagnosis5' => preg_replace('/[\\.]/', '', $row->diagnosisCode5), 'diagnosis6' => preg_replace('/[\\.]/', '', $row->diagnosisCode6), 'diagnosis7' => preg_replace('/[\\.]/', '', $row->diagnosisCode7), 'diagnosis8' => preg_replace('/[\\.]/', '', $row->diagnosisCode8), 'procedure' => $row->procedureCode, 'modifier1' => $row->modifier1, 'modifier2' => $row->modifier2, 'modifier3' => $row->modifier3, 'modifier4' => $row->modifier4, 'units' => str_replace('.00', '', $row->units), 'date_of_treatment' => $dateOfTreatment, 'clia_number' => ''), 'treating_facility' => $claimData['treating_facility'], 'provider' => $claimData['provider'], 'billing_facility' => $claimData['billing_facility'], 'subscriber' => $subscriber, 'clearing_house' => $claimData['clearing_house'], 'referring_provider' => $claimData['referring_provider'], 'supervising_provider' => $claimData['supervising_provider'], 'payer2' => $claimData['payer2']);
     }
     $hl2 = array();
     $hl2[] = array('hlCount' => $ctr, 'hlCount2' => ++$ctr, 'payer' => array('responsibility' => 'P'), 'subscriber' => $subscriber, 'patient' => array('weight' => '', 'last_name' => $patient->lastName, 'first_name' => $patient->firstName), 'responsible_party' => array('last_name' => '', 'first_name' => '', 'address' => array('line1' => '', 'line2' => '', 'city' => '', 'state' => '', 'zip' => '')), 'CLM' => $clm);
     $data['HL2'] = $hl2;
     return $data;
 }
 function flashUploadAction()
 {
     $attachmentReferenceId = (int) $this->_getParam('attachmentReferenceId');
     $fileData = base64_decode($this->_getParam('fileUpload'));
     $attachment = new Attachment();
     if (!isset($_FILES['uploadFile']['name'])) {
         $attachment->name = date('Y-m-d');
     } else {
         $attachment->name = $_FILES['uploadFile']['name'];
     }
     $attachment->attachmentReferenceId = $attachmentReferenceId;
     $attachment->mimeType = 'image/jpeg';
     $attachment->md5sum = md5($fileData);
     $attachment->dateTime = date('Y-m-d H:i:s');
     $attachment->persist();
     $attachmentBlobArray = array();
     $attachmentBlobArray['attachmentId'] = $attachment->attachmentId;
     $attachmentBlobArray['data'] = $fileData;
     $db = Zend_Registry::get('dbAdapter');
     $db->insert('attachmentBlobs', $attachmentBlobArray);
     $person = new Person();
     $person->personId = $attachmentReferenceId;
     $person->populate();
     $person->activePhoto = (int) $attachment->attachmentId;
     $person->persist();
     Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender();
     return;
 }
    ?>
					</a>
				</div>
				<?php 
}
?>
			<h3><?php 
echo _('Members');
?>
</h3>
			<form method="post" enctype="multipart/form-data" action="" class="bulk-person-action">

			<?php 
$dummy = new Person();
foreach ($family->getMemberData() as $personid => $person) {
    $dummy->populate($personid, $person);
    ?>
				<a href="?view=persons&personid=<?php 
    echo (int) $personid;
    ?>
">
				<div class="family-member">
					<?php 
    if ($GLOBALS['system']->featureEnabled('PHOTOS')) {
        ?>
						<img src="?call=photo&personid=<?php 
        echo $personid;
        ?>
" />
						<?php 
    }
Exemple #16
0
function replace_keywords($content, $person)
{
    static $dummy = NULL;
    if (!$dummy) {
        $dummy = new Person();
    }
    $dummy->populate($person['id'], $person);
    foreach ($person as $k => $v) {
        $keyword = '%' . strtoupper($k) . '%';
        if (FALSE !== strpos($content, $keyword)) {
            if ($k == 'expirydate') {
                $replacement = format_date($v);
            } else {
                $replacement = $dummy->getFormattedValue($k);
            }
            $content = str_replace($keyword, $replacement, $content);
        }
    }
    return $content;
}
 function save($update_members = TRUE)
 {
     $msg = '';
     if ($update_members) {
         if (!empty($this->_old_values['status'])) {
             if ($this->getValue('status') == 'archived') {
                 // Status has just been changed to 'archived' so archive members too
                 $members = $this->getMemberData();
                 if (!empty($members)) {
                     $GLOBALS['system']->includeDBClass('person');
                     $member = new Person();
                     $all_members_archived = TRUE;
                     foreach ($members as $id => $details) {
                         $member->populate($id, $details);
                         if ($member->canAcquireLock()) {
                             $member->acquireLock();
                             $member->setValue('status', 'archived');
                             $member->save(FALSE);
                             $member->releaseLock();
                         } else {
                             $all_members_archived = FALSE;
                         }
                     }
                     if ($all_members_archived) {
                         $msg = 'The ' . count($members) . ' members of the family have also been archived';
                     } else {
                         $msg = 'Not all members of the family could be accordingly archived because another user holds the lock';
                     }
                 }
             } else {
                 if ($this->_old_values['status'] == 'archived') {
                     // Status has just been changed from archived to something else
                     $msg = 'NB Members of the family will need to be de-archived separately';
                 }
             }
         }
         if (!empty($this->_old_values['family_name'])) {
             // Family name has changed
             // We update all the members' last names to match if
             // (a) there is only one member, or
             // (b) all members' current last name = the old family name
             $members = $this->getMemberData();
             if (count($members) == 1) {
                 $member = $GLOBALS['system']->getDBObject('person', key($members));
                 if ($member->canAcquireLock()) {
                     $member->acquireLock();
                     $member->setValue('last_name', $this->getValue('family_name'));
                     $member->save(FALSE);
                     $member->releaseLock();
                     $msg = 'The last name of the family\'s one member has also been set to "' . $this->getValue('family_name') . '"';
                 } else {
                     $msg = 'The family\'s one member could not be updated accordingly because another user holds the lock';
                 }
             } else {
                 if (!empty($members)) {
                     $members_all_have_family_name = TRUE;
                     foreach ($members as $id => $member) {
                         if ($member['last_name'] != $this->_old_values['family_name']) {
                             $members_all_have_family_name = FALSE;
                             break;
                         }
                     }
                     if ($members_all_have_family_name) {
                         $all_members_updated = TRUE;
                         $GLOBALS['system']->includeDBClass('person');
                         $member = new Person();
                         foreach ($members as $id => $details) {
                             $member->populate($id, $details);
                             if ($member->canAcquireLock()) {
                                 $member->acquireLock();
                                 $member->setValue('last_name', $this->getValue('family_name'));
                                 $member->save(FALSE);
                                 $member->releaseLock();
                             } else {
                                 $all_members_updated = FALSE;
                             }
                         }
                         if ($all_members_updated) {
                             $msg = 'Each family member\'s last name has also been set to "' . $this->getValue('family_name') . '"';
                         } else {
                             $msg = 'Not all family members could be updated with the new last name because another user holds the lock';
                         }
                     } else {
                         $msg = 'Family members have not been updated because they already have different last names';
                     }
                 }
             }
         }
     }
     $res = parent::save();
     if ($msg) {
         add_message($msg);
     }
     return $res;
 }
 protected function getMergeData()
 {
     $merge_type = array_get($_REQUEST, 'merge_type', 'person');
     switch ($merge_type) {
         case 'family':
             $GLOBALS['system']->includeDBClass('family');
             $merge_data = Family::getFamilyDataByMemberIDs($_POST['personid']);
             $dummy = new Family();
             break;
         case 'person':
         default:
             $temp_merge_data = $GLOBALS['system']->getDBObjectData('person', array('id' => $_POST['personid']));
             $merge_data = array();
             foreach ($_REQUEST['personid'] as $id) {
                 $merge_data[$id] = $temp_merge_data[$id];
             }
             $GLOBALS['system']->includeDBClass('person');
             $dummy = new Person();
             break;
     }
     foreach ($merge_data as $id => $row) {
         @$dummy->populate($id, $row);
         foreach ($row as $k => $v) {
             if ($k == 'history') {
                 unset($merge_data[$id][$k]);
             }
             if ($dummy->hasField($k)) {
                 $merge_data[$id][$k] = $dummy->getFormattedValue($k);
             }
             if ($k == 'selected_firstnames') {
                 $merge_data[$id]['selected_members'] = $v;
             }
         }
     }
     return $merge_data;
 }
 public function unallocatedFundsAction()
 {
     $personId = (int) $this->_getParam('personId');
     $person = new Person();
     $person->personId = $personId;
     $person->populate();
     $this->view->person = $person;
     $this->render();
 }
function getMergeVars($person_data, $email)
{
    static $dummy_person = null;
    if (is_null($dummy_person)) {
        $GLOBALS['system']->includeDBClass('person');
        $dummy_person = new Person();
    }
    $dummy_person->populate(0, $person_data);
    return array('EMAIL' => $email, 'FNAME' => $dummy_person->getFormattedValue('first_name'), 'LNAME' => $dummy_person->getFormattedValue('last_name'), 'GENDER' => $dummy_person->getFormattedValue('gender'), 'CONG' => $dummy_person->getFormattedValue('congregationid'), 'STATUS' => $dummy_person->getFormattedValue('status'), 'AGEBRACKET' => $dummy_person->getFormattedValue('age_bracket'));
}
 public function addProcessAction()
 {
     $dateActiveStart = strtotime($this->_getParam('dateActiveStart'));
     $dateActiveEnd = strtotime($this->_getParam('dateActiveEnd'));
     $serviceLevel = (int) $this->_getParam('serviceLevel');
     $personId = (int) $this->_getParam('personId');
     $provider = new Provider();
     $provider->person_id = $personId;
     $provider->populate();
     $provider->serviceLevel = $serviceLevel;
     if ($dateActiveStart > 0 && $dateActiveEnd > 0) {
         $provider->dateActiveStart = date('Y-m-d H:i:s', $dateActiveStart);
         $provider->dateActiveEnd = date('Y-m-d H:i:s', $dateActiveEnd);
     }
     $person = new Person();
     $person->person_id = $personId;
     $person->populate();
     $address = new Address();
     $address->person_id = $personId;
     $address->populateWithPersonId($personId);
     $phoneNumber = new PhoneNumber();
     $phoneNumber->person_id = $personId;
     $phoneNumber->populateWithType(4);
     $practice = new Practice();
     $practice->practiceId = $person->primaryPracticeId;
     $practice->populate();
     $data = array();
     $data['deaNumber'] = $provider->deaNumber;
     $data['stateLicenseNumber'] = $provider->stateLicenseNumber;
     //$data['portalId'] = Zend_Registry::get('config')->sureScripts->portalId;
     //$data['accountId'] = Zend_Registry::get('config')->sureScripts->accountId;
     $data['clinicName'] = '' . $practice->name;
     $data['lastName'] = $person->last_name;
     $data['firstName'] = $person->first_name;
     $address = new Address();
     $address->personId = $provider->personId;
     $address->populateWithType(4);
     $data['addressLine1'] = $address->line1;
     $data['addressLine2'] = $address->line2;
     $data['addressCity'] = $address->city;
     $data['addressState'] = $address->state;
     $data['addressZipCode'] = $address->zipCode;
     $data['email'] = $person->email;
     $phoneNumber = new PhoneNumber();
     $phoneNumber->personId = $provider->personId;
     /*
     $phoneNumberIterator = $phoneNumber->getIteratorByPatientId();
     $phones = array();
     foreach ($phoneNumberIterator as $number) {
     	if (!strlen($number->number) > 0) continue;
     	// SS Type options: BN - Beeper, CP - Cellular, FX - Fax, HP - Home, NP - Night, TE – Telephone*, WP – Work
     	$type = '';
     	switch ($number->type) {
     		case PhoneNumber::TYPE_HOME:
     			$type = 'HP'; 
     		case PhoneNumber::TYPE_WORK:
     			$type = 'WP';
     			break;
     		case PhoneNumber::TYPE_MOBILE:
     			$type = 'CP';
     			break;
     		case PhoneNumber::TYPE_FAX:
     			$type = 'FX';
     			break;
     		case PhoneNumber::TYPE_EMERGENCY:
     		case PhoneNumber::TYPE_EMPLOYER:
     		case PhoneNumber::TYPE_BILLING:
     			$type = 'TE';
     			break;
     		default:
     			continue;
     	}
     	$phones[$type] = array('number'=>$number->number,'type'=>$type);
     }
     $te = null;
     if (isset($phones['TE'])) {
     	$te = $phones['TE'];
     	unset($phones['TE']);
     }
     $fx = null;
     if (isset($phones['FX'])) {
     	$fx = $phones['FX'];
     	unset($phones['FX']);
     }
     if ($te === null) {
     	if (count($phones) > 0) {
     		$te = array_unshift($phones);
     	}
     	else if ($fx !== null) {
     		$te = $fx;
     	}
     }
     if ($fx === null) {
     	if (count($phones) > 0) {
     		$fx = array_unshift($phones);
     	}
     	else if ($te !== null) {
     		$fx = $te;
     	}
     }
     
     $data['phones'] = array();
     if ($te !== null) {
     	$data['phones'][] = $te;
     }
     if ($fx !== null) {
     	$data['phones'][] = $fx;
     }
     foreach ($phones as $p) {
     	$data['phones'][] = $p;
     }
     */
     $data['phones'] = $phoneNumber->phoneNumbers;
     /*$phoneNumbers = $phoneNumber->phoneNumbers;
     		$fax = '';
     		if (isset($phoneNumbers['FAX'])) {
     			$fax = $phoneNumbers['FAX'];
     			unset($phoneNumbers['FAX']);
     		}
     		$phone = $fax;
     		if (count($phoneNumbers) > 0) {
     			$phone = array_pop($phoneNumbers);
     		}
     		$data['phoneNumber'] = $phone;
     		$data['faxNumber'] = $fax;*/
     $data['specialtyCode'] = $provider->specialty;
     $specialtyQualifier = '';
     if (strlen($provider->specialty) > 0) {
         $specialtyQualifier = 'AM';
     }
     $data['specialtyQualifier'] = $specialtyQualifier;
     $data['serviceLevel'] = $provider->serviceLevel;
     $now = strtotime('now');
     $days30 = strtotime('+30 days', $now);
     $activeStartTime = gmdate("Y-m-d\\TH:i:s.0", $now) . 'Z';
     $activeEndTime = gmdate("Y-m-d\\TH:i:s.0", $days30) . 'Z';
     $data['activeStartTime'] = $provider->dateActiveStartZ;
     $data['activeEndTime'] = $provider->dateActiveEndZ;
     $dateActiveEnd = strtotime(date('Y-m-d', strtotime($provider->dateActiveEndZ)));
     if ($dateActiveEnd <= strtotime(date('Y-m-d'))) {
         // to disable a prescriber ActiveEndTime must be set to current date and ServiceLevel must be set to zero.
         $data['activeEndTime'] = date('Y-m-d');
         $data['serviceLevel'] = 0;
         $provider->serviceLevel = 0;
     }
     $provider->persist();
     $identifierType = $provider->identifierType;
     if (strlen($identifierType) > 0) {
         $data[$identifierType] = $provider->identifier;
     }
     /*
     		foreach ($data as $k=>$v) {
     			if (!strlen(trim($v)) > 0) {
     				$tmp = ' ';
     				if ($k == 'addressState') {
     					$tmp = 'AZ';
     				}
     				if ($k == 'addressZipCode') {
     					$tmp = '12345';
     				}
     				$data[$k] = $tmp;
     			}
     		}*/
     $messaging = new Messaging();
     //$messaging->messagingId = '';
     $type = 'add';
     $messaging->messageType = 'AddPrescriber';
     if (strlen($provider->sureScriptsSPI) > 0) {
         $messaging->messageType = 'UpdatePrescriber';
         $data['SPI'] = $provider->sureScriptsSPI;
         $type = 'update';
     }
     $messaging->populate();
     //$messaging->objectId = '';
     //$messaging->objectClass = '';
     $messaging->status = 'Sending';
     $messaging->note = 'Sending prescriber data';
     $messaging->dateStatus = date('Y-m-d H:i:s');
     //$messaging->auditId = '';
     $messaging->persist();
     $query = http_build_query(array('type' => $type, 'data' => $data));
     $ch = curl_init();
     $ePrescribeURL = Zend_Registry::get('config')->healthcloud->URL;
     $ePrescribeURL .= 'ss-manager.raw/edit-prescriber?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey;
     curl_setopt($ch, CURLOPT_URL, $ePrescribeURL);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $output = curl_exec($ch);
     trigger_error('OUTPUT: ' . $output, E_USER_NOTICE);
     $error = "";
     $prescriberSPI = '';
     $messaging->status = 'Sent';
     $messaging->note = 'Prescriber data sent';
     if (!curl_errno($ch)) {
         try {
             $responseXml = simplexml_load_string($output);
             if (isset($responseXml->error)) {
                 $errorCode = (string) $responseXml->error->code;
                 $errorMsg = (string) $responseXml->error->message;
                 if (isset($responseXml->error->errorCode)) {
                     $errorCode = (string) $responseXml->error->errorCode;
                 }
                 if (isset($responseXml->error->errorMsg)) {
                     $errorMsg = (string) $responseXml->error->errorMsg;
                 }
                 $error = $errorMsg;
                 trigger_error('There was an error enabling an ePresciber, Error code: ' . $errorCode . ' Error Message: ' . $errorMsg, E_USER_NOTICE);
             } elseif (isset($responseXml->data)) {
                 $xml = new SimpleXMLElement($responseXml->data);
                 $prescriber = $xml->AddPrescriberResponse->Prescriber;
                 if (isset($xml->AddPrescriberLocationResponse)) {
                     $prescriber = $xml->AddPrescriberLocationResponse->Prescriber;
                 }
                 $prescriberSPI = (string) $prescriber->Identification->SPI;
             }
             if (isset($responseXml->rawMessage)) {
                 $messaging->rawMessage = base64_decode((string) $responseXml->rawMessage);
                 $messaging->rawMessageResponse = base64_decode((string) $responseXml->rawMessageResponse);
             }
         } catch (Exception $e) {
             $error = __("There was an error connecting to HealthCloud to enable ePrescribing for this provider. Please try again or contact the system administrator.");
             trigger_error("There was an error enabling an ePresciber, the response couldn't be parsed as XML: " . $output, E_USER_NOTICE);
         }
     } else {
         $error = __("There was an error connecting to HealthCloud to enable ePrescribing for this provider. Please try again or contact the system administrator.");
         trigger_error("Curl error connecting to healthcare enabled an ePrescribe record: " . curl_error($ch), E_USER_NOTICE);
     }
     curl_close($ch);
     if (strlen($error) > 0) {
         $messaging->status = 'Error';
         $messaging->note = $error;
         $ret = false;
     }
     if ($messaging->resend) {
         $messaging->resend = 0;
     }
     $messaging->retries++;
     $messaging->dateStatus = date('Y-m-d H:i:s');
     $messaging->persist();
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $this->view->error = $error;
     if (strlen($error) > 0) {
         //$this->getResponse()->setHttpResponseCode(500);
         $json->direct(array('error' => $error));
         return;
     }
     if ($type == 'add') {
         $provider->sureScriptsSPI = trim($prescriberSPI);
         $provider->persist();
     } else {
         $prescriberSPI = $provider->sureScriptsSPI;
     }
     $this->view->message = "ePrescribing Information Saved for Provider, assigned SPI Number: " . $prescriberSPI;
     $this->view->prescriberSPI = $prescriberSPI;
     $json->direct(array('message' => $this->view->message, 'prescriberSPI' => $prescriberSPI, 'error' => $error));
 }
?>
<table class="table table-hover table-striped <?php 
if (empty($callbacks)) {
    echo 'clickable-rows';
}
?>
">
	<thead>
		<?php 
include 'person_list_header_footer.template.php';
?>
	</thead>
	<tbody>
	<?php 
foreach ($persons as $id => $details) {
    $dummy_person->populate($id, $details);
    $tr_class = $details['status'] === 'archived' ? ' class="archived"' : '';
    ?>
		<tr<?php 
    echo $tr_class;
    ?>
>
			<td><?php 
    echo $id;
    ?>
</td>
			<td class="nowrap"><?php 
    echo $dummy_person->printFieldvalue('name');
    ?>
</td>
		<?php 
 protected function _syncLocation(EPrescriber $ePrescriber)
 {
     $ret = true;
     $dateActiveStart = strtotime($ePrescriber->dateActiveStart);
     $dateActiveEnd = strtotime($ePrescriber->dateActiveEnd);
     $serviceLevel = (int) $ePrescriber->serviceLevel;
     $personId = (int) $ePrescriber->providerId;
     $provider = new Provider();
     $provider->personId = $personId;
     $provider->populate();
     $provider->serviceLevel = $serviceLevel;
     if ($dateActiveStart > 0 && $dateActiveEnd > 0) {
         $provider->dateActiveStart = date('Y-m-d H:i:s', $dateActiveStart);
         $provider->dateActiveEnd = date('Y-m-d H:i:s', $dateActiveEnd);
     }
     $person = new Person();
     $person->personId = $personId;
     $person->populate();
     $practice = new Practice();
     $practice->practiceId = $person->primaryPracticeId;
     $practice->populate();
     $data = array();
     $data['deaNumber'] = $provider->deaNumber;
     $data['stateLicenseNumber'] = $provider->stateLicenseNumber;
     //$data['portalId'] = Zend_Registry::get('config')->sureScripts->portalId;
     //$data['accountId'] = Zend_Registry::get('config')->sureScripts->accountId;
     $data['clinicName'] = '' . $practice->name;
     $data['lastName'] = $person->lastName;
     $data['firstName'] = $person->firstName;
     $address = $ePrescriber->building;
     $data['addressLine1'] = $address->line1;
     $data['addressLine2'] = $address->line2;
     $data['addressCity'] = $address->city;
     $data['addressState'] = $address->state;
     $data['addressZipCode'] = $address->zipCode;
     $data['email'] = $person->email;
     $data['phones'] = array(array('number' => PhoneNumber::autoFixNumber($address->phoneNumber), 'type' => 'TE'), array('number' => PhoneNumber::autoFixNumber($address->fax), 'type' => 'FX'));
     $data['specialtyCode'] = $provider->specialty;
     $specialtyQualifier = '';
     if (strlen($provider->specialty) > 0) {
         $specialtyQualifier = 'AM';
     }
     $data['specialtyQualifier'] = $specialtyQualifier;
     $data['serviceLevel'] = $provider->serviceLevel;
     $now = strtotime('now');
     $days30 = strtotime('+30 days', $now);
     $activeStartTime = gmdate("Y-m-d\\TH:i:s.0", $now) . 'Z';
     $activeEndTime = gmdate("Y-m-d\\TH:i:s.0", $days30) . 'Z';
     $data['activeStartTime'] = $provider->dateActiveStartZ;
     $data['activeEndTime'] = $provider->dateActiveEndZ;
     $dateActiveEnd = strtotime(date('Y-m-d', strtotime($provider->dateActiveEndZ)));
     if ($dateActiveEnd <= strtotime(date('Y-m-d'))) {
         // to disable a prescriber ActiveEndTime must be set to current date and ServiceLevel must be set to zero.
         $data['activeEndTime'] = date('Y-m-d');
         $data['serviceLevel'] = 0;
         $provider->serviceLevel = 0;
     }
     $provider->persist();
     $identifierType = $provider->identifierType;
     if (strlen($identifierType) > 0) {
         $data[$identifierType] = $provider->identifier;
     }
     $messaging = new Messaging();
     //$messaging->messagingId = '';
     $type = 'add';
     $messaging->messageType = 'AddPrescriber';
     if (strlen($ePrescriber->SSID) > 0) {
         $messaging->messageType = 'UpdatePrescriber';
         $data['SPI'] = $ePrescriber->SSID;
         $type = 'update';
     } else {
         if (strlen($provider->sureScriptsSPI) > 0) {
             $messaging->messageType = 'AddPrescriberLocation';
             $data['SPI'] = substr($provider->sureScriptsSPI, 0, -3);
             $type = 'addLocation';
         }
     }
     // backupPortalId must be supplied if type is updateLocation
     $messaging->populate();
     //$messaging->objectId = '';
     //$messaging->objectClass = '';
     $messaging->status = 'Sending';
     $messaging->note = 'Sending prescriber data';
     $messaging->dateStatus = date('Y-m-d H:i:s');
     //$messaging->auditId = '';
     $messaging->persist();
     $query = http_build_query(array('type' => $type, 'data' => $data));
     $ch = curl_init();
     $ePrescribeURL = Zend_Registry::get('config')->healthcloud->URL;
     $ePrescribeURL .= 'ss-manager.raw/edit-prescriber?apiKey=' . Zend_Registry::get('config')->healthcloud->apiKey;
     curl_setopt($ch, CURLOPT_URL, $ePrescribeURL);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $output = curl_exec($ch);
     trigger_error('OUTPUT: ' . $output, E_USER_NOTICE);
     $error = "";
     $prescriberSPI = '';
     $messaging->status = 'Sent';
     $messaging->note = 'Prescriber data sent';
     if (!curl_errno($ch)) {
         try {
             $responseXml = simplexml_load_string($output);
             if (isset($responseXml->error)) {
                 $errorCode = (string) $responseXml->error->code;
                 $errorMsg = (string) $responseXml->error->message;
                 if (isset($responseXml->error->errorCode)) {
                     $errorCode = (string) $responseXml->error->errorCode;
                 }
                 if (isset($responseXml->error->errorMsg)) {
                     $errorMsg = (string) $responseXml->error->errorMsg;
                 }
                 $error = $errorMsg;
                 trigger_error('There was an error enabling an ePresciber, Error code: ' . $errorCode . ' Error Message: ' . $errorMsg, E_USER_NOTICE);
             } elseif (isset($responseXml->data)) {
                 $xml = new SimpleXMLElement($responseXml->data);
                 $prescriber = $xml->AddPrescriberResponse->Prescriber;
                 //if ($type == 'addLocation') {
                 if (isset($xml->AddPrescriberLocationResponse)) {
                     $prescriber = $xml->AddPrescriberLocationResponse->Prescriber;
                 }
                 $prescriberSPI = (string) $prescriber->Identification->SPI;
                 if (!strlen($prescriberSPI) > 0) {
                     $error = 'Registration failed for location ' . $ePrescriber->building->name;
                 }
             }
             if (isset($responseXml->rawMessage)) {
                 $messaging->rawMessage = base64_decode((string) $responseXml->rawMessage);
                 $messaging->rawMessageResponse = base64_decode((string) $responseXml->rawMessageResponse);
             }
         } catch (Exception $e) {
             $error = __("There was an error connecting to HealthCloud to enable ePrescribing for this provider. Please try again or contact the system administrator.");
             trigger_error("There was an error enabling an ePresciber, the response couldn't be parsed as XML: " . $output, E_USER_NOTICE);
         }
     } else {
         $error = __("There was an error connecting to HealthCloud to enable ePrescribing for this provider. Please try again or contact the system administrator.");
         trigger_error("Curl error connecting to healthcare enabled an ePrescribe record: " . curl_error($ch), E_USER_NOTICE);
     }
     curl_close($ch);
     if (strlen($error) > 0) {
         $messaging->status = 'Error';
         $messaging->note = $error;
         $ret = false;
     }
     if ($messaging->resend) {
         $messaging->resend = 0;
     }
     $messaging->retries++;
     $messaging->dateStatus = date('Y-m-d H:i:s');
     $messaging->persist();
     if (strlen($error) > 0) {
         return $error;
     }
     if (!strlen($provider->sureScriptsSPI) > 0) {
         // handler of the first SPI
         $provider->sureScriptsSPI = $prescriberSPI;
         $provider->persist();
     }
     if ($type == 'add' || $type == 'addLocation') {
         $ePrescriber->SSID = $prescriberSPI;
         $ePrescriber->persist();
     }
     return $ret;
 }
    function printResults($with_links = FALSE)
    {
        $db = $GLOBALS['db'];
        $groupid = (int) $_REQUEST['groupid'];
        $all_member_details = array_get($_REQUEST, 'all_member_details', 0);
        if (empty($groupid)) {
            return;
        }
        $sql = '
		select family.id as familyid, family.family_name, family.home_tel, 
			person.*, congregation.long_name as congname,
			address_street, address_suburb, address_state, address_postcode
		from family 
		join person on family.id = person.familyid
		left join congregation on person.congregationid = congregation.id
		where person.status <> "archived"
		and family.id in 
		(select familyid 
		from person join person_group_membership pgm on person.id = pgm.personid
		where pgm.groupid = ' . (int) $groupid;
        if (!empty($_REQUEST['congregationid'])) {
            $sql .= '
				AND person.congregationid in (' . implode(',', array_map(array($db, 'quote'), $_REQUEST['congregationid'])) . ')';
        }
        $sql .= ')
		order by family_name asc, age_bracket asc, gender desc
		';
        $res = $db->queryAll($sql, null, null, true, true, true);
        check_db_result($res);
        if (empty($res)) {
            ?>
<p><i>No families to show</i></p><?php 
            return;
        }
        $sql = '
		select personid
		from person_group_membership pgm
		where pgm.groupid = ' . (int) $groupid;
        $signups = $db->queryCol($sql);
        check_db_result($signups);
        $GLOBALS['system']->includeDBClass('family');
        $GLOBALS['system']->includeDBClass('person');
        $dummy_family = new Family();
        $dummy_person = new Person();
        ?>

		<table class="contact-list">
		<?php 
        foreach ($res as $familyid => $family_members) {
            $adults = array();
            $children = array();
            $adults_use_full = false;
            $children_use_full = false;
            foreach ($family_members as $member) {
                if (empty($_REQUEST['age_bracket']) || in_array($member['age_bracket'], $_REQUEST['age_bracket'])) {
                    $adults[] = $member;
                    if ($member['last_name'] != $member['family_name']) {
                        $adults_use_full = true;
                    }
                } else {
                    $children[] = $member;
                    if ($member['last_name'] != $member['family_name']) {
                        $children_use_full = true;
                    }
                }
            }
            $first_member = reset($family_members);
            ?>
			<tr><td colspan="4"><h2 style="margin-bottom: 0px"><?php 
            echo $first_member['family_name'];
            ?>
</h2></td></tr>
			<?php 
            if ($first_member['home_tel']) {
                $dummy_family->setValue('home_tel', $first_member['home_tel']);
                echo '<tr><td colspan="4"><h3 style="border: 0px; margin: 0px; padding: 0px">';
                echo ents($dummy_family->getFormattedValue('home_tel'));
                echo '</h3></td></tr>';
            }
            if (!empty($_REQUEST['include_address']) && $first_member['address_street']) {
                echo '<tr><td colspan="4">' . nl2br(ents($first_member['address_street'])) . '<br />';
                echo ents($first_member['address_suburb'] . ' ' . $first_member['address_state'] . ' ' . $first_member['address_postcode']);
                echo '</td></tr>';
            }
            $fn = $with_links ? 'printFieldValue' : 'getFormattedValue';
            foreach ($adults as $adult) {
                $dummy_person->populate($adult['id'], $adult);
                ?>
				<tr>
					<td><?php 
                echo ents($adults_use_full ? $adult['first_name'] . ' ' . $adult['last_name'] : $adult['first_name']);
                ?>
</td>
					<td><?php 
                echo ents($adult['congname']);
                ?>
</td>
					<td><?php 
                if ($all_member_details || in_array($adult['id'], $signups)) {
                    echo ents($dummy_person->getFormattedValue('mobile_tel'));
                }
                ?>
</td>
					<td><?php 
                if ($all_member_details || in_array($adult['id'], $signups)) {
                    echo ents($dummy_person->{$fn}('email'));
                }
                ?>
</td>
				</tr>
				<?php 
            }
            $child_names = array();
            foreach ($children as $child) {
                $child_names[] = $children_use_full ? $child['first_name'] . ' ' . $child['last_name'] : $child['first_name'];
            }
            if ($child_names) {
                ?>
				<tr>
					<td colspan="4"><?php 
                echo ents(implode(', ', $child_names));
                ?>
</td
				</tr>
				<?php 
            }
            ?>
			<?php 
        }
        ?>
		</table>
		<?php 
    }
 public function listInsurersAction()
 {
     $patientId = (int) $this->_getParam('patientId');
     $rows = array();
     $insurancePrograms = InsuranceProgram::getInsurancePrograms();
     $insuredRelationship = new InsuredRelationship();
     $insuredRelationshipIterator = $insuredRelationship->getIteratorByPersonId($patientId);
     $subscribers = array();
     foreach ($insuredRelationshipIterator as $item) {
         $company = '';
         $program = '';
         if (isset($insurancePrograms[$item->insuranceProgramId])) {
             $exp = explode('->', $insurancePrograms[$item->insuranceProgramId]);
             $company = $exp[0];
             $program = $exp[1];
         }
         if (!isset($subscribers[$item->subscriberId])) {
             $person = new Person();
             $person->personId = $item->subscriberId;
             $person->populate();
             $subscribers[$item->subscriberId] = $person->displayName;
         }
         $effectiveEnd = date('m/d/Y', strtotime($item->effectiveEnd));
         $effective = 'Until';
         $effectiveToTime = strtotime($effectiveEnd);
         if ($effectiveToTime <= strtotime(date('m/d/Y'))) {
             $effective = 'Ended';
         }
         $effective .= ' ' . $effectiveEnd;
         $tmp = array();
         $tmp['id'] = $item->insuredRelationshipId;
         $tmp['data'][] = $company;
         $tmp['data'][] = $program;
         $tmp['data'][] = $item->groupName;
         $tmp['data'][] = $item->groupNumber;
         $tmp['data'][] = $item->copay;
         $tmp['data'][] = $subscribers[$item->subscriberId];
         $tmp['data'][] = $effective;
         $tmp['data'][] = $item->active ? __('Yes') : __('No');
         $rows[] = $tmp;
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct(array('rows' => $rows));
 }