コード例 #1
0
        public static void Demo(string[] args)
        {
            Console.WriteLine("Searching begins...");

            // hcOS Document Api tenant configuration info
            Configuration configuration = JsonConvert.DeserializeObject <Configuration>(File.ReadAllText("../../configurations/Configuration.Searching.json"));

            Search[] searches = JArray.Parse(File.ReadAllText("../../data/Searches.json")).ToObject <Search[]>();

            IRestClient client = new RestClient(configuration.BaseUrl);

            client.Authenticator = new searching.Authenticator(configuration.AppId, configuration.AppSecret, configuration.TenantId);

            Results results = new Results();

            IRestRequest  request  = configuration.NewRequest($"/api/v1/{configuration.TenantId}/document/search", Method.POST);
            IRestResponse response = null;

            foreach (Search search in searches)
            {
                results.Total++;
                Console.WriteLine($"Begin: {search.Description}");
                Console.WriteLine(JsonConvert.SerializeObject(search.Query, Formatting.Indented));
                request.AddOrUpdateParameter("application/json", JsonConvert.SerializeObject(search.Query), ParameterType.RequestBody);
                response = client.Execute(request);
                if ((response.ResponseStatus == ResponseStatus.Completed) && (response.StatusCode == HttpStatusCode.OK))
                {
                    QueryResponse queryResponse = JsonConvert.DeserializeObject <QueryResponse>(response.Content);

                    Console.WriteLine($"searchResponse.Offset: {queryResponse.Offset}");
                    Console.WriteLine($"searchResponse.RecordCount: {queryResponse.RecordCount}");
                    Console.WriteLine($"searchResponse.TotalRecordCount: {queryResponse.TotalRecordCount}");
                    int count = 1;
                    foreach (DocumentEntry entry in queryResponse.Hits)
                    {
                        Console.WriteLine($"{count}) {entry.DocumentRoot}-{entry.DocumentExtension}-{entry.DocumentTypeExtension}");
                        count++;
                    }
                    results.Success++;
                }
                else
                {
                    results.Errors++;
                    Console.WriteLine($"OOPS something wrong.{System.Environment.NewLine}\tResponseStatus: {response.ResponseStatus}{System.Environment.NewLine}\tHttpStatusCode: {response.StatusCode}{System.Environment.NewLine}\tContent: {response.Content}");
                }
                Console.WriteLine($"Ends: {search.Description}{System.Environment.NewLine}");
            }
            Console.WriteLine(results.CurrentStats);
        }
コード例 #2
0
        public static void Demo(string[] args)
        {
            Console.WriteLine("hcOS demo begins...");

            // Making sure Directory Exist
            if (!Directory.Exists("data"))
            {
                Directory.CreateDirectory("data");
            }
            //Initializing Documents
            documents.Configuration documentsConfiguration = JsonConvert.DeserializeObject <documents.Configuration>(File.ReadAllText("../../configurations/Configuration.Documents.json"));
            IRestClient             documentsClient        = new RestClient(documentsConfiguration.BaseUrl);

            documentsClient.Authenticator = new documents.Authenticator(documentsConfiguration.AppId, documentsConfiguration.AppSecret, documentsConfiguration.TenantSecret);

            //Initializing Searcj
            searching.Configuration searchConfiguration = JsonConvert.DeserializeObject <searching.Configuration>(File.ReadAllText("../../configurations/Configuration.Searching.json"));
            IRestClient             iSearchClient       = new RestClient(searchConfiguration.BaseUrl);

            iSearchClient.Authenticator = new searching.Authenticator(searchConfiguration.AppId, searchConfiguration.AppSecret, searchConfiguration.TenantId);

            // Creating search Search request
            IRestRequest iSearchRequest = searchConfiguration.NewRequest($"/api/v1/{searchConfiguration.TenantId}/document/search", Method.POST);
            string       literals       = "ulcerative colitis";

            Console.WriteLine($"Searching for documents containing '{literals}'");
            iSearchRequest.AddJsonBody(new searching.Query()
            {
                Criterion = $"literal='{literals}'"
            });

            // Making Search Request
            IRestResponse iSearchResponse = iSearchClient.Execute(iSearchRequest);

            if ((iSearchResponse.StatusCode == System.Net.HttpStatusCode.OK) && (iSearchResponse.ResponseStatus == ResponseStatus.Completed))
            {
                searching.QueryResponse queryResponse = JsonConvert.DeserializeObject <searching.QueryResponse>(iSearchResponse.Content);
                Console.WriteLine($"searchResponse.Offset: {queryResponse.Offset}");
                Console.WriteLine($"searchResponse.RecordCount: {queryResponse.RecordCount}");
                Console.WriteLine($"searchResponse.TotalRecordCount: {queryResponse.TotalRecordCount}");
                int    count = 1;
                string outFileName;
                foreach (searching.DocumentEntry entry in queryResponse.Hits)
                {
                    Console.WriteLine($"{count}) {entry.DocumentRoot}-{entry.DocumentExtension}-{entry.DocumentTypeExtension}");
                    IRestRequest  documentsRequest  = documentsConfiguration.NewRequest($"/api/v1/patient_document/{entry.DocumentRoot}/{entry.DocumentExtension}/text", Method.GET);
                    IRestResponse documentsResponse = documentsClient.Execute(documentsRequest);
                    if ((documentsResponse.StatusCode == System.Net.HttpStatusCode.OK) && (documentsResponse.ResponseStatus == ResponseStatus.Completed))
                    {
                        outFileName = $"./data/{entry.DocumentRoot}.{entry.DocumentExtension}.txt";
                        File.WriteAllText(outFileName, documentsResponse.Content);
                        Console.WriteLine($"Saved to {outFileName}");
                    }
                    else
                    {
                        Console.WriteLine($"documentsResponse.StatusCode: {documentsResponse.StatusCode}");
                        Console.WriteLine($"documentsResponse.ResponseStatus: {documentsResponse.ResponseStatus}");
                        Console.WriteLine($"documentsResponse.Content:{System.Environment.NewLine}{documentsResponse.Content}");
                        Console.WriteLine($"Halting...");
                        return;
                    }
                    count++;
                }
            }
            else
            {
                Console.WriteLine($"searchResponse.StatusCode: {iSearchResponse.StatusCode}");
                Console.WriteLine($"searchResponse.ResponseStatus: {iSearchResponse.ResponseStatus}");
                Console.WriteLine($"searchResponse.Content:{System.Environment.NewLine}{iSearchResponse.Content}");
                Console.WriteLine($"Halting...");
                return;
            }
            Console.WriteLine("hcOS demo ends...");
        }