Exemplo n.º 1
0
        private async Task <Dictionary <uint, string> > GetActiveIngredients(uint drugId)
        {
            Core.Models.ApiRequestData requestData = new Core.Models.ApiRequestData();
            requestData.Key = apiKey;
            requestData.Lib = new List <ushort> {
                62
            };
            requestData.Binarization = 0;
            requestData.Level        = new List <ushort> {
                1600
            };
            requestData.Route    = 2;
            requestData.Deepness = 1;
            requestData.LibId    = new List <string> {
                drugId.ToString()
            };
            requestData.Valmore = false;

            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(requestData));

            HttpContent content = new StringContent(stringPayload, Encoding.UTF8, "application/json");

            var resp = await httpClient.PostAsync("https://cs.socmedica.com/api/umkb/getsemantic", content);

            if (resp.Content == null)
            {
                return(null);
            }

            var responseContent = await resp.Content.ReadAsStringAsync();

            Core.Models.ApiResponseData responseData = JsonConvert.DeserializeObject <Core.Models.ApiResponseData>(responseContent);
            //get the trademark's node
            var tm = responseData.Graph.FirstOrDefault(x => x.IdA == 0 && x.IdB == 0);

            if (tm == null)
            {
                return(null);
            }
            //get active ingredients
            Dictionary <uint, string> ret = new Dictionary <uint, string>();

            responseData.Graph.ForEach(x =>
            {
                if (x.Level == 1600)
                {
                    if (x.IdA == drugId)
                    {
                        ret.Add(x.IdB, responseData.Names[x.IdB]);
                    }
                    if (x.IdB == drugId)
                    {
                        ret.Add(x.IdA, responseData.Names[x.IdA]);
                    }
                }
            });
            return(ret);
        }
Exemplo n.º 2
0
        private async Task <Dictionary <uint, string> > GetAnatomicalTherapeuticChemicalClassification(uint activeIngredientId)
        {
            Core.Models.ApiRequestData requestData = new Core.Models.ApiRequestData();
            requestData.Key = apiKey;
            requestData.Lib = new List <ushort> {
                62
            };
            requestData.Binarization = 0;
            requestData.Level        = new List <ushort> {
                1621
            };
            requestData.Route    = 0;
            requestData.Deepness = 1;
            requestData.LibId    = new List <string> {
                activeIngredientId.ToString()
            };
            requestData.Valmore = false;

            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(requestData));

            HttpContent content = new StringContent(stringPayload, Encoding.UTF8, "application/json");
            var         resp    = await httpClient.PostAsync("https://cs.socmedica.com/api/umkb/getsemantic", content);

            if (resp.Content == null)
            {
                return(null);
            }

            var responseContent = await resp.Content.ReadAsStringAsync();

            Core.Models.ApiResponseData responseData = JsonConvert.DeserializeObject <Core.Models.ApiResponseData>(responseContent);
            //get attached nodes' names
            Dictionary <uint, string> ret = new Dictionary <uint, string>();

            if (responseData.Graph == null)
            {
                return(null);
            }
            responseData.Graph.ForEach(x =>
            {
                if (x.Level == 1621)
                {
                    if (x.IdA == activeIngredientId && !ret.ContainsKey(x.IdB))
                    {
                        ret.Add(x.IdB, responseData.Names[x.IdB]);
                    }
                    if (x.IdB == activeIngredientId && !ret.ContainsKey(x.IdA))
                    {
                        ret.Add(x.IdA, responseData.Names[x.IdA]);
                    }
                }
            });
            return(ret);
        }
Exemplo n.º 3
0
        private async Task <(uint id, string name)?> GetDrugId(string drugName)
        {
            Core.Models.ApiRequestData requestData = new Core.Models.ApiRequestData();
            requestData.Key = apiKey;
            requestData.Lib = new List <ushort> {
                62
            };
            requestData.Binarization = 0;
            requestData.Level        = new List <ushort> {
                1600
            };
            requestData.Route    = 2;
            requestData.Deepness = 0;
            requestData.Text     = drugName;
            requestData.Valmore  = false;

            var stringPayload = await Task.Run(() => JsonConvert.SerializeObject(requestData));

            HttpContent content = new StringContent(stringPayload, Encoding.UTF8, "application/json");
            var         resp    = await httpClient.PostAsync("https://cs.socmedica.com/api/umkb/getsemantic", content);

            if (resp.Content == null)
            {
                return(null);
            }

            var responseContent = await resp.Content.ReadAsStringAsync();

            Core.Models.ApiResponseData responseData = JsonConvert.DeserializeObject <Core.Models.ApiResponseData>(responseContent);
            //get the trademark's node
            if (responseData.Graph == null)
            {
                return(null);
            }
            var tm = responseData.Graph.FirstOrDefault();

            if (tm == null)
            {
                return(null);
            }
            return(tm.Id, responseData.Names[tm.Id]);
        }