public async Task <ClinicalTrialResult <ClinicalTrial> > GetClinicalTrials(ClinicalTrialFilter filter)
        {
            GraphQLRequest graphQLRequest = GetGraphQLRequest(GetQueryForClinicalTrial(filter));
            var            result         = await _Client.PostAsync(graphQLRequest);

            ClinicalTrialResult <ClinicalTrial> clinicalTrialResult = GetClinicalTrialResultInstance(result);

            MapResultToClinicalTrialObject(result, clinicalTrialResult);

            return(clinicalTrialResult);
        }
        public string GetQueryForClinicalTrial(ClinicalTrialFilter filter)
        {
            string query = GetQuery(TrialObject, DefaultTrialProperties, false, filter.first, filter.after);

            if (filter.Conditions != null && filter.Conditions.Any())
            {
                bool   hasPagination = filter.first > 0 || !string.IsNullOrEmpty(filter.after);
                string conditions    = string.Join(",", filter.Conditions);
                string endOfLine     = hasPagination ? "," : ")";
                string baseFilters   = null;
                if (filter.Longitude != null)
                {
                    string latitude    = AddFilterToBase("", "latitude", filter.Latitude.ToString(), true);
                    string longitude   = AddFilterToBase("", "latitude", filter.Latitude.ToString(), true);
                    string coordinates = " coordinates: {" + latitude + ", " + longitude + "}";
                    baseFilters = coordinates;
                }
                baseFilters = AddFilterToBase(baseFilters, "studyType", filter.StudyType, true);
                baseFilters = AddFilterToBase(baseFilters, "zipCode", filter.ZipCode);
                baseFilters = AddFilterToBase(baseFilters, "phase", filter.Phase, true);

                if (filter.FromAge > 0)
                {
                    if (filter.ToAge > 0)
                    {
                        baseFilters = AddFilterToBase(baseFilters, "age", filter.FromAge.ToString() + ":" + filter.ToAge.ToString());
                    }
                    else
                    {
                        baseFilters = AddFilterToBase(baseFilters, "age", filter.FromAge.ToString(), true);
                    }
                }

                baseFilters = AddFilterToBase(baseFilters, "gender", filter.Gender, true);
                baseFilters = AddFilterToBase(baseFilters, "travelRadius", filter.TravelRadius > 0 ? filter.TravelRadius.ToString() : "", true);
                string baseMatches = "baseMatches(conditions: [" + conditions + "], baseFilters: { " + baseFilters + " }" + endOfLine + "";
                string startOfLine = hasPagination ? "(" : "";
                query = query.Replace(TrialObject + startOfLine, baseMatches);
            }
            return(query);
        }