-
Notifications
You must be signed in to change notification settings - Fork 2
/
send-record.php
63 lines (55 loc) · 1.65 KB
/
send-record.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
<?php namespace Vanderbilt\FHIRServicesExternalModule;
$projectId = $module->getProjectId();
$recordId = $module->getRecordId();
if($module->getProjectType() === 'composition'){
$resource = $module->buildBundle($projectId, $recordId);
}
else if($module->getProjectType() === 'questionnaire'){
$resource = $module->getFHIRResourceForRecord($projectId, $recordId);
}
else{
$resource = $module->getMappedFieldsAsBundle($projectId, $recordId);
}
$resource = $module->toArray($resource);
// Remove the ID since it is not allowed because it will be different on the remote system.
// The 'identifier' will still contain the id from this system.
unset($resource['id']);
$action = @$_GET['action'];
if($action === 'view'){
header('Content-type: application/json');
echo $module->jsonSerialize($resource);
return;
}
else if($action == 'validate'){
try{
$module->validateInBrowserAndDisplay($resource);
}
catch(\Throwable $t){
if($t instanceof StackFreeException){
die($t->getMessage());
}
else{
throw $t;
}
}
return;
}
header('Content-type: application/json');
try{
$response = $module->sendToRemoteFHIRServer($resource);
if(is_null($response)){
$remote_response = "";
} else {
$remote_response = $module->jsonSerialize($response);
}
echo json_encode([
'message' => 'The remote FHIR server has confirmed that the data has been successfully received.',
'remote-response' => $remote_response
]);
}
catch(\Throwable $t){
error_log($t->__toString());
echo json_encode([
'message' => $t->getMessage()
]);
}