Beispiel #1
0
        private static Drug ToDrug(DrugDataSet drugDataSet)
        {
            var drug = new Drug();

            drug.Name   = drugDataSet.Object.ToLowerInvariant();
            drug.DrugId = drugDataSet.Drug1;
            return(drug);
        }
Beispiel #2
0
        private static Drug ToPrecipitant(DrugDataSet drugDataSet)
        {
            var drug = new Drug();

            drug.Name        = drugDataSet.Precipitant.ToLowerInvariant();
            drug.DrugId      = drugDataSet.Drug2;
            drug.WarningText = drugDataSet.Label;
            return(drug);
        }
Beispiel #3
0
        /// <summary>
        /// Finds the overgiven drug
        /// </summary>
        /// <remarks>If more than one result is found null will be returned.</remarks>
        /// <param name="drugName"></param>
        /// <returns></returns>
        public Drug FindDrugByPredict(Predicate <CsvMappingResult <DrugDataSet> > lookupPattern)
        {
            Drug drug         = null;
            var  drugDataSets = _csvParser.ReadFromStream(Stream, Encoding.ASCII)
                                .Where(a => a?.Result?.Object != null &&
                                       lookupPattern.Invoke(a))
                                .Select(a => a.Result)
                                .ToArray();

            if (drugDataSets.Select(a => a.Drug1.ToLowerInvariant()).Distinct().Count() > 1)
            {
                drugDataSets = new DrugDataSet[0];
            }

            if (drugDataSets.Any())
            {
                //create the drug itself
                drug = ToDrug(drugDataSets.FirstOrDefault());

                foreach (DrugDataSet drugDataSet in drugDataSets)
                {
                    string drugIdPrecipitant = drugDataSet.Drug2;

                    //underneath code does not performe good so we remove it temporary
                    //var interactions = _csvParser.ReadFromStream(Stream, Encoding.ASCII)
                    //    .Where(a => a?.Result?.Drug1 != null
                    //        && a.Result.Drug1 == drugIdPrecipitant
                    //        && a.Result.Drug2 == drug.DrugId)
                    //            .Select(a => a.Result)
                    //                .ToArray();
                    //drug.Precipitant.Add(ToPrecipitant(interactions, drugDataSet.Precipitant));
                    drug.Precipitant.Add(ToPrecipitant(drugDataSet));
                }
            }

            return(drug);
        }