public function actionUpdate($resource_type, $id)
{
try {
$ref = $this->getRef($resource_type, $id);
$vid = $ref->getVersionId();
$vurl = $this->createAbsoluteUrl('api/') . '/' . Yii::app()->service->referenceToFhirUrl($ref) . "/_history/{$vid}";
if (isset($_SERVER['HTTP_CONTENT_LOCATION']) && $_SERVER['HTTP_CONTENT_LOCATION'] != $vurl) {
$this->sendResponse(409);
}
if (isset($_SERVER['HTTP_IF_MATCH'])) {
$match = false;
foreach (str_getcsv($_SERVER['HTTP_IF_MATCH']) as $tag) {
if ($tag == $vid || $tag == '*') {
$match = true;
break;
}
}
if (!$match) {
$this->sendResponse(412);
}
}
if (isset($_SERVER['HTTP_IF_UNMODIFIED_SINCE'])) {
$since = strtotime($_SERVER['HTTP_IF_UNMODIFIED_SINCE']);
if ($since === false) {
$this->sendError("Failed to parse If-Unmodified-Since header: {$_SERVER['HTTP_IF_UNMODIFIED_SINCE']}");
}
if ($ref->getLastModified() > $since) {
$this->sendResponse(412);
}
}
$input = $this->parseInput();
$tx = Yii::app()->db->beginTransaction();
$ref->fhirUpdate($input);
$tx->commit();
} catch (\services\NotFound $e) {
$this->sendError("Client defined IDs are not supported ({$e->getMessage()})", 405);
}
header("Location: {$vurl}");
header("Content-Location: {$vurl}");
header('Last-modified: ' . date(DATE_RFC1123, $ref->getLastModified()));
header("ETag: \"{$vid}\"");
$this->sendInfo("Resource {$resource_type}/{$id} successfully updated");
}