/library/Zend/Gdata/Health/Extension/Ccr.php

http://github.com/michael-romer/zf-boilerplate · PHP · 124 lines · 48 code · 8 blank · 68 comment · 4 complexity · df2ca166e5fb6728c4dfc9357b04f523 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Gdata
  17. * @subpackage Health
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Ccr.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see Zend_Gdata_App_Extension_Element
  24. */
  25. require_once 'Zend/Gdata/App/Extension/Element.php';
  26. /**
  27. * Concrete class for working with CCR elements.
  28. *
  29. * @category Zend
  30. * @package Zend_Gdata
  31. * @subpackage Health
  32. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Gdata_Health_Extension_Ccr extends Zend_Gdata_App_Extension_Element
  36. {
  37. protected $_rootNamespace = 'ccr';
  38. protected $_rootElement = 'ContinuityOfCareRecord';
  39. protected $_ccrDom = null;
  40. /**
  41. * Creates a Zend_Gdata_Health_Extension_Ccr entry, representing CCR data
  42. *
  43. * @param DOMElement $element (optional) DOMElement from which this
  44. * object should be constructed.
  45. */
  46. public function __construct($element = null)
  47. {
  48. foreach (Zend_Gdata_Health::$namespaces as $nsPrefix => $nsUri) {
  49. $this->registerNamespace($nsPrefix, $nsUri);
  50. }
  51. }
  52. /**
  53. * Transfers each child and attribute into member variables.
  54. * This is called when XML is received over the wire and the data
  55. * model needs to be built to represent this XML.
  56. *
  57. * @param DOMNode $node The DOMNode that represents this object's data
  58. */
  59. public function transferFromDOM($node)
  60. {
  61. $this->_ccrDom = $node;
  62. }
  63. /**
  64. * Retrieves a DOMElement which corresponds to this element and all
  65. * child properties. This is used to build an entry back into a DOM
  66. * and eventually XML text for sending to the server upon updates, or
  67. * for application storage/persistence.
  68. *
  69. * @param DOMDocument $doc The DOMDocument used to construct DOMElements
  70. * @return DOMElement The DOMElement representing this element and all
  71. * child properties.
  72. */
  73. public function getDOM($doc = null, $majorVersion = 1, $minorVersion = null)
  74. {
  75. if ($doc === null) {
  76. $doc = new DOMDocument('1.0', 'utf-8');
  77. }
  78. $domElement = $doc->importNode($this->_ccrDom, true);
  79. return $domElement;
  80. }
  81. /**
  82. * Magic helper that allows drilling down and returning specific elements
  83. * in the CCR. For example, to retrieve the users medications
  84. * (/ContinuityOfCareRecord/Body/Medications) from the entry's CCR, call
  85. * $entry->getCcr()->getMedications(). Similarly, getConditions() would
  86. * return extract the user's conditions.
  87. *
  88. * @param string $name Name of the function to call
  89. * @param unknown $args
  90. * @return array.<DOMElement> A list of the appropriate CCR data
  91. */
  92. public function __call($name, $args)
  93. {
  94. if (substr($name, 0, 3) === 'get') {
  95. $category = substr($name, 3);
  96. switch ($category) {
  97. case 'Conditions':
  98. $category = 'Problems';
  99. break;
  100. case 'Allergies':
  101. $category = 'Alerts';
  102. break;
  103. case 'TestResults':
  104. // TestResults is an alias for LabResults
  105. case 'LabResults':
  106. $category = 'Results';
  107. break;
  108. default:
  109. // $category is already well formatted
  110. }
  111. return $this->_ccrDom->getElementsByTagNameNS($this->lookupNamespace('ccr'), $category);
  112. } else {
  113. return null;
  114. }
  115. }
  116. }