public function getFhirService($fhir_type, array $profiles)
{
$candidates = array_filter($this->service_config, function ($config) use($fhir_type) {
return $config['fhir_type'] == $fhir_type;
});
if (!$candidates) {
throw new NotFound("Unsupported resource type: '{$fhir_type}'");
}
// Unambiguous resource type
if (count($candidates) == 1) {
list($name, $config) = each($candidates);
if (!$config['fhir_prefix']) {
return $this->{$name};
}
}
if (!$profiles) {
throw new ProcessingNotSupported("A profile must be specified for resources of type '{$fhir_type}'");
}
foreach ($candidates as $name => $config) {
$resource_class = $config['resource_class'];
if (in_array($resource_class::getOeFhirProfile(), $profiles)) {
return $this->{$name};
}
}
// Profile(s) supplied but no match, not necessarily an error
return;
}