src/Domain/Whater/Model/AnalyticalParameter.php line 16

Open in your IDE?
  1. <?php
  2. namespace Whater\Domain\Whater\Model;
  3. use BornFree\TacticianDomainEvent\Recorder\ContainsRecordedEvents;
  4. use BornFree\TacticianDomainEvent\Recorder\EventRecorderCapabilities;
  5. use InvalidArgumentException;
  6. use Ramsey\Uuid\Uuid;
  7. use Whater\Domain\Common\Exception\InvalidUUIDException;
  8. /**
  9. * Class AnalyticalParameter
  10. *
  11. * @package Whater\Domain\Whater\Model
  12. */
  13. class AnalyticalParameter implements ContainsRecordedEvents
  14. {
  15. use EventRecorderCapabilities;
  16. // Qualities Constants
  17. public const QUALITY_IMPROVE_PERCEPTION = 'IMPROVE_PERCEPTION';
  18. public const QUALITY_BIOLOGICAL_CONTAMINATION = 'BIOLOGICAL_CONTAMINATION';
  19. public const QUALITY_PESTICIDES = 'PESTICIDES';
  20. public const QUALITY_MEDICINES = 'MEDICINES';
  21. public const QUALITY_PFA = 'PFA';
  22. public const QUALITY_OXIDANTS = 'OXIDANTS';
  23. public const QUALITY_BYPRODUCTS = 'BYPRODUCTS';
  24. public const QUALITY_HYDROCARBONS = 'HYDROCARBONS';
  25. public const QUALITY_SYNTHETIC_CHEMICALS = 'SYNTHETIC_CHEMICALS';
  26. public const QUALITY_ORGANIC = 'ORGANIC';
  27. public const QUALITY_RADIOACTIVITY = 'RADIOACTIVITY';
  28. public const QUALITY_METALS = 'METALS';
  29. public const QUALITY_SALTS = 'SALTS';
  30. public const QUALITY_NITRATES_SULFATES_PHOSPHATES = 'NITRATES_SULFATES_PHOSPHATES';
  31. public const QUALITY_MINERALIZATION = 'MINERALIZATION';
  32. public const QUALITY_IRON_MANGANESE = 'IRON_MANGANESE';
  33. /**
  34. * @var string
  35. */
  36. private $uuid;
  37. /**
  38. * @var string
  39. */
  40. private $parameterCode;
  41. /**
  42. * @var string
  43. */
  44. private $parameterName;
  45. /**
  46. * @var string
  47. */
  48. private $parameterMetric;
  49. /**
  50. * @var float
  51. */
  52. private $referenceMinValue;
  53. /**
  54. * @var float
  55. */
  56. private $referenceValue;
  57. /**
  58. * @var float
  59. */
  60. private $referenceMaxValue;
  61. /**
  62. * @var float
  63. */
  64. private $limitMinValue;
  65. /**
  66. * @var float
  67. */
  68. private $limitMaxValue;
  69. /**
  70. * @var string
  71. */
  72. private $positivePresenceEffects;
  73. /**
  74. * @var string
  75. */
  76. private $negativePresenceEffects;
  77. /**
  78. * @var string
  79. */
  80. private $negativeAbsenceEffects;
  81. /**
  82. * @var string
  83. */
  84. private $negativeExcessEffects;
  85. /**
  86. * @var string
  87. */
  88. private $parameterDescription;
  89. /**
  90. * @var array
  91. */
  92. private $relevantQualities;
  93. /**
  94. * @var string
  95. */
  96. private $notes;
  97. /**
  98. * @var \DateTime
  99. */
  100. private $createdAt;
  101. public function __construct(
  102. string $analyticalParameterId = null,
  103. string $parameterCode,
  104. string $parameterName,
  105. string $parameterMetric,
  106. float $referenceMinValue = null,
  107. float $referenceValue = null,
  108. float $referenceMaxValue = null,
  109. float $limitMinValue = null,
  110. float $limitMaxValue = null
  111. ) {
  112. try {
  113. $this->uuid = Uuid::fromString($analyticalParameterId ?: Uuid::uuid4())->toString();
  114. } catch (\InvalidArgumentException $e) {
  115. throw new InvalidUUIDException();
  116. }
  117. $this->parameterCode = $parameterCode;
  118. $this->parameterName = $parameterName;
  119. $this->parameterMetric = $parameterMetric;
  120. $this->referenceMinValue = $referenceMinValue;
  121. $this->referenceValue = $referenceValue;
  122. $this->referenceMaxValue = $referenceMaxValue;
  123. $this->limitMinValue = $limitMinValue;
  124. $this->limitMaxValue = $limitMaxValue;
  125. $this->relevantQualities = [];
  126. $this->createdAt = new \DateTime();
  127. }
  128. public function updateAnalyticalParameter(
  129. string $parameterName,
  130. string $parameterMetric,
  131. float $referenceMinValue = null,
  132. float $referenceValue = null,
  133. float $referenceMaxValue = null,
  134. float $limitMinValue = null,
  135. float $limitMaxValue = null
  136. ) {
  137. $this->parameterName = $parameterName;
  138. $this->parameterMetric = $parameterMetric;
  139. $this->referenceMinValue = $referenceMinValue;
  140. $this->referenceValue = $referenceValue;
  141. $this->referenceMaxValue = $referenceMaxValue;
  142. $this->limitMinValue = $limitMinValue;
  143. $this->limitMaxValue = $limitMaxValue;
  144. }
  145. public function updateAnalyticalParameterDescriptions(
  146. string $positivePresenceEffects = null,
  147. string $negativePresenceEffects = null,
  148. string $negativeAbsenceEffects = null,
  149. string $negativeExcessEffects = null,
  150. string $parameterDescription = null,
  151. string $notes = null
  152. ) {
  153. $this->positivePresenceEffects = $positivePresenceEffects;
  154. $this->negativePresenceEffects = $negativePresenceEffects;
  155. $this->negativeAbsenceEffects = $negativeAbsenceEffects;
  156. $this->negativeExcessEffects = $negativeExcessEffects;
  157. $this->parameterDescription = $parameterDescription;
  158. $this->notes = $notes;
  159. }
  160. public function addRelevantQuality(string $relevantQuality): void
  161. {
  162. switch ($relevantQuality) {
  163. case self::QUALITY_IMPROVE_PERCEPTION:
  164. case self::QUALITY_BIOLOGICAL_CONTAMINATION:
  165. case self::QUALITY_PESTICIDES:
  166. case self::QUALITY_MEDICINES:
  167. case self::QUALITY_PFA:
  168. case self::QUALITY_OXIDANTS:
  169. case self::QUALITY_BYPRODUCTS:
  170. case self::QUALITY_HYDROCARBONS:
  171. case self::QUALITY_SYNTHETIC_CHEMICALS:
  172. case self::QUALITY_ORGANIC:
  173. case self::QUALITY_RADIOACTIVITY:
  174. case self::QUALITY_METALS:
  175. case self::QUALITY_SALTS:
  176. case self::QUALITY_NITRATES_SULFATES_PHOSPHATES:
  177. case self::QUALITY_MINERALIZATION:
  178. case self::QUALITY_IRON_MANGANESE:
  179. if (!in_array($relevantQuality, $this->relevantQualities, true)) {
  180. $this->relevantQualities[] = $relevantQuality;
  181. }
  182. break;
  183. default:
  184. throw new InvalidArgumentException("Invalid quality: $relevantQuality");
  185. }
  186. }
  187. public function removeRelevantQuality(string $relevantQuality): void
  188. {
  189. $this->relevantQualities = array_filter(
  190. $this->relevantQualities,
  191. fn($quality) => $quality !== $relevantQuality
  192. );
  193. // Reindex the array to maintain numerical keys
  194. $this->relevantQualities = array_values($this->relevantQualities);
  195. }
  196. public function cleanRelevantQuality(): void
  197. {
  198. $this->relevantQualities = [];
  199. }
  200. public function editNotes(string $notes = null): string
  201. {
  202. $this->notes = $notes;
  203. return $this->notes;
  204. }
  205. public function editDescription(string $parameterDescription = null): string
  206. {
  207. $this->parameterDescription = $parameterDescription;
  208. return $this->parameterDescription;
  209. }
  210. /**
  211. * @return string
  212. */
  213. public function id(): string
  214. {
  215. return $this->uuid;
  216. }
  217. /**
  218. * @return string
  219. */
  220. public function parameterCode(): string
  221. {
  222. return $this->parameterCode;
  223. }
  224. /**
  225. * @return string
  226. */
  227. public function parameterName(): string
  228. {
  229. return $this->parameterName;
  230. }
  231. /**
  232. * @return string
  233. */
  234. public function parameterMetric(): string
  235. {
  236. return $this->parameterMetric;
  237. }
  238. /**
  239. * @return float
  240. */
  241. public function referenceMinValue(): ?float
  242. {
  243. return $this->referenceMinValue;
  244. }
  245. /**
  246. * @return float
  247. */
  248. public function referenceValue(): ?float
  249. {
  250. return $this->referenceValue;
  251. }
  252. /**
  253. * @return float
  254. */
  255. public function referenceMaxValue(): ?float
  256. {
  257. return $this->referenceMaxValue;
  258. }
  259. /**
  260. * @return float
  261. */
  262. public function limitMinValue(): ?float
  263. {
  264. return $this->limitMinValue;
  265. }
  266. /**
  267. * @return float
  268. */
  269. public function limitMaxValue(): ?float
  270. {
  271. return $this->limitMaxValue;
  272. }
  273. /**
  274. * @return array
  275. */
  276. public function relevantQualities(): ?array
  277. {
  278. return $this->relevantQualities;
  279. }
  280. /**
  281. * @return string
  282. */
  283. public function positivePresenceEffects(): ?string
  284. {
  285. return $this->positivePresenceEffects;
  286. }
  287. /**
  288. * @return string
  289. */
  290. public function negativePresenceEffects(): ?string
  291. {
  292. return $this->negativePresenceEffects;
  293. }
  294. /**
  295. * @return string
  296. */
  297. public function negativeAbsenceEffects(): ?string
  298. {
  299. return $this->negativeAbsenceEffects;
  300. }
  301. /**
  302. * @return string
  303. */
  304. public function negativeExcessEffects(): ?string
  305. {
  306. return $this->negativeExcessEffects;
  307. }
  308. /**
  309. * @return string
  310. */
  311. public function parameterDescription(): ?string
  312. {
  313. return $this->parameterDescription;
  314. }
  315. /**
  316. * @return string
  317. */
  318. public function notes(): ?string
  319. {
  320. return $this->notes;
  321. }
  322. /**
  323. * @return \DateTime
  324. */
  325. public function createdAt(): \DateTime
  326. {
  327. return $this->createdAt;
  328. }
  329. /**
  330. * @return bool
  331. */
  332. public function equals(AnalyticalParameter $analyticalParameter)
  333. {
  334. return $this->id() === $analyticalParameter->id();
  335. }
  336. }