fix: quick fix to enforce support of x509 database connection on install (#6157)
[openemr.git] / src / Validators / ConditionValidator.php
blob56a2ab638cacb3ec5f72c026a5b05a1d86c3829d
1 <?php
3 namespace OpenEMR\Validators;
5 use Particle\Validator\Validator;
7 /**
8 * Supports AllergyIntolerance Record Validation.
10 * @package OpenEMR
11 * @link http://www.open-emr.org
12 * @author Yash Bothra <yashrajbothra786@gmail.com>
13 * @copyright Copyright (c) 2020 Yash Bothra <yashrajbothra786@gmail.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
16 class ConditionValidator extends BaseValidator
18 /**
19 * Configures validations for the AllergyIntolerance DB Insert and Update use-case.
20 * The update use-case is comprised of the same fields as the insert use-case.
21 * The update use-case differs from the insert use-case in that fields other than uuid are not required.
23 protected function configureValidator()
25 parent::configureValidator();
27 // insert validations
28 $this->validator->context(
29 self::DATABASE_INSERT_CONTEXT,
30 function (Validator $context) {
31 $context->required('title')->lengthBetween(2, 255);
32 $context->required('begdate')->datetime('Y-m-d');
33 $context->optional('diagnosis')->lengthBetween(2, 255);
34 $context->optional('enddate')->datetime('Y-m-d');
35 $context->required("puuid", "Patient UUID")->callback(
36 function ($value) {
37 return $this->validateId("uuid", "patient_data", $value, true);
43 // update validations copied from insert
44 $this->validator->context(
45 self::DATABASE_UPDATE_CONTEXT,
46 function (Validator $context) {
47 $context->copyContext(
48 self::DATABASE_INSERT_CONTEXT,
49 function ($rules) {
50 foreach ($rules as $key => $chain) {
51 $chain->required(false);
55 // additional muuid validation
56 $context->required("uuid", "Condition UUID")->callback(function ($value) {
57 return $this->validateId("uuid", "lists", $value, true);
58 })->uuid();