1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* The MIT License |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 Julien Fastré <[email protected]>. |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
10
|
|
|
* in the Software without restriction, including without limitation the rights |
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
16
|
|
|
* all copies or substantial portions of the Software. |
17
|
|
|
* |
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24
|
|
|
* THE SOFTWARE. |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace PHPHealth\CDA\Elements; |
28
|
|
|
|
29
|
|
|
use PHPHealth\CDA\DataType\Quantity\DateAndTime\TimeStamp; |
30
|
|
|
use PHPHealth\CDA\DataType\Collection\Interval\PeriodicIntervalOfTime; |
31
|
|
|
use PHPHealth\CDA\DataType\Collection\Interval\IntervalOfTime; |
32
|
|
|
use PHPHealth\CDA\ClinicalDocument as CDA; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* |
37
|
|
|
* @author Julien Fastré <[email protected]> |
38
|
|
|
*/ |
39
|
|
|
class EffectiveTime extends AbstractElement |
40
|
|
|
{ |
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
* @var TimeStamp|PeriodicIntervalOfTime |
44
|
|
|
*/ |
45
|
|
|
protected $value; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
protected $operator = ''; |
52
|
|
|
|
53
|
|
|
public function __construct($value) |
54
|
|
|
{ |
55
|
|
|
$this->setValue($value); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function getValue() |
60
|
|
|
{ |
61
|
|
|
return $this->value; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setValue($value) |
65
|
|
|
{ |
66
|
|
|
if ($value instanceof PeriodicIntervalOfTime |
67
|
|
|
|| |
68
|
|
|
$value instanceof TimeStamp |
69
|
|
|
|| |
70
|
|
|
$value instanceof IntervalOfTime |
71
|
|
|
) { |
72
|
|
|
$this->value = $value; |
|
|
|
|
73
|
|
|
} else { |
74
|
|
|
throw new \UnexpectedValueException(sprintf("The timestamp must " |
75
|
|
|
. "implements %s, %s or %s", PeriodicIntervalOfTime::class, |
76
|
|
|
TimeStamp::class, IntervalOfTime::class)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function setOperatorAppend() |
83
|
|
|
{ |
84
|
|
|
$this->operator = 'A'; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function toDOMElement(\DOMDocument $doc) |
88
|
|
|
{ |
89
|
|
|
$el = $this->createElement($doc, ['value']); |
90
|
|
|
|
91
|
|
|
if ($this->operator === 'A') { |
92
|
|
|
$el->setAttribute(CDA::NS_CDA.'operator', 'A'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $el; |
|
|
|
|
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function getElementTag() |
99
|
|
|
{ |
100
|
|
|
return 'effectiveTime'; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.