public function nsdrPopulate($tthis, $context, $data) { $context = (int) $context; $attributes = $tthis->_attributes; $nsdrNamespace = $tthis->_nsdrNamespace; $aliasedNamespace = $tthis->_aliasedNamespace; if ($context == '*') { if (isset($attributes['isDefaultContext']) && $attributes['isDefaultContext']) { // get genericData $objectClass = 'ClinicalNote'; $clinicalNoteId = 0; if (isset($attributes['clinicalNoteId'])) { $clinicalNoteId = (int) $attributes['clinicalNoteId']; } $revisionId = 0; if (isset($attributes['revisionId'])) { $revisionId = (int) $attributes['revisionId']; } if (!$revisionId > 0) { $revisionId = GenericData::getUnsignedRevisionId($objectClass, $clinicalNoteId); } $gd = new self(); $gd->objectClass = $objectClass; $gd->objectId = $clinicalNoteId; $gd->name = preg_replace('/[-\\.]/', '_', $nsdrNamespace); $gd->revisionId = $revisionId; $gd->loadValue(); return $gd->value; } else { // all $ret = array(); $gd = new self(); $gdIterator = $gd->getIterator(); foreach ($gdIterator as $g) { $ret[] = $g->toArray(); } return $ret; } } $gd = new self(); $gd->genericDataId = $context; $gd->populate(); return $gd->toArray(); }
function processAction() { $clinicalNoteId = (int) $this->_getParam('clinicalNoteId'); $revisionId = (int) $this->_getParam('revisionId'); $data = $this->_getParam('namespaceData'); $saveDate = date('Y-m-d H:i:s'); $cn = new ClinicalNote(); $cn->clinicalNoteId = $clinicalNoteId; $cn->populate(); if (!$revisionId > 0) { $revisionId = GenericData::getUnsignedRevisionId(get_class($cn), $cn->clinicalNoteId); } $eSignatureId = ESignature::retrieveSignatureId(get_class($cn), $revisionId); if ($eSignatureId > 0) { $msg = __('Failed to save. Note is already signed'); } else { $cn->dateTime = date('Y-m-d H:i:s'); $cn->persist(); $msg = __('Data saved.'); $template = $cn->clinicalNoteDefinition->clinicalNoteTemplate->template; $xml = simplexml_load_string($template); $objectClass = 'ClinicalNote'; list($name, $value) = each($data); $gd = new GenericData(); $gd->objectClass = $objectClass; $gd->objectId = $clinicalNoteId; $gd->name = $name; $rowExists = $gd->doesRowExist(true); $preQueries = null; if ($rowExists) { $revisionId = (int) $gd->revisionId; $preQueries = 'DELETE FROM `' . $gd->_table . '` WHERE `revisionId`=' . $revisionId; } else { $revisionId = WebVista_Model_ORM::nextSequenceId(); } $otm = new WebVista_Model_ORMTransactionManager(); foreach ($data as $name => $value) { $gd = new GenericData(); $gd->objectClass = $objectClass; $gd->objectId = $clinicalNoteId; $gd->dateTime = $saveDate; $gd->name = $name; $gd->value = $value; $gd->revisionId = $revisionId; $otm->addORM($gd); } if (!$otm->persist($preQueries)) { $msg = __('Failed to save.'); } if ((string) $xml->attributes()->useNSDR && (string) $xml->attributes()->useNSDR == 'true') { if (!ClinicalNote::processNSDRPersist($xml, $cn, $data)) { $msg = __('Failed to save.'); } } } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $json->direct($msg); }
public static function processNSDRPersist(SimpleXMLElement $xml, self $clinicalNote, array $data) { $ret = false; if ((string) $xml->attributes()->useNSDR != 'true') { $ret = false; } $revisionId = GenericData::getUnsignedRevisionId(get_class($clinicalNote), $clinicalNote->clinicalNoteId); $requests = array(); foreach ($xml as $questions) { foreach ($questions as $key => $item) { $namespace = (string) $item->attributes()->namespace; if ($key != 'dataPoint' || $namespace && !strlen($namespace) > 0) { continue; } $default = 0; $selectedPatientId = '[selectedPatientId]'; $key = str_replace($selectedPatientId, $clinicalNote->personId, $namespace); if (preg_match('/^[^.]*/', $key, $matches) && strpos($matches[0], '::') === false) { // context is not defined, default to *? $key = '*::' . $key; $default = 1; } if (preg_match('/(.*)\\[(.*)\\]$/', $key, $matches)) { $args = $matches[2]; $x = explode(',', $args); $x[] = '@revisionId=' . $revisionId; $x[] = '@clinicalNoteId=' . $clinicalNote->clinicalNoteId; $x[] = '@isDefaultContext=' . $default; $key = str_replace($args, implode(',', $x), $key); } else { $key .= '[@revisionId=' . $revisionId . ',@clinicalNoteId=' . $clinicalNote->clinicalNoteId . ',@isDefaultContext=' . $default . ']'; } $val = array(); $namespace = NSDR2::extractNamespace($namespace); // this MUST coincide with the $elementName of ClinicalNotesFormController::_buildForm() $elementName = preg_replace('/[-\\.]/', '_', $namespace); if (isset($data[$elementName])) { $val = $data[$elementName]; } //$requests[$key] = $val; if (!is_array($val)) { $val = array($val); } $ret = NSDR2::persist($key, $val); } } return $ret; }