forked from openemr/openemr
-
Notifications
You must be signed in to change notification settings - Fork 13
/
TransactionRestController.php
85 lines (69 loc) · 2.64 KB
/
TransactionRestController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* PatientRestController
* This controller creates, updates, and retrieves transactions
*
* @package OpenEMR
* @link http://www.open-emr.org
* @author Jonathan Moore <[email protected]>
* @copyright Copyright (c) 2022 Jonathan Moore <[email protected]>
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
*/
namespace OpenEMR\RestControllers;
use OpenEMR\RestControllers\RestControllerHelper;
use OpenEMR\Services\PatientTransactionService;
use OpenEMR\Services\TransactionService;
use OpenEMR\Validators\ProcessingResult;
class TransactionRestController
{
/**
* @var PatientTransactionService
*/
private $patientTransactionService;
/**
* White list of patient search fields
*/
private const SUPPORTED_SEARCH_FIELDS = array(
'pid'
);
public function __construct()
{
$this->patientTransactionService = new PatientTransactionService();
}
/**
* Process a HTTP POST request used to create a patient record.
*
* @param $data - array of patient fields.
* @return a 201/Created status code and the patient identifier if successful.
*/
public function CreateTransaction($pid, $data)
{
$processingResult = new ProcessingResult();
$serviceValidation = $this->patientTransactionService->validate($data);
$controllerValidationResult = RestControllerHelper::validationHandler($serviceValidation);
if (is_array($controllerValidationResult)) {
$processingResult->setValidationMessages($controllerValidationResult);
}
$serviceResult = $this->patientTransactionService->insert($pid, $data);
$processingResult->addData($serviceResult);
return RestControllerHelper::handleProcessingResult($processingResult, 201, true);
}
public function UpdateTransaction($tid, $data)
{
$processingResult = new ProcessingResult();
$data = $this->patientTransactionService->update($tid, $data);
$processingResult->addData($data);
return RestControllerHelper::handleProcessingResult($processingResult, 200, false);
}
/**
* Returns patient resources which match an optional search criteria.
*/
public function GetPatientTransactions($pid)
{
$processingResult = $this->patientTransactionService->getAll($pid);
if (!$processingResult->hasErrors() && count($processingResult->getData()) == 0) {
return RestControllerHelper::handleProcessingResult($processingResult, 404);
}
return RestControllerHelper::handleProcessingResult($processingResult, 200, true);
}
}