コード例 #1
0
        public JsonResult GetDrugList()
        {
            var context = new ScriptCycleContext();
            var repo    = new DrugRepo(context);
            var drugs   = repo.GetDrugNames();

            return(Json(drugs, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public void RetrieveRawGPI_Test()
        {
            var ctx     = new ScriptCycleContext();
            var repo    = new DrugRepo(ctx);
            var results = repo.GetGPI();

            Assert.IsTrue(results.Count > 0);
            Console.WriteLine("GPI Result count: " + results.Count);
        }
コード例 #3
0
        public JsonResult FindDrugsByName(string drugId)
        {
            var context = new ScriptCycleContext();
            var repo    = new DrugRepo(context);
            var results = repo.FindByName(drugId);

            var vm = new DrugSelectionViewModel();

            vm.MapResultsToViewModel(results, drugId);
            var dto = new DrugSearchResultDto {
                DisplayName   = vm.DisplayAs,
                DosageOptions = vm.DosageOptions,
                GPIs          = vm.GPIs,
                NDCs          = vm.NDCs,
                SearchResults = results,
                Strengths     = vm.Strengths
            };

            return(Json(dto));
        }
コード例 #4
0
        public void MapResultsToViewModel(List <DrugSearchResult> results, string drugId)
        {
            this.SearchResults = results;
            if (results.Count > 0)
            {
                var uniqueDoages    = results.GroupBy(d => d.dosage_form).Select(d => d.First()).ToList();
                var uniqueStrengths = results.GroupBy(d => d.strength).Select(d => d.First()).ToList();
                var resultGPIs      = new List <GPIDto>();

                results.ForEach(r => {
                    var hasNDC = this.NDCs.FirstOrDefault(n => n.NDC == r.ndc_upc_hri);
                    if (hasNDC == null)
                    {
                        this.NDCs.Add(
                            new NDCDto {
                            DisplayName     = string.Format("{0} {1} {2}{3}", r.drug_name, r.dosage_form, r.strength, r.strength_unit_of_measure),
                            MaintenanceCode = GetMaintenanceCode(r.maintenance_drug_code),
                            MONY            = r.multi_source_code,
                            NDC             = r.ndc_upc_hri
                        });
                    }
                    var gpiExists = resultGPIs.FirstOrDefault(n => n.GPI == r.generic_product_identifier);
                    if (gpiExists == null)
                    {
                        resultGPIs.Add(new GPIDto {
                            DisplayName = r.DisplayName, GPI = r.generic_product_identifier
                        });
                    }

                    var exists = this.DosageOptions.FirstOrDefault(n => n == r.dosage_form);
                    if (string.IsNullOrEmpty(exists))
                    {
                        this.DosageOptions.Add(r.dosage_form);
                    }

                    exists = this.Strengths.FirstOrDefault(n => n == r.strength + r.strength_unit_of_measure);
                    if (string.IsNullOrEmpty(exists))
                    {
                        if (!string.IsNullOrEmpty(r.strength))
                        {
                            this.Strengths.Add(r.strength + r.strength_unit_of_measure);
                        }
                    }
                });
                resultGPIs = resultGPIs.OrderBy(c => c.GPI).ToList();
                int length      = drugId.Length;
                var partialGPIs = new List <string>();

                // make sure we have a proper partial GPI
                if (length % 2 == 0 && length < 13)
                {
                    for (int i = drugId.Length; i < 13; i = i + 2)
                    {
                        partialGPIs.AddRange(GeneratePartialGPIs(results, i));
                    }
                }
                var sctx = new ScriptCycleContext();
                var repo = new DrugRepo(sctx);

                var namedPartials = repo.GetPartialGPINames(partialGPIs);
                this.GPIs.AddRange(namedPartials);
                this.GPIs.AddRange(resultGPIs);

                var selectedGPI = this.GPIs.SingleOrDefault(g => g.GPI == drugId);
                if (selectedGPI != null)
                {
                    this.DisplayAs = selectedGPI.DisplayName;
                    this.GPIs.Remove(selectedGPI);
                }
                else
                {
                    this.DisplayAs = results[0].DisplayName;
                }
                this.Strengths.Sort();
                this.DosageOptions.Sort();
                this.NDCs = NDCs.OrderBy(c => c.DisplayName).ThenBy(c => c.NDC).ToList();
            }
            else
            {
                this.DisplayAs     = string.Empty;
                this.DosageOptions = new List <string>();
                this.Strengths     = new List <string>();
                this.NDCs          = new List <NDCDto>();
                this.GPIs          = new List <GPIDto>();
            }
        }
コード例 #5
0
        public void ConvertRawGPItoTree_Test()
        {
            string filter   = "35";
            bool   hasError = false;
            var    ctx      = new ScriptCycleContext();
            var    repo     = new DrugRepo(ctx);
            var    results  = repo.GetGPI(filter);

            var errors = new List <string>();
            var list   = new List <GPITreeItem>();

            var startNode = results.SingleOrDefault(r => r.name == filter);


            var gpiTreeItem = new GPITreeItem {
                name        = startNode.name,
                description = startNode.gpi_name,
                size        = 0
            };

            list.Add(gpiTreeItem);

            for (int i = 4; i < 16; i = i + 2)
            {
                string level = i.ToString();
                if (i < 10)
                {
                    level = string.Format("0{0}", i);
                }

                var gpis = results.Where(g => g.level == level).ToList();

                gpis.ForEach(gpi => {
                    if (i == 2)
                    {
                        list.Add(new GPITreeItem {
                            name = gpi.name, description = gpi.gpi_name
                        });
                    }
                    else
                    {
                        string name = gpi.name.Substring(0, gpi.name.Length - 2);
                        foreach (var node in list)
                        {
                            var found = Find(node, name);
                            if (found != null)
                            {
                                found.children.Add(new GPITreeItem {
                                    name = gpi.name, description = gpi.gpi_name
                                });
                            }
                            else
                            {
                                errors.Add("Cound not find node for " + name + ".");
                                hasError = true;
                            }
                        }
                    }
                });
            }

            if (errors.Count > 0)
            {
                Console.WriteLine("Errors Detected:");
                errors.ForEach(e => { Console.WriteLine(e); });
            }
            var json = JsonConvert.SerializeObject(gpiTreeItem);

            File.WriteAllText(@"c:\temp\gpi_" + filter + ".json", json);

            Assert.IsTrue(hasError == false);
        }