コード例 #1
0
        /// <summary>
        /// Retrieves a list of patients. The endpoint implements pagination by using links. Additionally, it is possible to filter by parameters such as lastName, firstName, createdAfter, updatedAfter or to sort ascending or descending.
        /// </summary>
        /// <exception cref="CNXT.Connector.Client.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="first">Fetch only the first certain number of patients of the set. The default and maximum value is set to 25 patients per request.</param>
        /// <param name="after">Fetch only patients in the set after (below) this cursor (exclusive). (optional)</param>
        /// <param name="filter">Filter patients by parameters e.g. lastName for filtering patients by their last name.  (Supported values: firstName, lastName, search, dateOfBirth, createdAfter, updatedAfter) (optional)</param>
        /// <param name="sort">List of parameters to sort patients by parameters.  (Supported values: lastName, firstName, latestSessionUpdate, createdAt, updatedAt).    To sort descending add a &#39;-&#39; as prefix e.g (-lastName, -firstName, -latestSessionUpdate, -createdAt, -updatedAt). (optional)</param>
        /// <param name="include">List of related resources for including relationships or properties directly into patient such as Session, latestSessionId, or latestSessionUpdate   (Supported values: session, latestSessionId, latestSessionUpdate) (optional)</param>
        /// <returns>ApiResponse of PatientsResponse</returns>
        public ApiResponse <PatientsResponse> GetPatientsWithHttpInfo(int first, string after = default(string), PatientFilter filter = default(PatientFilter), List <string> sort = default(List <string>), List <string> include = default(List <string>))
        {
            // verify the required parameter 'first' is set
            if (first == null)
            {
                throw new ApiException(400, "Missing required parameter 'first' when calling PatientsApi->GetPatients");
            }

            var    localVarPath         = "/patients";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
            };
            String localVarHttpContentType    = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (first != null)
            {
                localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("", "first", first));                // query parameter
            }
            if (after != null)
            {
                localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("", "after", after));                // query parameter
            }
            // TODO: Bugfix for supporting deepObjects as query parameters
            //if (filter != null) localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("", "filter", filter)); // query parameter
            if (filter != null)
            {
                foreach (PropertyInfo propertyInfo in filter.GetType().GetProperties().Where(property => property.GetValue(filter, null) != null))
                {
                    if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?))
                    {
                        DateTime?dateTimeValue = propertyInfo.GetValue(filter, null) as DateTime?;

                        if (dateTimeValue.HasValue)
                        {
                            localVarQueryParams.Add(new KeyValuePair <string, string>(string.Format("filter[{0}]", char.ToLower(propertyInfo.Name[0]) + propertyInfo.Name.Substring(1)), dateTimeValue.Value.ToString("s")));
                        }
                    }
                    else
                    {
                        localVarQueryParams.Add(new KeyValuePair <string, string>(string.Format("filter[{0}]", char.ToLower(propertyInfo.Name[0]) + propertyInfo.Name.Substring(1)), propertyInfo.GetValue(filter, null).ToString()));
                    }
                }
            }

            if (sort != null)
            {
                localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("csv", "sort", sort));               // query parameter
            }
            if (include != null)
            {
                localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("csv", "include", include));                  // query parameter
            }
            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)this.Configuration.ApiClient.CallApi(localVarPath,
                                                                                                 Method.GET, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                 localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("GetPatients", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <PatientsResponse>(localVarStatusCode,
                                                      localVarResponse.Headers.ToDictionary(x => x.Name, x => string.Join(",", x.Value)),
                                                      (PatientsResponse)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(PatientsResponse))));
        }