CCDA server fixups (#4356)
[openemr.git] / src / Validators / EncounterValidator.php
blob262fbe9e7fe4786d3524ab998a61b5788a43a612
1 <?php
3 namespace OpenEMR\Validators;
5 use Particle\Validator\Validator;
6 use Particle\Validator\Exception\InvalidValueException;
8 /**
9 * Supports Encounter Record Validation.
11 class EncounterValidator extends BaseValidator
14 /**
15 * Configures validations for the Encounter DB Insert and Update use-case.
16 * The update use-case is comprised of the same fields as the insert use-case.
17 * The update use-case differs from the insert use-case in that fields other than pid are not required.
19 protected function configureValidator()
21 parent::configureValidator();
23 // insert validations
24 $this->validator->context(
25 self::DATABASE_INSERT_CONTEXT,
26 function (Validator $context) {
27 $context->required('pc_catid');
28 $context->required('class_code')->callback(
29 function ($value) {
30 return $this->validateCode($value, "list_options", "_ActEncounterCode");
33 $context->required("puuid", "Patient UUID")->callback(
34 function ($value) {
35 return $this->validateId('uuid', "patient_data", $value, true);
37 )->uuid();
41 // update validations copied from insert
42 $this->validator->context(
43 self::DATABASE_UPDATE_CONTEXT,
44 function (Validator $context) {
45 $context->copyContext(
46 self::DATABASE_INSERT_CONTEXT,
47 function ($rules) {
48 foreach ($rules as $key => $chain) {
49 $chain->required(false);
53 // additional euuid validation
54 $context->required("euuid", "Encounter UUID")->callback(function ($value) {
55 return $this->validateId("uuid", "form_encounter", $value, true);
56 })->uuid();
57 // additional puuid validation
58 $context->required("puuid", "Patient UUID")->callback(function ($value) {
59 return $this->validateId('uuid', "patient_data", $value, true);
60 })->uuid();
61 $context->optional('class_code')->callback(
62 function ($value) {
63 return $this->validateCode($value, "list_options", "_ActEncounterCode");