ApiController::actionSearch PHP Method

actionSearch() public method

Search for resource(s).
public actionSearch ( $resource_type )
$resource_type
    public function actionSearch($resource_type)
    {
        $params = $_REQUEST;
        unset($params['id']);
        // Can't send a service layer ID directly
        // We keep track of the search params that were actually used in order to create a self URL for the bundle (http://www.hl7.org/implement/standards/fhir/search.html#conformance)
        $used_params = array('resource_type' => $resource_type);
        foreach (array('_count', '_format', '_id', '_profile') as $param) {
            if (isset($params[$param])) {
                $used_params[$param] = $params[$param];
            }
        }
        $service = $this->getSearchService($resource_type, $params);
        if ($service) {
            $params = array_intersect_key($params, $service->getSupportedSearchParams());
            $used_params += $params;
            unset($used_params['id']);
            $resources = $service->search($params);
            if (isset($_REQUEST['_count'])) {
                $resources = array_slice($resources, 0, $_REQUEST['_count']);
            }
        } else {
            $resources = array();
        }
        $self_url = $this->createAbsoluteUrl('api/search', $used_params);
        $base_url = $this->createAbsoluteUrl('api/');
        $indexed_resources = array();
        foreach ($resources as $resource) {
            $url = $base_url . '/' . Yii::app()->service->serviceAndIdToFhirUrl($service->getServiceName(), $resource->getId());
            $indexed_resources[$url] = $resource;
        }
        $bundle = services\FhirBundle::create('Search results', $self_url, $base_url, $indexed_resources);
        $this->sendBundle($bundle);
    }