6 * @link http://www.open-emr.org
7 * @author Stephen Nielson <stephen@nielson.org>
8 * @copyright Copyright (c) 2021 Stephen Nielson <stephen@nielson.org>
9 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 * @link http://www.open-emr.org
16 * @author Stephen Nielson <stephen@nielson.org>
17 * @copyright Copyright (c) 2021 Stephen Nielson <stephen@nielson.org>
18 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
21 namespace OpenEMR\Tests\Unit\Common\Forms
;
23 use OpenEMR\Common\Database\QueryUtils
;
24 use OpenEMR\Common\Forms\FormVitalDetails
;
25 use OpenEMR\Common\Forms\FormVitals
;
26 use OpenEMR\Services\ListService
;
27 use PHPUnit\Framework\TestCase
;
29 class FormVitalsTest
extends TestCase
31 const NOTE_UNIT_TEST
= "OEUnitTest";
32 const VITAL_DETAILS_COLUMN
= "bps";
34 protected function tearDown(): void
36 QueryUtils
::sqlStatementThrowException("DELETE FROM " . FormVitalDetails
::TABLE_NAME
37 . " WHERE form_id IN (select id FROM " . FormVitals
::TABLE_NAME
. " WHERE note=?)", [self
::NOTE_UNIT_TEST
]);
38 QueryUtils
::sqlStatementThrowException("DELETE FROM " . FormVitals
::TABLE_NAME
. " WHERE note=?", [self
::NOTE_UNIT_TEST
]);
41 public function test__construct()
43 // make sure we can construct the object and there are no errors
44 $formVitals = new FormVitals();
45 $this->assertNotEmpty($formVitals->get_date(), "Date should be populated");
46 $this->assertIsArray($formVitals->get_vital_details(), "Vital details should be array");
49 public function test_set_details_for_column()
51 $details = new FormVitalDetails();
52 $formVitals = new FormVitals();
54 // verify column get / set are being done correctly.
55 $formVitals->set_details_for_column(self
::VITAL_DETAILS_COLUMN
, $details);
56 $this->assertEquals($details, $formVitals->get_details_for_column(self
::VITAL_DETAILS_COLUMN
));
59 public function test_persist()
61 $formVitals = new FormVitals();
62 $formVitals->note
= self
::NOTE_UNIT_TEST
;
63 $formVitals->persist();
65 $this->assertNotNull($formVitals->get_id(), "Form vitals id should be populated");
67 $records = $this->getVitalFormRecords($formVitals->get_id());
68 $this->assertNotEmpty($records, "Vital records should have been found");
71 public function test_persist_vitals_with_details()
73 $formVitals = new FormVitals();
74 $formVitals->note
= self
::NOTE_UNIT_TEST
;
76 $details = new FormVitalDetails();
77 $details->set_vitals_column(self
::VITAL_DETAILS_COLUMN
);
78 $formVitals->set_details_for_column($details->get_vitals_column(), $details);
79 $formVitals->persist();
81 $this->assertNotNull($formVitals->get_id(), "Form vitals id should be populated");
82 $vitalRecords = $this->getVitalFormRecords($formVitals->get_id());
83 $this->assertNotEmpty($vitalRecords, "Vital records should have been found");
85 $this->assertNotNull($details->get_id(), "Form vital details id should be populated");
86 $this->assertNotNull($details->get_form_id(), "Form vital details form id should be populated");
88 $records = QueryUtils
::fetchRecords("SELECT * FROM " . FormVitalDetails
::TABLE_NAME
. " WHERE id=?", [$details->get_id()]);
89 $this->assertNotEmpty($records, "Vital detail records should have been found");
91 $tableDetails = $records[0];
92 $this->assertEquals($formVitals->get_id(), $tableDetails['form_id'], "Form id should match with vitals form id");
93 $this->assertEquals(self
::VITAL_DETAILS_COLUMN
, $tableDetails['vitals_column'], "Vital detail column should have been persisted");
96 public function test_persist_vitals_with_details_interpretation()
98 $formVitals = new FormVitals();
99 $formVitals->note
= self
::NOTE_UNIT_TEST
;
101 $listService = new ListService();
102 $options = $listService->getOptionsByListName(FormVitals
::LIST_OPTION_VITALS_INTERPRETATION
);
103 $this->assertNotEmpty($options, "Vital options should be populated");
105 $details = new FormVitalDetails();
106 $details->set_vitals_column(self
::VITAL_DETAILS_COLUMN
);
107 $details->set_interpretation_option_id($options[0]['option_id']);
108 $details->set_interpretation_list_id(FormVitals
::LIST_OPTION_VITALS_INTERPRETATION
);
109 $details->set_interpretation_title($options[0]['title']);
110 $details->set_interpretation_codes($options[0]['codes']);
111 $formVitals->set_details_for_column($details->get_vitals_column(), $details);
112 $formVitals->persist();
114 $this->assertNotNull($formVitals->get_id(), "Form vitals id should be populated");
115 $vitalRecords = $this->getVitalFormRecords($formVitals->get_id());
116 $this->assertNotEmpty($vitalRecords, "Vital records should have been found");
118 $this->assertNotNull($details->get_id(), "Form vital details id should be populated");
119 $this->assertNotNull($details->get_form_id(), "Form vital details form id should be populated");
121 $records = QueryUtils
::fetchRecords("SELECT * FROM " . FormVitalDetails
::TABLE_NAME
. " WHERE id=?", [$details->get_id()]);
122 $this->assertNotEmpty($records, "Vital detail records should have been found");
124 $tableDetails = $records[0];
125 $this->assertEquals($formVitals->get_id(), $tableDetails['form_id'], "Form id should match with vitals form id");
126 $this->assertEquals($details->get_interpretation_list_id(), $tableDetails['interpretation_list_id'], "details object should match with form_vital_details column");
127 $this->assertEquals($details->get_interpretation_option_id(), $tableDetails['interpretation_option_id'], "details object should match with form_vital_details column");
128 $this->assertEquals($details->get_interpretation_title(), $tableDetails['interpretation_title'], "details object should match with form_vital_details column");
129 $this->assertEquals($details->get_interpretation_codes(), $tableDetails['interpretation_codes'], "details object should match with form_vital_details column");
131 $this->assertEquals(self
::VITAL_DETAILS_COLUMN
, $tableDetails['vitals_column'], "Vital detail column should have been persisted");
134 public function test_populate_array()
138 ,"uuid" => 0x33333333333333
143 ,'interpretation_codes' => 'A'
144 ,'interpretation_title' => 'Abnormal'
145 ,'vitals_column' => 'pulse'
150 $vitals = new FormVitals();
151 $vitals->populate_array($vitalsArray);
152 foreach ($vitalsArray as $key => $value) {
153 if ($key == 'details') {
156 $function = "get_" . $key;
157 $this->assertEquals($vitals->$function(), $value, FormVitals
::class . " property '" . $key
158 . "' should have been populated with array value " . $value);
161 $details = $vitals->get_details_for_column('pulse');
162 $this->assertNotEmpty($details, "Details column for pulse should have been populated");
164 foreach ($vitalsArray['details']['pulse'] as $key => $value) {
165 $function = "get_" . $key;
166 $this->assertEquals($details->$function(), $value, FormVitalDetails
::class . " property '" . $key
167 . "' should have been populated with array value " . $value);
171 private function getVitalFormRecords($form_id)
173 return QueryUtils
::fetchRecords("SELECT * FROM " . FormVitals
::TABLE_NAME
. " WHERE id=?", [$form_id]);