public function testPersist() { // test case 3 $data = array(); $data['first_name'] = 'John'; $data['last_name'] = 'Doe'; $data['middle_name'] = 'C'; $result = NSDR2::persist('1234::com.clearhealth.person', $data); // verify if persist successful $result = NSDR2::populate('1234::com.clearhealth.person'); $this->assertEquals($result['first_name'], $data['first_name'], 'TEST CASE 3 failed.'); $this->assertEquals($result['last_name'], $data['last_name'], 'TEST CASE 3 failed.'); $this->assertEquals($result['middle_name'], $data['middle_name'], 'TEST CASE 3 failed.'); // test case 4 $result = NSDR2::persist('1234::com.clearhealth.person.middleName', array('harriet')); // verify if persist successful $result = NSDR2::populate('1234::com.clearhealth.person.middleName'); $this->assertEquals($result, 'harriet', 'TEST CASE 4 failed.'); $result = NSDR2::populate('1234::com.clearhealth.person'); $this->assertEquals($result['first_name'], $data['first_name'], 'TEST CASE 4 failed.'); $this->assertEquals($result['last_name'], $data['last_name'], 'TEST CASE 4 failed.'); $this->assertNotEquals($result['middle_name'], $data['middle_name'], 'TEST CASE 4 failed.'); }
/** * persist given a POST request * @todo: this method is temporarily not complete */ protected function persistPOST() { $ret = array(); foreach ($this->_nsdrNamespace as $key => $namespace) { $ret[$namespace] = NSDR2::persist($namespace, $this->_nsdrNamespaceValue[$key]); } }
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; }