예제 #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;
 }
 public function processEditAction()
 {
     $params = $this->_getParam('stats');
     $psd = new PatientStatisticsDefinition();
     if (!isset($params['guid']) || !(strlen($params['guid']) > 0)) {
         $params['guid'] = NSDR::create_guid();
     }
     $data = array();
     $id = (int) $params['patientStatisticsDefinitionId'];
     if ($id > 0) {
         $psd->patientStatisticsDefinitionId = $id;
         $psd->populate();
         if (isset($params['name']) && $psd->isNameExists($params['name'])) {
             $data['error'] = __('Name already exists') . ': ' . $params['name'];
         }
     }
     $psd->populateWithArray($params);
     if (!ctype_alpha(substr($psd->name, 0, 1))) {
         $data['error'] = __('Invalid name') . ': ' . $psd->name;
     }
     if (!isset($data['error'])) {
         $psd->persist();
         $data = $this->_generateStatsRow($psd);
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
 public function templatedTextAction()
 {
     $personId = $this->_getParam('personId', 0);
     $templateId = $this->_getParam('templateId', 0);
     $templateName = $this->_getParam('templateName');
     $templatedText = new TemplatedText();
     if ($templateId > 0) {
         $templatedText->templateId = $templateId;
         $templatedText->populate();
     } else {
         $templatedText->populateByName($templateName);
     }
     $template = $templatedText->template;
     preg_match_all('/{nsdr:(.*)}/', $template, $matches);
     if (count($matches[1]) > 0) {
         foreach ($matches[1] as $val) {
             $namespace = str_replace('[selectedPatientId]', $personId, $val);
             if (Zend_Registry::get('memcacheStatus') === 0) {
                 $resultValue = __("Memcache server not started");
             } else {
                 $result = NSDR::populate($namespace);
                 $resultValue = $result[$namespace];
                 if (is_array($resultValue) && isset($resultValue['error'])) {
                     $resultValue = $resultValue['error'];
                     $resultValue = __('No current data for: ') . $val;
                 }
             }
             $template = preg_replace('/{nsdr:(.*)}/', $resultValue, $template, 1);
         }
     }
     $this->view->template = $template;
     $this->render();
 }
예제 #4
0
 public static function getServices()
 {
     $ok = true;
     $services = array();
     $service = array();
     $id = 'nsdr';
     $service['id'] = $id;
     $service['name'] = 'NSDR';
     $nsdrStatus = NSDR::systemStatus();
     if ($nsdrStatus === false) {
         $ok = false;
         $nsdrStatus = 'stopped';
     }
     if ($nsdrStatus != 'started' && $nsdrStatus != 'reloaded') {
         $ok = false;
     }
     $service['status'] = ucwords($nsdrStatus);
     $services[$id] = $service;
     $service = array();
     $id = 'hl7d';
     $service['id'] = $id;
     $service['name'] = 'Processing Daemon';
     $hl7Status = false;
     // temporarily set to false
     if ($hl7Status === false) {
         $hl7Status = 'stopped';
     }
     $service['status'] = ucwords($hl7Status);
     $services[$id] = $service;
     $service = array();
     $id = 'menu';
     $service['id'] = $id;
     $service['name'] = 'Menu';
     $configItem = new ConfigItem();
     $configItem->configId = 'enableCache';
     $configItem->populate();
     $menuStatus = __('Disable');
     if ($configItem->value) {
         $menuStatus = __('Enable');
     } else {
         $ok = false;
     }
     $service['status'] = $menuStatus;
     $services[$id] = $service;
     $memcache = Zend_Registry::get('memcache');
     $serviceNominal = $memcache->get(self::SERVICE_NOMINAL);
     if ($ok) {
         $memcache = Zend_Registry::get('memcache');
         $memcache->set(self::SERVICE_NOMINAL, true);
     } else {
         if ($serviceNominal !== false) {
             $memcache->delete(self::SERVICE_NOMINAL);
         }
     }
     return $services;
 }
예제 #5
0
    public function persist($single = true)
    {
        if ($single) {
            return parent::persist();
        }
        $db = Zend_Registry::get('dbAdapter');
        if ($this->_persistMode == WebVista_Model_ORM::DELETE) {
            $sql = 'DELETE FROM `' . $this->_table . '` WHERE (`guid` = ' . $db->quote($this->guid) . ')';
            $db->query($sql);
            return $this;
        }
        if (!strlen($this->guid) > 0) {
            $this->guid = str_replace('-', '', NSDR::create_guid());
        }
        // Multiple fee schedule cannot be set for the same insurance programs for the same dates of service
        if ($this->hasConflicts()) {
            $error = __('Please choose different insurance programs or date of service.');
            throw new Exception($error);
        }
        if (!$this->dateObsolete || $this->dateObsolete == '0000-00-00') {
            $this->dateObsolete = $this->dateOfServiceEnd;
        }
        $updates = array();
        $fields = array();
        $values = array();
        $columns = array('name', 'guid', 'insuranceProgramIds', 'dateOfServiceStart', 'dateOfServiceEnd', 'procedureCode', 'fee', 'dateObsolete');
        foreach ($columns as $col) {
            $fields[$col] = '`' . $col . '`';
            $values[$col] = $db->quote($this->{$col});
            $updates[$col] = $fields[$col] . ' = ' . $values[$col];
        }
        $values['procedureCode'] = '`code`';
        unset($updates['guid']);
        unset($updates['procedureCode']);
        unset($updates['fee']);
        unset($updates['dateObsolete']);
        // name, guid, insuranceProgramIds, dateOfServiceStart, dateOfServiceEnd
        $sql = 'INSERT INTO `feeSchedules` (' . implode(', ', $fields) . ')
				SELECT ' . implode(', ', $values) . ' FROM procedureCodesCPT
			ON DUPLICATE KEY UPDATE ' . implode(', ', $updates);
        WebVista::debug($sql);
        $db->query($sql);
        return $this;
    }
 public function persist()
 {
     $db = Zend_Registry::get('dbAdapter');
     if ($this->_persistMode == WebVista_Model_ORM::DELETE) {
         return parent::persist();
     }
     $data = $this->toArray();
     if (!strlen($data['uuid']) > 0) {
         $this->uuid = NSDR::create_guid();
         $data['uuid'] = $this->uuid;
         $db->insert($this->_table, $data);
     } else {
         $db->update($this->_table, $data, 'uuid = ' . $db->quote($data['uuid']));
     }
     if ($this->shouldAudit()) {
         $audit = array();
         $audit['objectClass'] = get_class($this);
         $audit['objectId'] = $data['uuid'];
         $audit['auditValues'] = $data;
         Audit::persistManualAuditArray($audit);
     }
     return $this;
 }
예제 #7
0
    public static function generateTestTetanus()
    {
        $objects = array();
        $person = new Person();
        $person->last_name = 'ClearHealth';
        $person->first_name = 'Test';
        $person->middle_name = 'I';
        $person->active = 1;
        $person->persist();
        $objects['person'] = $person;
        $patient = new Patient();
        $patient->person->_cascadePersist = false;
        // to avoid persist() calls on person
        $patient->person_id = $person->person_id;
        $patient->recordNumber = 1000;
        $patient->persist();
        $objects['patient'] = $patient;
        $medication = new Medication();
        $medication->_shouldAudit = false;
        // do not audit
        $medication->hipaaNDC = 'hipaaNDC';
        $medication->personId = $patient->person_id;
        $medication->persist();
        $objects['medication'] = $medication;
        $audit = new Audit();
        $audit->_ormPersist = true;
        $audit->objectClass = get_class($medication);
        $audit->objectId = $medication->medicationId;
        $audit->dateTime = date('Y-m-d H:i:s');
        $audit->type = WebVista_Model_ORM::REPLACE;
        $audit->userId = (int) Zend_Auth::getInstance()->getIdentity()->personId;
        $audit->persist();
        $objects['audit'] = $audit;
        $handler = new HealthStatusHandler();
        $handler->name = 'Tetanus Shots Handler ' . NSDR::create_guid();
        $handler->active = 1;
        $handler->timeframe = '+1 month';
        //$handler->condition = $audit->auditId;
        $handlerName = Handler::normalizeHandlerName($handler->name);
        $handler->handlerObject = <<<EOL

class {$handlerName}HealthStatusHandlerObject extends HealthStatusHandlerObjectAbstract {
\t//abstract requires at least this method
\tpublic static function matchAudit(HealthStatusHandler \$handler,Audit \$auditOrm) {
\t\t// check if the patientId of the item referenced by the audit is subscribed to the handler, if not return false (no match)
\t\t\$objectClass = \$auditOrm->objectClass;
\t\t\$obj = new \$objectClass();
\t\tforeach (\$obj->_primaryKeys as \$key) {
\t\t\t\$obj->\$key = \$auditOrm->objectId;
\t\t}
\t\t\$obj->populate();
\t\t\$patientId = \$obj->personId;
\t\tif (!HealthStatusHandlerPatient::isPatientSubscribed(\$handler->healthStatusHandlerId,\$patientId)) {
\t\t\treturn false;
\t\t}
\t\tif (\$auditOrm->objectClass == '{$audit->objectClass}' && \$auditOrm->type == '{$audit->type}') {
\t\t\treturn true;
\t\t}
\t\treturn false;
\t}

\tpublic static function fulfill(HealthStatusHandler \$handler,\$patientId) {
\t\t// fulfill sees if current patient has any open alerts linked to this handler
\t\t\$alert = new HealthStatusAlert();
\t\t\$alert->populateByHandlerPatientId(\$handler->healthStatusHandlerId,\$patientId);
\t\t// if there are open alerts then calls patientMatch again
\t\tif (strlen(\$alert->status) > 0) {
\t\t\t// if patientMatch returns FALSE then marks alerts as fulfilled if patientMatch return non-false alerts stay as is
\t\t\t// sees if any alerts exist for the patient that are for this handler and marks then as fulfilled if the same condition in patientMatch is reversed
\t\t\tif (self::patientMatch(\$handler,\$patientId) === false) {
\t\t\t\t\$alert->status = 'fulfilled';
\t\t\t\t\$alert->persist();
\t\t\t}
\t\t}
\t}

\tpublic static function patientMatch(HealthStatusHandler \$handler,\$patientId) {
 \t\t// check if the patient does not have any record of a tetanus immunization (preferably by using NSDR)
\t\t// if it has, add the timeframe to the date of that immunization and check if that date is greater than today, if so then return true
\t\t// \$immunization = NSDR::populate(\$patientId.'::com.clearhealth.immunization');
\t\t// temporarily superseded NSDR
\t\t\$alert = new HealthStatusAlert();
\t\t\$alert->populateByHandlerPatientId(\$handler->healthStatusHandlerId,\$patientId);
\t\tif (!strlen(\$alert->status) > 0) {
\t\t\t// no existing alert, return true
\t\t\treturn true;
\t\t}
\t\t// would test to see if the date of a given patients last tetanus shot plus the timeframe is less than today
\t\t// if (strtotime(\$handler->timeframe,strtotime(\$alert->dateTime)) < strtotime(date('m/d/Y h:i A',strtotime('+1 month')))) {
\t\tif (\$alert->status == 'active') {
\t\t\tif (strtotime(\$alert->dateDue) < strtotime(date('m/d/Y h:i A',strtotime('+5 weeks')))) {
\t\t\t\t//self::fulfill(\$handler,\$patientId);
\t\t\t\treturn false;
\t\t\t}
\t\t\t// patientMatch checks if patient 1234 has NOT had a tetanus when date of last tetanus + timeframe < today and generates an alert
\t\t\treturn true;
\t\t}
\t\t/* \$alert->lastOccurence
\t\tif (\$alert->status == 'active' || \$alert->status == 'fulfilled' || \$alert->status == 'ignored') {
\t\t\t// would not match if patient already has an active, fulfilled or ignored alert
\t\t\treturn false;
\t\t}
\t\t*/
\t\treturn true;
\t}
}

EOL;
        $handler->datasource = $handler->generateDefaultDatasource();
        $handler->template = $handler->generateDefaultTemplate();
        $handler->persist();
        $objects['healthStatusHandler'] = $handler;
        // subscribe patient to handler
        $handlerPatient = new HealthStatusHandlerPatient();
        $handlerPatient->healthStatusHandlerId = $handler->healthStatusHandlerId;
        $handlerPatient->personId = $patient->personId;
        $handlerPatient->persist();
        $objects['healthStatusHandlerPatient'] = $handler;
        return $objects;
    }
예제 #8
0
    public static function populate(CCD $base, SimpleXMLElement $xml)
    {
        $component = $xml->addChild('component');
        $section = $component->addChild('section');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '2.16.840.1.113883.3.88.11.83.102');
        $templateId->addAttribute('assigningAuthorityName', 'HITSP/C83');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '1.3.6.1.4.1.19376.1.5.3.1.3.13');
        $templateId->addAttribute('assigningAuthorityName', 'IHE PCC');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '2.16.840.1.113883.10.20.1.2');
        $templateId->addAttribute('assigningAuthorityName', 'HL7 CCD');
        // <!--Allergies/Reactions section template-->
        $code = $section->addChild('code');
        $code->addAttribute('code', '48765-2');
        $code->addAttribute('codeSystem', '2.16.840.1.113883.6.1');
        $code->addAttribute('codeSystemName', 'LOINC');
        $code->addAttribute('displayName', 'Allergies');
        $section->addChild('title', 'Allergies and Adverse Reactions');
        $enumeration = new Enumeration();
        $listSymptoms = array();
        $enumeration->populateByEnumerationName(PatientAllergy::ENUM_SYMPTOM_PARENT_NAME);
        $enumerationsClosure = new EnumerationsClosure();
        $enumerationIterator = $enumerationsClosure->getAllDescendants($enumeration->enumerationId, 1);
        foreach ($enumerationIterator as $enum) {
            $listSymptoms[$enum->key] = $enum->name;
        }
        $filters = array('patientId' => $base->patient->personId);
        $base->setFiltersDateRange($filters);
        $rows = array();
        $allergies = PatientAllergy::listMedicationAllergies($filters);
        foreach ($allergies as $key => $allergy) {
            $exp = explode(',', $allergy['symptoms']);
            $symptoms = array();
            foreach ($exp as $symp) {
                $symptoms[] = isset($listSymptoms[$symp]) ? $listSymptoms[$symp] : '';
            }
            $reactionType = $allergy['reactionType'];
            if (!strlen($reactionType) > 0) {
                $reactionType = 'Unknown';
            }
            $active = (int) $allergy['active'] ? 'Active' : 'Inactive';
            $snomed = '';
            $row = array();
            $row['type'] = $reactionType;
            //'Drug Allergy';
            if ($reactionType == 'Specific Drug Allergy') {
                $snomed = '416098002';
            }
            $row['snomed'] = $snomed;
            $row['substance'] = html_convert_entities($allergy['causativeAgent']);
            $row['rxnorm'] = html_convert_entities($allergy['rxnorm_cuid']);
            $row['reaction'] = array('id' => 'ReactionID-' . $key, 'value' => html_convert_entities(implode(', ', $symptoms)));
            $row['date'] = date('M d, Y', strtotime($allergy['dateTimeReaction']));
            $row['status'] = html_convert_entities($active);
            $rows[] = $row;
        }
        /*
        -**SNOMED Allergy Type Code** (note from NIST: "The SNOMED Allergy Type Code is required by HITSP/C83, which is a component of the HITSP/C32 implementation guide specified by ONC in the Final Rule")
        -**Medication/Agent Allergy** (including medication/agent allergy and associated RxNorm code)
        */
        $text = $section->addChild('text');
        if ($rows) {
            $table = $text->addChild('table');
            $thead = $table->addChild('thead');
            $tr = $thead->addChild('tr');
            $tr->addChild('th', 'Type');
            $tr->addChild('th', 'Drug allergy SNOMED code');
            $tr->addChild('th', 'Substance');
            $tr->addChild('th', 'Substance RxNorm code');
            $tr->addChild('th', 'Reaction');
            $tr->addChild('th', 'Date Identified');
            $tr->addChild('th', 'Status');
            $tbody = $table->addChild('tbody');
            foreach ($rows as $row) {
                $tr = $tbody->addChild('tr');
                $tr->addChild('td', $row['type']);
                $tr->addChild('td', $row['snomed']);
                $tr->addChild('td', $row['substance']);
                $tr->addChild('td', $row['rxnorm']);
                $td = $tr->addChild('td', $row['reaction']['value']);
                $td->addAttribute('ID', $row['reaction']['id']);
                $tr->addChild('td', $row['date']);
                $tr->addChild('td', $row['status']);
            }
        }
        foreach ($allergies as $allergy) {
            $type = $allergy['reactionType'];
            if (!strlen($type) > 0) {
                $type = 'Unknown';
            }
            $substance = html_convert_entities($allergy['causativeAgent']);
            $exp = explode(',', $allergy['symptoms']);
            $symptoms = array();
            foreach ($exp as $symp) {
                $symptoms[] = isset($listSymptoms[$symp]) ? $listSymptoms[$symp] : '';
            }
            $reaction = '';
            if ($symptoms) {
                $reaction = html_convert_entities(implode(', ', $symptoms));
            }
            $status = 'Inactive';
            $statusCode = 'completed';
            $effectiveTimeHigh = '<high nullFlavor="UNK"/>';
            if ((int) $allergy['active']) {
                $status = 'Active';
                $statusCode = 'active';
                $effectiveTimeHigh = '';
            }
            $status = (int) $allergy['active'] ? 'Active' : 'Inactive';
            // STATUS CODES: active, suspended, aborted, completed
            $statusCode = (int) $allergy['active'] ? 'active' : 'completed';
            $entry = '<act classCode="ACT" moodCode="EVN">
				<templateId root="2.16.840.1.113883.3.88.11.83.6" assigningAuthorityName="HITSP C83"/>
				<templateId root="2.16.840.1.113883.10.20.1.27" assigningAuthorityName="CCD"/>
				<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.5.1" assigningAuthorityName="IHE PCC"/>
				<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.5.3" assigningAuthorityName="IHE PCC"/>
				<id root="' . NSDR::create_guid() . '"/>
				<code nullFlavor="NA"/>
				<statusCode code="' . $statusCode . '"/>
				<effectiveTime>
					<low nullFlavor="UNK"/>' . $effectiveTimeHigh . '
				</effectiveTime>
				<entryRelationship typeCode="SUBJ" inversionInd="false">
					<observation classCode="OBS" moodCode="EVN">
						<templateId root="2.16.840.1.113883.10.20.1.18" assigningAuthorityName="CCD"/>
						<templateId root="2.16.840.1.113883.10.20.1.28" assigningAuthorityName="CCD"/>
						<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.5" assigningAuthorityName="IHE PCC"/>
						<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.6" assigningAuthorityName="IHE PCC"/>
						<id root="' . NSDR::create_guid() . '"/>
						<code code="416098002" codeSystem="2.16.840.1.113883.6.96" displayName="drug allergy" codeSystemName="SNOMED CT" />
						<text>
							<reference value="PtrToValueInSectionText"/>
						</text>
						<statusCode code="completed"/>
						<effectiveTime>
							<low nullFlavor="UNK"/>
						</effectiveTime>
						<value xsi:type="CD"/>
						<participant typeCode="CSM">
							<participantRole classCode="MANU">
								<addr/>
								<telecom/>
								<playingEntity classCode="MMAT">
									<code code="70618" codeSystem="2.16.840.1.113883.6.88" displayName="' . $substance . '">
										<originalText>
											<reference value="PointrToSectionText"/>
										</originalText>
									</code>
									<name>' . $substance . '</name>
								</playingEntity>
							</participantRole>';
            if ($reaction != '' && false) {
                $entry .= '
							<entryRelationship typeCode="MFST" inversionInd="true">
								<observation classCode="OBS" moodCode="EVN">
									<templateId root="2.16.840.1.113883.10.20.1.54" assigningAuthorityName="CCD"/>
									<!--Reaction observation template -->
									<code code="ASSERTION" codeSystem="2.16.840.1.113883.5.4"/>
									<text/>
									<statusCode code="completed"/>
									<value xsi:type="CD" code="247472004" codeSystem="2.16.840.1.113883.6.96" displayName="' . $reaction . '"/>
									<entryRelationship typeCode="SUBJ">
										<observation classCode="OBS" moodCode="EVN">
											<templateId root="2.16.840.1.113883.10.20.1.55" assigningAuthorityName="CCD"/>
											<code code="SEV" displayName="Severity" codeSystemName="HL7 ActCode" codeSystem="2.16.840.1.113883.5.4"/>
											<text>Required by HITSP C-83</text>
											<statusCode code="completed"/>
											<value xsi:type="CE" displayName="moderate" code="6736007" codeSystemName="SNOMED" codeSystem="2.16.840.1.113883.6.96"/>
										</observation>
									</entryRelationship>
								</observation>
							</entryRelationship>';
            }
            $entry .= '
							<!--<entryRelationship typeCode="REFR">
								<observation classCode="OBS" moodCode="EVN">
									<templateId root="2.16.840.1.113883.10.20.1.39"/>
									<code code="33999-4" codeSystem="2.16.840.1.113883.6.1" displayName="Status"/>
									<statusCode code="completed"/>
									<value xsi:type="CE" code="55561003" codeSystem="2.16.840.1.113883.6.96" displayName="' . $status . '"/>
								</observation>
							</entryRelationship>-->
						</participant>
					</observation>
				</entryRelationship>
			</act>';
            $entry = $section->addChild('entry', $entry);
            $entry->addAttribute('typeCode', 'DRIV');
        }
    }
예제 #9
0
    public static function populate(CCD $base, SimpleXMLELement $xml)
    {
        $component = $xml->addChild('component');
        $section = $component->addChild('section');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '2.16.840.1.113883.3.88.11.83.103');
        $templateId->addAttribute('assigningAuthorityName', 'HITSP/C83');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '1.3.6.1.4.1.19376.1.5.3.1.3.6');
        $templateId->addAttribute('assigningAuthorityName', 'IHE PCC');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '2.16.840.1.113883.10.20.1.11');
        $templateId->addAttribute('assigningAuthorityName', 'HL7 CCD');
        // <!-- Problem section template -->
        $code = $section->addChild('code');
        $code->addAttribute('code', '11450-4');
        $code->addAttribute('codeSystem', '2.16.840.1.113883.6.1');
        $code->addAttribute('codeSystemName', 'LOINC');
        $code->addAttribute('displayName', 'Problem list');
        $section->addChild('title', 'Problems');
        $icd9Rows = array();
        $snomedRows = array();
        $rows = array('ICD-9' => array(), 'SNOMED' => array());
        foreach ($base->problemLists as $problem) {
            $code = html_convert_entities($problem->code);
            $row = array('code' => $code, 'problem' => html_convert_entities($problem->codeTextShort), 'date' => date('M d, Y', strtotime($problem->dateOfOnset)), 'status' => html_convert_entities($problem->status));
            if (strpos($code, '.') !== false) {
                $rows['ICD-9'][] = $row;
            } else {
                $rows['SNOMED'][] = $row;
            }
        }
        $text = $section->addChild('text');
        if ($rows) {
            foreach ($rows as $key => $values) {
                $table = $text->addChild('table');
                $thead = $table->addChild('thead');
                $tr = $thead->addChild('tr');
                $tr->addChild('th', $key . ' Code');
                $tr->addChild('th', 'Problem');
                $tr->addChild('th', 'Date Diagnosed');
                $tr->addChild('th', 'Problem Status');
                $tbody = $table->addChild('tbody');
                foreach ($values as $row) {
                    $tr = $tbody->addChild('tr');
                    $tr->addChild('td', $row['code']);
                    $tr->addChild('td', $row['problem']);
                    $tr->addChild('td', $row['date']);
                    $tr->addChild('td', $row['status']);
                }
            }
        }
        foreach ($base->problemLists as $problem) {
            $entry = '<act classCode="ACT" moodCode="EVN">
				<templateId root="2.16.840.1.113883.3.88.11.83.7" assigningAuthorityName="HITSP C83"/>
				<templateId root="2.16.840.1.113883.10.20.1.27" assigningAuthorityName="CCD"/>
				<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.5.1" assigningAuthorityName="IHE PCC"/>
				<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.5.2" assigningAuthorityName="IHE PCC"/>
				<!-- Problem act template -->
				<id root="' . NSDR::create_guid() . '"/>
				<code nullFlavor="NA"/>
				<statusCode code="active"/>
				<effectiveTime>
					<low nullFlavor="UNK"/>
				</effectiveTime>
				<performer typeCode="PRF">
					<time>
						<low nullFlavor="UNK"/>
					</time>
					<assignedEntity>
						<id extension="PseudoMD-' . $problem->providerId . '" root="2.16.840.1.113883.3.72.5.2"/>
						<addr/>
						<telecom/>
					</assignedEntity>
				</performer>
				<entryRelationship typeCode="SUBJ" inversionInd="false">
					<observation classCode="OBS" moodCode="EVN">
						<templateId root="2.16.840.1.113883.10.20.1.28" assigningAuthorityName="CCD"/>
						<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.5" assigningAuthorityName="IHE PCC"/>
						<!--Problem observation template -->
						<id root="' . NSDR::create_guid() . '"/>
						<code displayName="Condition" code="64572001" codeSystemName="SNOMED-CT" codeSystem="2.16.840.1.113883.6.96"/>
						<text>
							<reference value="#CondID-' . $problem->providerId . '"/>
						</text>
						<statusCode code="completed"/>
						<effectiveTime>
							<low nullFlavor="UNK"/>
							<high nullFlavor="UNK"/>
						</effectiveTime>
						<value xsi:type="CD" displayName="' . html_convert_entities($problem->codeTextShort) . '" code="233604007" codeSystemName="SNOMED" codeSystem="2.16.840.1.113883.6.96"/>
						<entryRelationship typeCode="REFR">
							<observation classCode="OBS" moodCode="EVN">
								<templateId root="2.16.840.1.113883.10.20.1.50"/>
								<!-- Problem status observation template -->
								<code code="33999-4" codeSystem="2.16.840.1.113883.6.1" displayName="Status"/>
								<statusCode code="completed"/>
								<value xsi:type="CE" code="413322009" codeSystem="2.16.840.1.113883.6.96" displayName="' . html_convert_entities($problem->status) . '"/>
							</observation>
						</entryRelationship>
					</observation>
				</entryRelationship>
			</act>';
            $entry = $section->addChild('entry', $entry);
            $entry->addAttribute('typeCode', 'DRIV');
        }
    }
예제 #10
0
 public function testEnumerations()
 {
     $memcache = Zend_Registry::get('memcache');
     $memcache->flush();
     NSDR::systemStart();
     $namespace = "*::com.clearhealth.enumerations.gender";
     $nsdr = NSDR::populate($namespace);
     //$this->assertEquals(count($nsdr[$namespace]),3);
     $namespace = "F::com.clearhealth.enumerations.gender";
     $nsdr = NSDR::populate($namespace);
     //$this->assertEquals(isset($nsdr[$namespace]['key']),true);
     //$this->assertEquals($nsdr[$namespace]['key'],'F');
 }
예제 #11
0
 public function updateGuid($oldGuid, $newGuid)
 {
     $db = Zend_Registry::get('dbAdapter');
     if (!strlen($newGuid) > 0) {
         $newGuid = str_replace('-', '', NSDR::create_guid());
     }
     $sql = 'UPDATE `' . $this->_table . '` SET `guid` = ' . $db->quote($newGuid) . ' WHERE (`guid` = ' . $db->quote($oldGuid) . ')';
     return $db->query($sql);
 }
예제 #12
0
 public function testAddDefinition()
 {
     $uuid = NSDR::create_guid();
     $nsdrParams = array('uuid' => $uuid, 'namespace' => 'com.clearhealth.person.age', 'aliasFor' => 'com.clearhealth.person.dateOfBirth');
     $objNSDR = new NSDRDefinition();
     $objNSDR->populateWithArray($nsdrParams);
     // workaround for Unknown column 'methodName'/'method' in 'field list'
     $objNSDR->methodName = array();
     $objNSDR->method = array();
     $objNSDR->persist();
     $nsdrDefinition = new NSDRDefinition();
     $nsdrDefinition->uuid = $uuid;
     $nsdrDefinition->populate();
     $this->assertEquals('com.clearhealth.person.age', $nsdrDefinition->namespace);
 }
예제 #13
0
    function listItemsAction()
    {
        $eSignIterator = new ESignatureIterator();
        $objectId = (int) $this->_getParam('objectId');
        if ($objectId > 0) {
            $eSignIterator->setFilter($objectId, 'objectId');
        } else {
            $eSignIterator->setFilter((int) Zend_Auth::getInstance()->getIdentity()->personId, 'signList');
        }
        //var_dump($db->query($cnSelect)->fetchAll());exit;
        $baseStr = "<?xml version='1.0' standalone='yes'?><rows></rows>";
        $xml = new SimpleXMLElement($baseStr);
        $currentCat = null;
        $category = null;
        // override the include_path to include controllers path
        set_include_path(realpath(Zend_Registry::get('basePath') . '/application/controllers') . PATH_SEPARATOR . get_include_path());
        foreach ($eSignIterator as $row) {
            $row = $row->toArray();
            $obj = new $row['objectClass']();
            foreach ($obj->_primaryKeys as $key) {
                $obj->{$key} = $row['objectId'];
            }
            if (!$obj->populate()) {
                continue;
            }
            // signing but actual object does not exists
            if ($currentCat != $row['objectClass']) {
                $currentCat = $row['objectClass'];
                $category = $xml->addChild("row");
                $category->addAttribute("style", 'height:20px;');
                $category->addAttribute("id", $row['objectClass']);
                $cell = $category->addChild("cell", call_user_func($currentCat . "::" . "getPrettyName", array()));
                $cell = $category->addChild("cell", '');
                $controllerName = call_user_func($currentCat . "::" . "getControllerName");
                $jumpLink = call_user_func_array($controllerName . "::" . "buildJSJumpLink", array($row['objectId'], $row['signingUserId'], $row['objectClass']));
                //$jumpLink = $this->buildJSJumpLink($row['objectId'],$row['signingUserId'],$row['objectClass']);
                $js = "function jumpLink{$row['objectClass']}(objectId,patientId) {\n{$jumpLink}\n}";
                //				$cell = $category->addChild('cell',$js);
                $userdata = $category->addChild('userdata', $js);
                $userdata->addAttribute('name', 'js');
            }
            $leaf = $category->addChild("row");
            $leaf->addAttribute('id', $row['eSignatureId']);
            $leaf->addChild('cell', $row['dateTime'] . " " . preg_replace('/[<>]/', '', $row['summary']));
            $leaf->addChild('cell', '');
            $userdata = $leaf->addChild('userdata', $row['objectId']);
            $userdata->addAttribute('name', 'objectId');
            // hidden column that will load the correct tab
            //			$leaf->addChild('cell',$row['objectId']); // temporary set to objectId
            //$leaf->addChild('cell',$this->buildJSJumpLink($row['objectId'],$row['signingUserId']));
            // for patientId hidden column, not sure if this is the correct field.
            //$leaf->addChild('cell',$row['signingUserId']);
            $patientId = $obj->personId;
            $userdata = $leaf->addChild('userdata', $patientId);
            $userdata->addAttribute('name', 'patientId');
            //$leaf->addChild('cell',$patientId);
            // add a subrow for other info
            if ($row['objectClass'] == 'Medication') {
                $pharmacyInfo = array();
                // $obj refers to Medication ORM
                if ($obj->isScheduled()) {
                    $pharmacyInfo[] = 'Medication is a controlled substance, it cannot be sent electronically. The Rx will be printed and needs a wet signature before it can be faxed to the pharmacy or handed to the patient.';
                } else {
                    $pharmacy = $obj->pharmacy;
                    if (strlen($pharmacy->StoreName) > 0) {
                        $pharmacyInfo[] = $pharmacy->StoreName;
                        $address = $pharmacy->AddressLine1;
                        if (strlen($pharmacy->AddressLine2) > 0) {
                            $address .= ' ' . $pharmacy->AddressLine2;
                        }
                        $address .= ', ' . $pharmacy->City;
                        $address .= ', ' . $pharmacy->State;
                        $address .= ', ' . $pharmacy->Zip;
                        $pharmacyInfo[] = $address;
                        $phones = array();
                        $phones[] = $pharmacy->PhonePrimary;
                        if (strlen($pharmacy->Fax) > 0) {
                            $phones[] = $pharmacy->Fax;
                        }
                        if (strlen($pharmacy->PhoneAlt1) > 0) {
                            $phones[] = $pharmacy->PhoneAlt1;
                        }
                        if (strlen($pharmacy->PhoneAlt2) > 0) {
                            $phones[] = $pharmacy->PhoneAlt2;
                        }
                        if (strlen($pharmacy->PhoneAlt3) > 0) {
                            $phones[] = $pharmacy->PhoneAlt3;
                        }
                        if (strlen($pharmacy->PhoneAlt4) > 0) {
                            $phones[] = $pharmacy->PhoneAlt4;
                        }
                        if (strlen($pharmacy->PhoneAlt5) > 0) {
                            $phones[] = $pharmacy->PhoneAlt5;
                        }
                        $pharmacyInfo[] = implode(', ', $phones);
                    } else {
                        $pharmacyInfo[] = 'No pharmacy selected';
                    }
                }
                $pharmacyInfo = implode(" <br /> ", $pharmacyInfo);
                $patient = new Patient();
                $patient->personId = $obj->personId;
                $patient->populate();
                $patientInfo = $patient->lastName . ", " . $patient->firstName . " " . strtoupper(substr($patient->middleName, 0, 1)) . " #" . $patient->recordNumber;
                $qualifiers = Medication::listQuantityQualifiersMapping();
                $medicationInfo = array();
                $rxn = $obj->rxReferenceNumber;
                if (strlen($rxn) > 0) {
                    $medicationInfo[] = 'Rx Reference Number: ' . $rxn;
                }
                $medicationInfo[] = 'Description: ' . htmlspecialchars($obj->description);
                $medicationInfo[] = 'Directions: ' . htmlspecialchars($obj->directions);
                $medicationInfo[] = 'Quantity: ' . $obj->quantity . ' ' . $qualifiers[$obj->quantityQualifier];
                //$medicationInfo[] = 'Quantity: '.$obj->quantity.' '.$obj->quantityQualifier;
                $medicationInfo[] = 'Strength: ' . $obj->dose . ' ' . $qualifiers[$obj->quantityQualifier];
                //$medicationInfo[] = 'Strength: '.$obj->dose.' '.$obj->quantityQualifier;
                $medicationInfo[] = 'Days Supply: ' . $obj->daysSupply;
                $refills = $obj->refills;
                if ($obj->prn) {
                    $refills = 'PRN';
                }
                $medicationInfo[] = 'Refills: ' . $refills;
                $substitution = 'Permitted';
                if ($obj->substitution == 0) {
                    $substitution = 'Not Permitted';
                }
                $medicationInfo[] = 'Substitutions: ' . $substitution;
                $medicationInfo[] = 'Date Prescribed: ' . date('Y-m-d', strtotime($obj->datePrescribed));
                //$medicationInfo[] = 'NDC: '.$obj->hipaaNDC;
                //$medicationInfo[] = 'Dosage Form: '.DataTables::getDosageForm($obj->chmedDose);
                //$medicationInfo[] = 'DB Code: '.$obj->pkey;
                $medicationInfo[] = 'Note: ' . htmlspecialchars($obj->comment);
                $medicationInfo = implode(' <br /> ', $medicationInfo);
                $info = '<div style="margin-left:75px;margin-top:-18px;margin-bottom:5px;">
					<fieldset>
						<legend title="' . htmlspecialchars($patientInfo) . '">' . __('Patient') . '</legend>' . htmlspecialchars($patientInfo) . '
					</fieldset>
					<fieldset>
						<legend title="' . htmlspecialchars($pharmacyInfo) . '">' . __('Pharmacy') . '</legend>' . htmlspecialchars($pharmacyInfo) . '
					</fieldset>
					<fieldset title="' . htmlspecialchars($medicationInfo) . '">
						<legend>' . __('Medication') . '</legend>' . htmlspecialchars($medicationInfo) . '
					</fieldset></div>';
                $node = $leaf->addChild('row');
                $guid = NSDR::create_guid();
                $node->addAttribute('id', $guid);
                //				$node->addAttribute('style','vertical-align:top;height:50px;');
                $node->addChild('cell', '<![CDATA[' . $info . ']]>');
                $node->addChild('cell', '');
                $node->addChild('cell', '');
                $node->addChild('cell', '');
            }
        }
        header('content-type: text/xml');
        $this->view->content = $xml->asXml();
        $this->view->content = html_entity_decode($this->view->content);
        file_put_contents('/tmp/esign.xml', $this->view->content);
        $this->render();
    }
 /**
  * Process the modified NSDR definition together its NSDR definition methods
  */
 public function processEditAction()
 {
     $this->editAction();
     // NSDR Definition parameters
     $params = $this->_getParam('nsdrDefinition');
     $this->_nsdrDefinition->populateWithArray($params);
     $id = $params['uuid'];
     if (!strlen($id) > 0) {
         $this->_nsdrDefinition->uuid = NSDR::create_guid();
     }
     $message = __('Record Saved for NSDR Definition: ' . $this->_nsdrDefinition->namespace);
     $code = 200;
     // cannot add method if alias exists (alias must be canonical)
     if (strlen($this->_nsdrDefinition->aliasFor) > 0) {
         $nsdr = new NSDRDefinition();
         //$nsdr->uuid = $this->_nsdrDefinition->aliasFor;
         //$nsdr->populate();
         $nsdr->populateByNamespace($this->_nsdrDefinition->aliasFor);
         if (strlen($nsdr->namespace) > 0) {
             if (strlen($nsdr->aliasFor) > 0) {
                 $this->_nsdrDefinition->aliasFor = '';
                 $message = __('Alias must be canonical.');
                 $code = 400;
             }
         } else {
             $this->_nsdrDefinition->aliasFor = '';
             $message = __('Alias does not exists.');
             $code = 401;
         }
     }
     if (strlen($this->_nsdrDefinition->ORMClass) > 0) {
         if (!NSDRDefinition::isORMClassImplementsMethod($this->_nsdrDefinition->ORMClass)) {
             $this->_nsdrDefinition->ORMClass = '';
             $message = __('Invalid ORM Class');
             $code = 402;
         }
     }
     $this->_nsdrDefinition->persist();
     $this->view->message = $message;
     $this->view->code = $code;
     $this->render('edit');
 }
예제 #15
0
    public static function populate(CCD $base, SimpleXMLElement $xml)
    {
        $component = $xml->addChild('component');
        $section = $component->addChild('section');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '2.16.840.1.113883.3.88.11.83.112');
        $templateId->addAttribute('assigningAuthorityName', 'HITSP/C83');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '1.3.6.1.4.1.19376.1.5.3.1.3.19');
        $templateId->addAttribute('assigningAuthorityName', 'IHE PCC');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '2.16.840.1.113883.10.20.1.8');
        $templateId->addAttribute('assigningAuthorityName', 'HL7 CCD');
        // <!-- Medications section template -->
        $code = $section->addChild('code');
        $code->addAttribute('code', '10160-0');
        $code->addAttribute('codeSystem', '2.16.840.1.113883.6.1');
        $code->addAttribute('codeSystemName', 'LOINC');
        $code->addAttribute('displayName', 'History of medication use');
        $section->addChild('title', 'Medications');
        $medications = array();
        $rows = array();
        $filters = array('patientId' => $base->patient->personId);
        $base->setFiltersDateRange($filters);
        $iterator = new MedicationIterator();
        $iterator->setFilter($filters);
        foreach ($iterator as $medication) {
            $medications[] = $medication;
            $datePrescribed = '&#160;';
            if ($medication->datePrescribed != '0000-00-00 00:00:00') {
                $datePrescribed = date('M d, Y', strtotime($medication->datePrescribed));
            }
            $baseMed24 = $medication->baseMed24;
            //$status = ($medication->status != 'Discontinued')?'Active':'Discontinued';
            $rows[] = array('rxnorm' => $baseMed24->rxnorm_cuid, 'product' => 'Medication', 'medication' => html_convert_entities($medication->description), 'generic' => html_convert_entities($baseMed24->fdaDrugname), 'brand' => html_convert_entities($baseMed24->tradename), 'instructions' => html_convert_entities($medication->directions), 'strength' => html_convert_entities($medication->strength), 'dose' => html_convert_entities($medication->dose), 'route' => html_convert_entities($medication->route), 'frequency' => html_convert_entities($medication->schedule), 'date' => $datePrescribed, 'status' => html_convert_entities($medication->displayStatus));
        }
        $text = $section->addChild('text');
        if ($rows) {
            $table = $text->addChild('table');
            $thead = $table->addChild('thead');
            $tr = $thead->addChild('tr');
            $tr->addChild('th', 'RxNorm Code');
            $tr->addChild('th', 'Product');
            $tr->addChild('th', 'Medication');
            $tr->addChild('th', 'Generic Name');
            $tr->addChild('th', 'Brand Name');
            $tr->addChild('th', 'Instructions');
            $tr->addChild('th', 'Strength');
            $tr->addChild('th', 'Dose');
            $tr->addChild('th', 'Route');
            $tr->addChild('th', 'Frequency');
            $tr->addChild('th', 'Date Started');
            $tr->addChild('th', 'Status');
            $tbody = $table->addChild('tbody');
            foreach ($rows as $row) {
                $tr = $tbody->addChild('tr');
                $tr->addChild('td', $row['rxnorm']);
                $tr->addChild('td', $row['product']);
                $tr->addChild('td', $row['medication']);
                $tr->addChild('td', $row['generic']);
                $tr->addChild('td', $row['brand']);
                $tr->addChild('td', $row['instructions']);
                $tr->addChild('td', $row['strength']);
                $tr->addChild('td', $row['dose']);
                $tr->addChild('td', $row['route']);
                $tr->addChild('td', $row['frequency']);
                $tr->addChild('td', $row['date']);
                $tr->addChild('td', $row['status']);
            }
        }
        foreach ($medications as $medication) {
            $quantity = '';
            if (strlen($medication->strength) > 0 && strlen($medication->unit) > 0) {
                $strength = explode(';', $medication->strength);
                $strength = str_replace(',', '', $strength[0]);
                $unit = explode(';', $medication->unit);
                if ($strength) {
                    $quantity = '<quantity value="' . $strength . '" unit="' . preg_replace('/ /', '', strtolower($unit[0])) . '"/>';
                }
            }
            $status = $medication->displayStatus;
            $description = html_convert_entities($medication->description);
            $entry = '<substanceAdministration classCode="SBADM" moodCode="EVN">
				<templateId root="2.16.840.1.113883.3.88.11.83.8" assigningAuthorityName="HITSP C83"/>
				<templateId root="2.16.840.1.113883.10.20.1.24" assigningAuthorityName="CCD"/>
				<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.7" assigningAuthorityName="IHE PCC"/>
				<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.7.1" assigningAuthorityName="IHE PCC"/>
				<!--Medication activity template -->
				<id root="' . NSDR::create_guid() . '"/>
				<statusCode code="completed"/>
				<effectiveTime xsi:type="IVL_TS">
					<low nullFlavor="UNK"/>
					<high nullFlavor="UNK"/>
				</effectiveTime>
				<effectiveTime xsi:type="PIVL_TS" institutionSpecified="false" operator="A">
					<period value="24" unit="h"/>
				</effectiveTime>
				<routeCode code="C38288" displayName="Oral" codeSystem="2.16.840.1.113883.3.26.1.1" codeSystemName="FDA RouteOfAdministration">
					<!--IHE/PCC recommends that the routeCode be taken from the HL7 RouteOfAdministration code system. However, HITSP/C32, C83 and C80 recommend that for the U.S. Realm it be taken from the FDA RouteOfAdministration code system.-->
					<translation displayName="Swallow, oral" code="PO" codeSystemName="HL7 RouteOfAdministration" codeSystem="2.16.840.1.113883.5.112"/>
				</routeCode>
				<doseQuantity value="1"/>
				<rateQuantity nullFlavor="NA"/>
				<consumable>
					<manufacturedProduct>
						<templateId root="2.16.840.1.113883.3.88.11.83.8.2" assigningAuthorityName="HITSP C83"/>
						<templateId root="2.16.840.1.113883.10.20.1.53" assigningAuthorityName="CCD"/>
						<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.7.2" assigningAuthorityName="IHE PCC"/>
						<!-- Product template -->
						<manufacturedMaterial>
							<code code="309362" codeSystem="2.16.840.1.113883.6.88" displayName="' . $description . '">
								<originalText>' . $description . '<reference/>
								</originalText>
								<translation code="174742" codeSystem="2.16.840.1.113883.6.88" displayName="' . $description . '" codeSystemName="RxNorm"/>
							</code>
							<name>Plavix</name>
						</manufacturedMaterial>
					</manufacturedProduct>
				</consumable>
				<entryRelationship typeCode="REFR">
					<observation classCode="OBS" moodCode="EVN">
						<templateId root="2.16.840.1.113883.10.20.1.47"/>
						<code code="33999-4" displayName="Status" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC"/>
						<value xsi:type="CE" code="55561003" displayName="' . $status . '" codeSystem="2.16.840.1.113883.6.96" codeSystemName="SNOMED CT"/>
					</observation>
				</entryRelationship>
				<entryRelationship typeCode="REFR">
					<supply classCode="SPLY" moodCode="INT">
						<templateId root="2.16.840.1.113883.10.20.1.34" assigningAuthorityName="CCD"/>
						<templateId root="2.16.840.1.113883.3.88.11.83.8.3" assigningAuthorityName="HITSP C83"/>
						<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.7.3" assigningAuthorityName="IHE PCC"/>
						<id/>
						<statusCode code="completed"/>
						<effectiveTime xsi:type="IVL_TS">
							<low value="20020101"/>
							<high nullFlavor="UNK"/>
						</effectiveTime>
						<repeatNumber value="1"/>' . $quantity . '
					</supply>
				</entryRelationship>
				<entryRelationship typeCode="SUBJ">
					<observation classCode="OBS" moodCode="EVN">
						<templateId root="2.16.840.1.113883.3.88.11.83.8.1" assigningAuthorityName="HITSP C83"/>
						<code code="73639000" codeSystem="2.16.840.1.113883.6.96" displayName="Prescription Drug"/>
					</observation>
				</entryRelationship>
			</substanceAdministration>';
            $entry = $section->addChild('entry', $entry);
            $entry->addAttribute('typeCode', 'DRIV');
        }
    }
예제 #16
0
 /**
  * Returns an array
  */
 protected function populateGET()
 {
     return NSDR::populate($this->_nsdrNamespace);
     $result = '';
     $key = $this->_nsdrNamespace;
     // extract method name from namespace
     preg_match('/\\[(.*)\\(\\)\\]$/', $this->_nsdrNamespace, $matches);
     // return if no method defined
     if (!isset($matches[1])) {
         return $result;
     }
     $nsdrMethodName = $matches[1];
     if ($method = $this->_memcache->get($key)) {
         // get returns FALSE if error or key not found
         $nsdrBase = new NSDRBase();
         // create anonymous function and use the code from memcache
         $anonFunc = create_function('$tthis', $method);
         if ($anonFunc === false) {
             return $result;
         }
         // assign the unique function name returned by create_function to NSDRBase property
         $nsdrBase->{$nsdrMethodName} = $anonFunc;
         // execute the function and pass the base as $tthis instead of $this
         $result = $nsdrBase->{$nsdrMethodName}($nsdrBase);
     }
     return $result;
 }
 public function generateTestDataAction()
 {
     NSDR::generateTestData();
     die('done');
 }
 public function processEditAction()
 {
     $params = $this->_getParam('feeSchedule');
     $oldGuid = $this->_getParam('oldGuid');
     $fs = new FeeSchedule();
     if (isset($params['guid'])) {
         if ($oldGuid != $params['guid'] && $oldGuid != '') {
             if (!strlen($params['guid']) > 0) {
                 $params['guid'] = str_replace('-', '', NSDR::create_guid());
             }
             $fs->updateGuid($oldGuid, $params['guid']);
         }
         $fs->guid = $params['guid'];
         $fs->populateByGuid();
     }
     $fs->populateWithArray($params);
     try {
         $fs->persist(false);
         $ret = $this->_generateRowData($fs);
     } catch (Exception $e) {
         $fs->populateByGuid();
         $ret = $e->getMessage();
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($ret);
 }
 protected function _processEdit()
 {
     $params = $this->_getParam('discountTable');
     $incomes = $this->_getParam('incomes');
     $oldGuid = $this->_getParam('oldGuid');
     $data = __('No inputs found');
     if (is_array($params)) {
         $discountTable = new DiscountTable();
         if (isset($params['guid'])) {
             if ($oldGuid != $params['guid'] && $oldGuid != '') {
                 if (!strlen($params['guid']) > 0) {
                     $params['guid'] = str_replace('-', '', NSDR::create_guid());
                 }
                 $discountTable->updateGuid($oldGuid, $params['guid']);
             }
             $discountTable->guid = $params['guid'];
             $discountTable->populateByGuid();
         }
         $discountTable->populateWithArray($params);
         if ($discountTable->hasConflicts()) {
             $data = __('Please choose different insurance programs or date of service.');
         } else {
             $ctr = 1;
             foreach ($incomes as $key => $value) {
                 $discountTable->populateWithArray($value);
                 $discountTable->discountId = $ctr++;
                 $discountTable->persist();
             }
             $data = $this->_generateRowData($discountTable);
         }
     }
     $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json');
     $json->suppressExit = true;
     $json->direct($data);
 }
예제 #20
0
 public function addNamespace($namespace, $ORMClass = '', $aliasFor = '', $recursive = true)
 {
     if ($recursive) {
         $x = explode('.', $namespace);
         $ns = array();
         foreach ($x as $n) {
             $ns[] = $n;
             $tmpNamespace = implode('.', $ns);
             if ($this->isNamespaceExists($tmpNamespace)) {
                 continue;
             }
             $this->addNamespace($tmpNamespace, $ORMClass, $aliasFor, false);
         }
         return true;
     }
     $nsdrDefinition = new self();
     $nsdrDefinition->namespace = $namespace;
     $nsdrDefinition->aliasFor = $aliasFor;
     $nsdrDefinition->ORMClass = $ORMClass;
     $nsdrDefinition->uuid = NSDR::create_guid();
     // random uuid
     $nsdrDefinition->persist();
     return true;
 }
예제 #21
0
 public function NSDRUnload()
 {
     return NSDR::systemUnload();
 }
예제 #22
0
 protected static function _saveEnumeration($data, $parentId = 0)
 {
     $enumerationsClosure = new EnumerationsClosure();
     foreach ($data as $item) {
         $enumerationId = $enumerationsClosure->insertEnumeration($item, $parentId);
         if (isset($item['data'])) {
             $item['guid'] = NSDR::create_guid();
             self::_saveEnumeration($item['data'], $enumerationId);
         }
     }
 }
예제 #23
0
    public static function generateUserLoggedOut()
    {
        $objects = self::_generatePatient();
        $handler = new GeneralAlertHandler();
        $handler->name = 'Logout Handler ' . NSDR::create_guid();
        $handler->active = 1;
        $handler->condition = 0;
        $handlerName = Handler::normalizeHandlerName($handler->name);
        $handler->handlerObject = <<<EOL

class {$handlerName}GeneralAlertHandlerObject extends GeneralAlertHandlerObjectAbstract {
\t//abstract requires at least this method
\tpublic static function matchAudit(Audit \$auditOrm) {
\t\tif (\$auditOrm->objectClass == 'Logout' && \$auditOrm->type == '1') {
\t\t\treturn true;
\t\t}
\t\treturn false;
\t}

}

EOL;
        $handler->datasource = <<<EOL

class {$handlerName}GeneralAlertDatasource extends GeneralAlertDatasourceAbstract {
\t//abstract requires at least this method
\tpublic static function sourceData(Audit \$audit) {
\t\t\$eSignIterator = new ESignatureIterator();
\t\t\$eSignIterator->setFilter(\$audit->userId,'signList');
\t\t\$ret = array();
\t\tforeach (\$eSignIterator as \$eSign) {
\t\t\t\$objectClass = \$eSign->objectClass;
\t\t\t\$obj = new \$objectClass();
\t\t\tforeach (\$obj->_primaryKeys as \$key) {
\t\t\t\t\$obj->\$key = \$eSign->objectId;
\t\t\t}
\t\t\t\$obj->populate();
\t\t\t\$personId = \$obj->personId;
\t\t\t\$patient = new Patient();
\t\t\t\$patient->personId = \$personId;
\t\t\t\$patient->populate();
\t\t\t\$teamId = \$patient->teamId;

\t\t\t\$row = array();
\t\t\t\$row['teamId'] = \$teamId;
\t\t\t\$row['signingUserId'] = \$eSign->signingUserId;
\t\t\t\$row['objectId'] = \$eSign->objectId;
\t\t\t\$row['objectClass'] = \$eSign->objectClass;
\t\t\t\$ret[] = \$row;
\t\t}
\t\treturn \$ret;
\t}
}

EOL;
        $handler->template = $handler->generateDefaultTemplate();
        $handler->persist();
        $objects['generalAlertHandler'] = $handler;
        return $objects;
    }
예제 #24
0
 public static function handlerSSSourceData(Audit $audit)
 {
     $data = array();
     if ($audit->objectClass != 'ESignature') {
         return $data;
     }
     $eSignature = new ESignature();
     $eSignature->eSignatureId = $audit->objectId;
     $eSignature->populate();
     if ($eSignature->objectClass != 'Medication' || !strlen($eSignature->signature) > 0) {
         WebVista::log('esignature is not signed or medication');
         return $data;
     }
     // MEDICATION DATA
     $medication = new Medication();
     $medication->medicationId = (int) $eSignature->objectId;
     $medication->populate();
     if ($medication->transmit != 'ePrescribe' || $medication->isScheduled()) {
         WebVista::log('medication is either scheduled or not an eprescribe');
         return $data;
     }
     WebVista::log('generating source data');
     $data['_audit'] = $audit;
     $uuid = NSDR::create_guid();
     $data['messageId'] = str_replace('-', '', $uuid);
     $data['prescriberOrderNumber'] = $medication->medicationId . '_' . $audit->auditId;
     $data['rxReferenceNumber'] = $medication->rxReferenceNumber;
     WebVista::log('messageId:[' . $data['messageId'] . '] prescriberOrderNumber:[' . $data['prescriberOrderNumber'] . '], rxReferenceNumber:[' . $data['rxReferenceNumber'] . ']');
     $medData = array();
     $medData['description'] = $medication->description;
     $medData['strength'] = $medication->dose;
     $qualifiers = Medication::listQuantityQualifiersMapping();
     $medData['strengthUnits'] = $qualifiers[$medication->quantityQualifier];
     // temporarily set to the same with quantity
     $medData['quantity'] = $medication->quantity;
     $medData['quantityUnits'] = $qualifiers[$medication->quantityQualifier];
     $medData['daysSupply'] = $medication->daysSupply;
     $medData['directions'] = $medication->directions;
     $qualifier = 'R';
     if ($medication->prn) {
         $qualifier = 'PRN';
     }
     $medData['refills'] = $medication->refills;
     $medData['refillsUnits'] = $qualifier;
     $medData['substitutions'] = $medication->substitution ? '0' : '1';
     $writtenDate = date('Ymd', strtotime($medication->datePrescribed));
     if ($medication->datePrescribed == '0000-00-00 00:00:00') {
         $writtenDate = '';
     }
     $medData['writtenDate'] = $writtenDate;
     $medData['productCode'] = $medication->hipaaNDC;
     $medData['productQualifier'] = 'ND';
     $medData['dosageForm'] = DataTables::getDosageForm($medication->chmedDose);
     $medData['drugDBCode'] = $medication->pkey;
     $medData['drugDBQualifier'] = '';
     //'pkey'; valid options: "E|G|FG|FS|MC|MD|MG|MM"
     $medData['note'] = $medication->comment;
     $data['Medication'] = $medData;
     WebVista::log('medication data: ' . print_r($medData, true));
     // PHARMACY DATA
     $pharmacy = new Pharmacy();
     $pharmacy->pharmacyId = $medication->pharmacyId;
     $pharmacy->populate();
     $pharmacyData = array();
     $pharmacyData['NCPDPID'] = $pharmacy->NCPDPID;
     $pharmacyData['fileId'] = $pharmacy->pharmacyId;
     $pharmacyData['NPI'] = $pharmacy->NPI;
     $pharmacyData['storeName'] = $pharmacy->StoreName;
     $pharmacyData['storeNumber'] = $pharmacy->StoreNumber;
     $pharmacyData['email'] = $pharmacy->Email;
     $pharmacyData['twentyFourHourFlag'] = $pharmacy->TwentyFourHourFlag;
     $pharmacyData['crossStreet'] = $pharmacy->CrossStreet;
     $pharmacyData['addressLine1'] = $pharmacy->AddressLine1;
     $pharmacyData['addressLine2'] = $pharmacy->AddressLine2;
     $pharmacyData['city'] = $pharmacy->City;
     $pharmacyData['state'] = $pharmacy->State;
     $pharmacyData['zip'] = $pharmacy->Zip;
     $phones = array();
     $phones[] = array('number' => $pharmacy->PhonePrimary, 'type' => 'TE');
     $phones[] = array('number' => $pharmacy->Fax, 'type' => 'FX');
     $phones[] = array('number' => $pharmacy->PhoneAlt1, 'type' => $pharmacy->PhoneAlt1Qualifier);
     $phones[] = array('number' => $pharmacy->PhoneAlt2, 'type' => $pharmacy->PhoneAlt2Qualifier);
     $phones[] = array('number' => $pharmacy->PhoneAlt3, 'type' => $pharmacy->PhoneAlt3Qualifier);
     $phones[] = array('number' => $pharmacy->PhoneAlt4, 'type' => $pharmacy->PhoneAlt4Qualifier);
     $phones[] = array('number' => $pharmacy->PhoneAlt5, 'type' => $pharmacy->PhoneAlt5Qualifier);
     $pharmacyData['phones'] = $phones;
     $data['Pharmacy'] = $pharmacyData;
     WebVista::log('pharmacy data: ' . print_r($pharmacyData, true));
     // PRESCRIBER DATA
     $provider = new Provider();
     $provider->personId = $medication->prescriberPersonId;
     $provider->populate();
     $prescriberData = array();
     $prescriberData['DEANumber'] = $provider->deaNumber;
     // it has conflicts with DEANumber
     //$prescriberData['stateLicenseNumber'] = $provider->stateLicenseNumber;
     $prescriberData['fileId'] = $provider->personId;
     $prescriberData['clinicName'] = '';
     $identifierType = $provider->identifierType;
     if (strlen($identifierType) > 0) {
         //	$prescriberData[$identifierType] = $provider->identifier;
     }
     $prescriberData['lastName'] = $provider->person->lastName;
     $prescriberData['firstName'] = $provider->person->firstName;
     $prescriberData['middleName'] = $provider->person->middleName;
     $prescriberData['suffix'] = $provider->person->suffix;
     $prescriberData['prefix'] = '';
     $prescriberData['email'] = $provider->person->email;
     $prescriberData['specialtyCode'] = $provider->specialty;
     $specialtyQualifier = '';
     if (strlen($provider->specialty) > 0) {
         $specialtyQualifier = 'AM';
     }
     $prescriberData['specialtyQualifier'] = $specialtyQualifier;
     $building = Building::getBuildingDefaultLocation((int) $provider->personId);
     $ePrescriber = new EPrescriber();
     $ePrescriber->providerId = (int) $provider->personId;
     $ePrescriber->buildingId = (int) $building->buildingId;
     $ePrescriber->populateWithBuildingProvider();
     $prescriberData['SPI'] = $ePrescriber->SSID;
     $prescriberData['addressLine1'] = $building->line1;
     $prescriberData['addressLine2'] = $building->line2;
     $prescriberData['city'] = $building->city;
     $prescriberData['state'] = $building->state;
     $prescriberData['zip'] = $building->zipCode;
     $prescriberData['phones'] = $building->phoneNumbers;
     $data['Prescriber'] = $prescriberData;
     WebVista::log('prescriber data: ' . print_r($prescriberData, true));
     // PATIENT DATA
     $patient = new Patient();
     $patient->personId = $medication->personId;
     $patient->populate();
     $patientData = array();
     $patientData['lastName'] = $patient->person->lastName;
     $patientData['firstName'] = $patient->person->firstName;
     $patientData['middleName'] = $patient->person->middleName;
     $patientData['suffix'] = $patient->person->suffix;
     $patientData['prefix'] = '';
     $patientData['email'] = $patient->person->email;
     $patientData['fileId'] = $patient->recordNumber;
     $patientData['medicareNumber'] = '';
     // TODO: to be implemented
     $identifierType = $patient->identifierType;
     if (strlen($identifierType) > 0) {
         $patientData[$identifierType] = $patient->identifier;
     }
     $patientData['gender'] = $patient->person->getDisplayGender();
     $dateOfBirth = date('Ymd', strtotime($patient->person->dateOfBirth));
     if ($patient->person->dateOfBirth == '0000-00-00') {
         $dateOfBirth = '';
     }
     $patientData['dateOfBirth'] = $dateOfBirth;
     $address = new Address();
     $address->personId = $patient->personId;
     $addressIterator = $address->getIteratorByPersonId();
     foreach ($addressIterator as $address) {
         break;
         // retrieves the top address
     }
     $patientData['addressLine1'] = $address->line1;
     $patientData['addressLine2'] = $address->line2;
     $patientData['city'] = $address->city;
     $patientData['state'] = $address->state;
     $patientData['zip'] = $address->zipCode;
     $phoneNumber = new PhoneNumber();
     $phoneNumber->personId = $patient->personId;
     $patientData['phones'] = $phoneNumber->phoneNumbers;
     $data['Patient'] = $patientData;
     WebVista::log('patient data: ' . print_r($patientData, true));
     // CHECK for attending/supervisor
     $attendingId = (int) TeamMember::getAttending($patient->teamId);
     $building = Building::getBuildingDefaultLocation($attendingId);
     $ePrescriber = new EPrescriber();
     $ePrescriber->providerId = $attendingId;
     $ePrescriber->buildingId = (int) $building->buildingId;
     $ePrescriber->populateWithBuildingProvider();
     if ($attendingId > 0 && strlen($ePrescriber->SSID) > 0) {
         // SUPERVISOR
         $provider = new Provider();
         $provider->personId = $attendingId;
         $provider->populate();
         $supervisorData = array();
         $supervisorData['DEANumber'] = $provider->deaNumber;
         $supervisorData['SPI'] = $ePrescriber->SSID;
         // it has conflicts with DEANumber
         //$supervisorData['stateLicenseNumber'] = $provider->stateLicenseNumber;
         $supervisorData['fileId'] = $provider->personId;
         $supervisorData['clinicName'] = '';
         $identifierType = $provider->identifierType;
         if (strlen($identifierType) > 0) {
             //	$prescriberData[$identifierType] = $provider->identifier;
         }
         $phoneNumber = new PhoneNumber();
         $phoneNumber->personId = $provider->personId;
         $supervisorData['phones'] = $phoneNumber->phoneNumbers;
         $supervisorData['lastName'] = $provider->person->lastName;
         $supervisorData['firstName'] = $provider->person->firstName;
         $supervisorData['middleName'] = $provider->person->middleName;
         $supervisorData['suffix'] = $provider->person->suffix;
         $supervisorData['prefix'] = '';
         $supervisorData['email'] = $provider->person->email;
         $supervisorData['specialtyCode'] = $provider->specialty;
         $specialtyQualifier = '';
         if (strlen($provider->specialty) > 0) {
             $specialtyQualifier = 'AM';
         }
         $supervisorData['specialtyQualifier'] = $specialtyQualifier;
         $supervisorData['addressLine1'] = $building->line1;
         $supervisorData['addressLine2'] = $building->line2;
         $supervisorData['city'] = $building->city;
         $supervisorData['state'] = $building->state;
         $supervisorData['zip'] = $building->zipCode;
         $supervisorData['phones'] = $building->phoneNumbers;
         $data['Supervisor'] = $supervisorData;
         WebVista::log('supervisor data: ' . print_r($supervisorData, true));
     }
     return $data;
 }
예제 #25
0
    public static function populate(CCD $base, SimpleXMLElement $xml)
    {
        $component = $xml->addChild('component');
        $section = $component->addChild('section');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '2.16.840.1.113883.3.88.11.83.122');
        $templateId->addAttribute('assigningAuthorityName', 'HITSP/C83');
        $templateId = $section->addChild('templateId');
        $templateId->addAttribute('root', '1.3.6.1.4.1.19376.1.5.3.1.3.28');
        $templateId->addAttribute('assigningAuthorityName', 'IHE PCC');
        // <!--Diagnostic Results section template-->
        $code = $section->addChild('code');
        $code->addAttribute('code', '30954-2');
        $code->addAttribute('codeSystem', '2.16.840.1.113883.6.1');
        $code->addAttribute('codeSystemName', 'LOINC');
        $code->addAttribute('displayName', 'Results');
        $section->addChild('title', 'Diagnostic Results');
        $rows = array();
        foreach ($base->labResults as $orderId => $value) {
            foreach ($value['results'] as $lab) {
                $rows[] = array('identifier' => html_convert_entities($lab->identifier), 'description' => html_convert_entities($lab->description), 'result' => html_convert_entities($lab->value . ' ' . $lab->units), 'abnormalFlag' => html_convert_entities($lab->abnormalFlag), 'date' => date('M d, Y', strtotime($lab->observationTime)));
            }
        }
        $text = $section->addChild('text');
        if ($rows) {
            $table = $text->addChild('table');
            $thead = $table->addChild('thead');
            $tr = $thead->addChild('tr');
            $tr->addChild('th', 'LOINC Code');
            $tr->addChild('th', 'Test');
            $tr->addChild('th', 'Result');
            $tr->addChild('th', 'Abnormal Flag');
            $tr->addChild('th', 'Date Performed');
            $tbody = $table->addChild('tbody');
            foreach ($rows as $row) {
                $tr = $tbody->addChild('tr');
                $tr->addChild('td', $row['identifier']);
                $tr->addChild('td', $row['description']);
                $tr->addChild('td', $row['result']);
                $tr->addChild('td', $row['abnormalFlag']);
                $tr->addChild('td', $row['date']);
            }
        }
        foreach ($base->labResults as $orderId => $value) {
            $orderLabTest = $value['orderLabTest'];
            $labTest = $value['labTest'];
            $results = $value['results'];
            $entry = '<organizer classCode="BATTERY" moodCode="EVN">
				<templateId root="2.16.840.1.113883.10.20.1.32"/>
				<!--Result organizer template -->
				<id root="' . NSDR::create_guid() . '"/>
				<code code="43789009" codeSystem="2.16.840.1.113883.6.96" displayName="' . html_convert_entities($labTest->service) . '"/>
				<statusCode code="completed"/>
				<effectiveTime value="' . date('YmdHi', strtotime($orderLabTest->dateCollection)) . '"/>
				<component>
					<procedure classCode="PROC" moodCode="EVN">
						<templateId root="2.16.840.1.113883.3.88.11.83.17" assigningAuthorityName="HITSP C83"/>
						<templateId root="2.16.840.1.113883.10.20.1.29" assigningAuthorityName="CCD"/>
						<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.19" assigningAuthorityName="IHE PCC"/>
						<id/>
						<code code="43789009" codeSystem="2.16.840.1.113883.6.96" displayName="' . html_convert_entities($labTest->service) . '">
							<originalText>' . html_convert_entities($orderLabTest->order->orderText) . '<reference value="Ptr to text  in parent Section"/>
							</originalText>
						</code>
						<text>' . html_convert_entities($orderLabTest->order->orderText) . '<reference value="Ptr to text  in parent Section"/>
						</text>
						<statusCode code="completed"/>
						<effectiveTime value="' . date('YmdHi', strtotime($orderLabTest->dateCollection)) . '"/>
						<performer>
							<assignedEntity>
								<id extension="PseudoMD-' . $orderLabTest->order->providerId . '" root="2.16.840.1.113883.3.72.5.2"/>
								<addr>See documentationOf in Header</addr>
								<telecom/>
							</assignedEntity>
						</performer>
					</procedure>
				</component>';
            foreach ($results as $result) {
                $referenceRange = '';
                if (strlen($result->referenceRange) > 0) {
                    $referenceRange = '
						<referenceRange>
							<observationRange>
								<text>' . html_convert_entities($result->referenceRange) . '</text>
							</observationRange>
						</referenceRange>';
                }
                if (is_numeric($result->value)) {
                    $resultValue = '<value xsi:type="PQ" value="' . html_convert_entities($result->value) . '" unit="' . html_convert_entities($result->units) . '"/>';
                } else {
                    $resultValue = '<value xsi:type="ST">' . html_convert_entities($result->value) . '</value>';
                }
                $entry .= '
				<component>
					<observation classCode="OBS" moodCode="EVN">
						<templateId root="2.16.840.1.113883.3.88.11.83.15" assigningAuthorityName="HITSP C83"/>
						<templateId root="2.16.840.1.113883.10.20.1.31" assigningAuthorityName="CCD"/>
						<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.13" assigningAuthorityName="IHE PCC"/>
						<templateId root="2.16.840.1.113883.3.88.11.83.15.1"/>
						<!-- Result observation template -->
						<id root="' . NSDR::create_guid() . '"/>
						<code code="' . html_convert_entities($result->identifier) . '" codeSystem="2.16.840.1.113883.6.1" displayName="' . html_convert_entities($result->description) . '"/>
						<text>
							<reference value="PtrToValueInsectionText"/>
						</text>
						<statusCode code="completed"/>
						<effectiveTime value="' . date('YmdHi', strtotime($result->observationTime)) . '"/>
						' . $resultValue . '
						<interpretationCode code="N" codeSystem="2.16.840.1.113883.5.83"/>
						' . $referenceRange . '
					</observation>
				</component>';
            }
            $entry .= '
				<component>
					<act classCode="ACT" moodCode="EVN">
						<templateId root="1.3.6.1.4.1.19376.1.5.3.1.4.4" assigningAuthorityName="IHE PCC"/>
						<id/>
						<code nullFlavor="NA"/>
						<text>
							<reference value="PointerToTextinSection"/>
						</text>
						<reference typeCode="REFR">
							<externalDocument classCode="DOC" moodCode="EVN">
								<id root="REGISTRYOID" extension="SOMEID" assigningAuthorityName="NIST Registry"/>
								<text>http://nist.etc</text>
							</externalDocument>
						</reference>
					</act>
				</component>
			</organizer>';
            $entry = $section->addChild('entry', $entry);
            $entry->addAttribute('typeCode', 'DRIV');
        }
    }
예제 #26
0
 public static function generateTestData()
 {
     $guids = array();
     $nsdrDefinition = new NSDRDefinition();
     $nsdrDefinition->truncate();
     $namespaces = array();
     $namespaces['com'] = array();
     $namespaces['com.clearhealth'] = array();
     $namespaces['com.clearhealth.enumerations'] = array('ORMClass' => 'Enumeration');
     $namespaces['com.clearhealth.enumerations.gender'] = array('aliasFor' => 'com.clearhealth.enumerations');
     $namespaces['com.clearhealth.person'] = array('methods' => array(array('methodName' => 'aggregateDisplay', 'method' => 'return "aggregateDisplay";'), array('methodName' => 'populate', 'method' => 'return "populated data";'), array('methodName' => 'persist', 'method' => 'return "persisted data";')));
     $namespaces['com.clearhealth.person.salutation'] = array();
     $namespaces['com.clearhealth.person.lastName'] = array();
     $namespaces['com.clearhealth.person.firstName'] = array();
     $namespaces['com.clearhealth.person.middleName'] = array();
     $namespaces['com.clearhealth.person.gender'] = array();
     $namespaces['com.clearhealth.person.dataOfBirth'] = array();
     $namespaces['com.clearhealth.person.problemList'] = array('ORMClass' => 'ProblemList');
     $namespaces['com.clearhealth.person.vitalSignsGroup'] = array('ORMClass' => 'VitalSignGroup');
     foreach ($namespaces as $namespace => $val) {
         $nsdr = clone $nsdrDefinition;
         $nsdr->uuid = NSDR::create_guid();
         $guids[] = $nsdr->uuid;
         $nsdr->namespace = $namespace;
         // workaround for Unknown column 'methodName'/'method' in 'field list'
         $nsdr->methodName = array();
         $nsdr->method = array();
         if (count($val) > 0) {
             $nsdr->populateWithArray($val);
         }
         $nsdr->persist();
         if (isset($val['methods'])) {
             $nsdr->persistMethods($val['methods']);
         }
     }
     return $guids;
 }
예제 #27
0
 public function executeQueries(array $filters, ReportView $view)
 {
     $config = Zend_Registry::get('config');
     $dbName = $config->database->params->dbname;
     $db = Zend_Registry::get('dbAdapter');
     $ret = array();
     $reportFilters = array();
     foreach ($this->reportFilters as $key => $filter) {
         $reportFilters['{{' . $filter->name . '}}'] = $filter;
     }
     //trigger_error(print_r($reportFilters,true),E_USER_NOTICE);
     $reportQuery = new ReportQuery();
     $reportQueryIterator = $reportQuery->getIteratorByBaseId($this->reportBaseId);
     foreach ($reportQueryIterator as $query) {
         $row = array();
         $row['reportQuery'] = $query->toArray();
         $queryValue = $query->query;
         $tokens = $this->_extractTokens($queryValue);
         if (isset($tokens[0])) {
             // tokens defined
             // check for undefined/orphaned filter
             $undefinedTokens = array();
             foreach ($tokens as $token) {
                 if (!isset($reportFilters[$token])) {
                     $undefinedTokens[] = $token;
                 }
             }
             if (isset($undefinedTokens[0])) {
                 $error = 'Query "' . $query->displayName . '" contains undefined tokens: ' . implode(', ', $undefinedTokens);
                 $row['error'] = $error;
                 trigger_error($error, E_USER_NOTICE);
                 $ret[] = $row;
                 continue;
             }
             $queryValue = $this->_applyFilters($filters, $queryValue, $tokens);
         }
         $columnDefinitions = $view->unserializedColumnDefinitions;
         switch ($query->type) {
             case ReportQuery::TYPE_SQL:
                 trigger_error($queryValue, E_USER_NOTICE);
                 try {
                     if ($view->customizeColumnNames) {
                         $results = array();
                         $stmt = $db->query($queryValue, array(), Zend_Db::FETCH_NUM);
                         $columnInfo = array();
                         $rowCount = $stmt->rowCount();
                         for ($i = 0; $i < $rowCount; $i++) {
                             $fetchRow = $stmt->fetch(Zend_Db::FETCH_NUM, null, $i);
                             if ($i == 0) {
                                 for ($ctr = 0, $rowLen = count($fetchRow); $ctr < $rowLen; $ctr++) {
                                     $columnMeta = $stmt->getColumnMeta($ctr);
                                     $resultSetName = $dbName . '.' . $columnMeta['table'] . '.' . $columnMeta['name'];
                                     foreach ($columnDefinitions as $id => $mapping) {
                                         // id, queryId, queryName, resultSetName, displayName, transform
                                         if ($mapping->resultSetName == $resultSetName) {
                                             $columnInfo[$ctr] = $mapping;
                                             break;
                                         }
                                     }
                                 }
                             }
                             $tmp = array();
                             foreach ($columnInfo as $index => $mapping) {
                                 $tmp[$mapping->displayName] = $this->_applyTransforms($mapping->transforms, $fetchRow[$index]);
                             }
                             $tmpResult = array();
                             foreach ($columnDefinitions as $id => $mapping) {
                                 // id, queryId, queryName, resultSetName, displayName, transform
                                 $tmpResult[$mapping->displayName] = $tmp[$mapping->displayName];
                             }
                             $results[] = $tmpResult;
                         }
                     } else {
                         $results = $db->fetchAll($queryValue);
                     }
                     $row['rows'] = $results;
                 } catch (Exception $e) {
                     $uniqErrCode = uniqid();
                     $row['error'] = 'There was a problem executing query: ' . $query->displayName . '. Contact your administrator with error code: ' . $uniqErrCode;
                     trigger_error('Exception error (' . $uniqErrCode . '): ' . $e->getMessage(), E_USER_NOTICE);
                     trigger_error('SQL Query (' . $uniqErrCode . '): ' . $queryValue, E_USER_NOTICE);
                 }
                 $ret[] = $row;
                 break;
             case ReportQuery::TYPE_NSDR:
                 $nsdr = explode("\n", $queryValue);
                 $results = array();
                 foreach ($nsdr as $key => $value) {
                     $tokens = $this->_extractTokens($queryValue);
                     if (isset($tokens[0])) {
                         $value = $this->_applyFilters($filters, $value);
                     }
                     $resultSetName = ReportView::extractNamespace($value);
                     $displayName = ReportView::metaDataPrettyName($resultSetName);
                     $nsdrResult = NSDR::populate($value);
                     $tmp = array('Name' => $displayName, 'Value' => '');
                     $tmp['Value'] = $nsdrResult[$value];
                     $results[] = $tmp;
                 }
                 if ($view->customizeColumnNames) {
                     $tmpResults = $results;
                     $results = array();
                     foreach ($columnDefinitions as $id => $mapping) {
                         // id, queryId, queryName, resultSetName, displayName, transform
                         if ($mapping->queryId != $query->reportQueryId && $mapping->queryName != $query->displayName) {
                             continue;
                         }
                         $displayName = ReportView::metaDataPrettyName($mapping->resultSetName);
                         $tmp = array('Name' => $displayName, 'Value' => '');
                         if (isset($tmpResults[$displayName])) {
                             $tmp['Value'] = $this->_applyTransforms($mapping->transforms, $tmpResults[$displayName]);
                         }
                         $results[] = $tmp;
                     }
                 }
                 $row['rows'] = $results;
                 $ret[] = $row;
                 break;
         }
     }
     return $ret;
 }