Esempio n. 1
0
        public async Task <DiseaseDTO> AddDiseaseAsync(DiseaseDTO disease)
        {
            var d = _diseaseFactory.Transform(disease);
            await _diseaseRepository.AddAsync(d);

            return(_diseaseFactory.Transform(await _diseaseRepository.FindWithSymptomsAsync(d.Id)));
        }
        /// <summary>
        /// Returns all the previous answers along with a questionnaire object
        /// containing the symptom that needs a YES/NO answer or the resulting disease.
        /// </summary>
        /// <param name="questionnaire">Previously answered questions</param>
        /// <returns>Questionnaire with a new question or the answer</returns>
        public async Task <Questionnaire> DiagnoseInteractiveAsync(Questionnaire questionnaire)
        {
            if (questionnaire.NewQuestion != null)
            {
                questionnaire.PreviousAnswers.Add(questionnaire.NewQuestion);
            }

            var diseases = await FilterDiseasesAsync(questionnaire.PreviousAnswers);

            if (diseases.Count > 1)
            {
                questionnaire.NewQuestion = new Question()
                {
                    Symptom = GetSymptomForQuestionAsync(diseases)
                }
            }
            ;
            else if (diseases.Count == 1)
            {
                questionnaire.Result = DiseaseDTO.CreateFromDomain(diseases.Single());
            }
            else
            {
                throw new ArgumentException("Previous questions don't match any disease in the database");
            }
            return(questionnaire);
        }
Esempio n. 3
0
        public async Task <DiseaseDTO> AddAsync(DiseaseDTO dto)
        {
            var disease = DiseaseDTO.CreateFromDTO(dto);
            await _uow.Diseases.AddAsync(disease);

            if (dto.Symptoms.Any())
            {
                foreach (var dtoSymptom in dto.Symptoms)
                {
                    var symptom = await _uow.Symptoms.FindAsync(dtoSymptom.SymptomId);

                    if (symptom == null)
                    {
                        symptom = new Symptom()
                        {
                            SymptomName = dtoSymptom.SymptomName
                        };
                        await _uow.Symptoms.AddAsync(symptom);
                    }
                    await _uow.DiseaseSymptoms.AddAsync(new DiseaseSymptom()
                    {
                        Disease = disease, Symptom = symptom
                    });
                }
            }

            await _uow.SaveChangesAsync();

            return(DiseaseDTO.CreateFromDomain(disease));
        }
 public static Disease DTOtoDisease(DiseaseDTO diseaseDTO)
 {
     return(new Disease
     {
         Name = diseaseDTO.Name,
         Description = diseaseDTO.Description
     });
 }
Esempio n. 5
0
 public static Disease Map(DiseaseDTO itemDTO)
 {
     return(new Disease()
     {
         Id = itemDTO.Id,
         Name = itemDTO.Name,
         Description = itemDTO.Description
     });
 }
 public static DiseaseViewModel DTOtoDiseaseVM(DiseaseDTO diseaseDTO)
 {
     return(new DiseaseViewModel
     {
         Id = diseaseDTO.Id,
         Name = diseaseDTO.Name,
         Description = diseaseDTO.Description
     });
 }
        public async Task <IActionResult> UploadFile()
        {
            #region Code that needs a better place
            if (Request.Form.Files.Count != 1)
            {
                return(BadRequest(new FeedbackDTO("only one file allowed at a time")));
            }
            var file = Request.Form.Files.First();

            var streamReader = new StreamReader(file.OpenReadStream());



            var symptomList = new List <string>();
            while (!streamReader.EndOfStream)
            {
                var strings = (await streamReader.ReadLineAsync()).Split(',').ToList().Skip(1).ToList();
                symptomList.AddRange(strings);
            }
            streamReader.Close();
            symptomList = symptomList.GroupBy(s => s).Select(x => x.First()).ToList();
            var symptomsDictionary = new Dictionary <string, SymptomDTO>();
            foreach (string symptomName in symptomList)
            {
                symptomsDictionary.Add(symptomName, await _symptomService.AddSymptomAsync(new SymptomDTO {
                    Name = symptomName
                }));
            }



            streamReader = new StreamReader(file.OpenReadStream());
            while (!streamReader.EndOfStream)
            {
                var line = (await streamReader.ReadLineAsync()).Split(',');

                var newDisease = new DiseaseDTO {
                    Name = line.First(), Symptoms = new List <SymptomDTO>()
                };

                var diseaseSymptoms = line.Skip(1).ToList();
                foreach (var symptom in diseaseSymptoms)
                {
                    SymptomDTO foundSymptom;
                    if (symptomsDictionary.TryGetValue(symptom, out foundSymptom))
                    {
                        newDisease.Symptoms.Add(foundSymptom);
                    }
                }
                await _diseaseService.AddDiseaseAsync(newDisease);
            }
            streamReader.Close();
            #endregion

            return(Ok());
        }
Esempio n. 8
0
        // [Authorize(Roles = "Worker,Admin")]
        public async Task <IActionResult> Create([FromBody] DiseaseDTO item)
        {
            var result = await _diseaseService.Create(item);

            if (!result.Success)
            {
                return(BadRequest(result.Messages));
            }
            return(CreatedAtAction("GetAll", result.disease));
        }
 public Disease Transform(DiseaseDTO dto)
 {
     return(new Disease
     {
         Id = dto.Id ?? 0,
         Name = dto.Name,
         DiseaseSymptoms = dto.Symptoms.Select(s => new DiseaseSymptom {
             DiseaseId = dto.Id ?? 0, SymptomId = s.Id ?? 0
         }).ToList()
     });
 }
Esempio n. 10
0
        public async Task <IActionResult> PostDisease([FromBody] DiseaseDTO disease)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            disease = await _diseaseService.AddAsync(disease);

            return(CreatedAtAction("GetDisease", new { id = disease.DiseaseId }, disease));
        }
Esempio n. 11
0
 /// <summary>
 /// This method is used to get all Diseases with symptoms.
 /// SymptomsInDiseases are already included from the database
 /// but here we will also will the symptoms list itself.
 /// </summary>
 /// <returns>IEnumerable of diseases with symptoms list filled</returns>
 public IEnumerable <DiseaseDTO> AllWithSymptoms()
 {
     /*  First we everything from diseasesRepo which includes SymptomsInDiseases
      *   Then we Select the SymptomsInDiseases, take out the symptom object and add
      *   it to the original object symptoms List and we do it with everything in
      *   SymptomsInDiseases.
      *   Then we make it into a list and return it.
      */
     return(_diseasesRepo
            .AllWithSymptoms()
            .Select(x => { x.Symptoms = x.SymptomsInDiseases.Select(s => s.Symptom).ToList(); return x; })
            .Select(s => DiseaseDTO.Transform(s)));
 }
Esempio n. 12
0
        //  [Authorize(Roles = "Worker,Admin")]
        public async Task <ActionResult> Update(int id, [FromBody] DiseaseDTO disease)
        {
            try
            {
                var result = await _diseaseService.Update(id, disease);

                if (!result.Success)
                {
                    return(BadRequest(result.Messages));
                }
            }
            catch (KeyNotFoundException)
            {
                Error e = new Error();
                e.Message = "Disease not found.";
                return(NotFound(e));
            }
            return(NoContent());
        }
        public async Task <IActionResult> Post([FromBody] DiseaseDTO disease)
        {
            if (disease.Id != null)
            {
                return(BadRequest(new FeedbackDTO("ID can not be set when posting")));
            }

            if (disease?.Symptoms == null || disease.Symptoms.Count < 1)
            {
                return(BadRequest(new FeedbackDTO("Disease must have symptoms")));
            }
            if (!disease.Symptoms.TrueForAll(s => s.Id != null))
            {
                return(BadRequest(new FeedbackDTO("Symptoms must have IDs")));
            }



            return(Ok(await _diseaseService.AddDiseaseAsync(disease)));
        }
Esempio n. 14
0
        public async Task <DiseaseDTO> Update(DiseaseDTO dto)
        {
            var disease = await _uow.Diseases.FindAsync(dto.DiseaseId);

            if (disease == null)
            {
                return(null);
            }

            disease.DiseaseName = dto.DiseaseName;
            disease             = _uow.Diseases.Update(disease);

            // Change Symptoms
            await _uow.DiseaseSymptoms.RemoveByDiseaseAsync(disease.DiseaseId);

            if (dto.Symptoms.Any())
            {
                foreach (var dtoSymptom in dto.Symptoms)
                {
                    var symptom = await _uow.Symptoms.FindAsync(dtoSymptom.SymptomId);

                    if (symptom == null)
                    {
                        symptom = new Symptom()
                        {
                            SymptomName = dtoSymptom.SymptomName
                        };
                        await _uow.Symptoms.AddAsync(symptom);
                    }
                    await _uow.DiseaseSymptoms.AddAsync(new DiseaseSymptom()
                    {
                        Disease = disease, Symptom = symptom
                    });
                }
            }

            await _uow.SaveChangesAsync();

            return(DiseaseDTO.CreateFromDomain(disease));
        }
Esempio n. 15
0
        public DiseaseDTO AddDisease(DiseaseDTO diseaseDTO)
        {
            var diseases = new Disease()
            {
                DiseaseName = diseaseDTO.DiseaseName,
                DiseaseType = diseaseDTO.DiseaseType
            };

            _context.Diseases.Add(diseases);
            _context.SaveChanges();
            int diseaseid = diseases.DiseaseId;

            diseaseDTO.Diseaseid = diseaseid;
            //_context.Diseases.Add(new Disease()
            //{
            //    DiseaseName = disease.DiseaseName,
            //    DiseaseType = disease.DiseaseType
            //});


            return(diseaseDTO);
        }
Esempio n. 16
0
        public async Task <DiseaseResponse> Update(int id, DiseaseDTO updatedDisease)
        {
            var disease = await _diseaseRepository.GetById(id);

            if (disease == null)
            {
                throw new KeyNotFoundException();
            }

            //disease.Id = updatedDisease.Id;
            disease.Name        = updatedDisease.Name;
            disease.Description = updatedDisease.Description;
            if (disease.Name == null)
            {
                string errorMessage3 = "Disease name not found.";
                Log.Error(errorMessage3);
                return(new DiseaseResponse(errorMessage3));
            }
            if (disease.Description == null)
            {
                string errorMessage3 = "Disease description not found.";
                Log.Error(errorMessage3);
                return(new DiseaseResponse(errorMessage3));
            }

            try
            {
                _diseaseRepository.Update(disease);
                await _context.SaveChangesAsync();

                return(new DiseaseResponse());
            }
            catch (Exception exception)
            {
                string errorMessage = $"An error occured when updating the item: {exception.Message}";
                return(new DiseaseResponse(errorMessage));
            }
        }
Esempio n. 17
0
        public async Task <DiseaseResponse> Create(DiseaseDTO newDisease)
        {
            var disease = DiseaseMapper.Map(newDisease);

            if (disease == null)
            {
                string errorMessage = "Disease not found.";

                Log.Error(errorMessage);
                return(new DiseaseResponse(errorMessage));
            }
            if (disease.Name == null)
            {
                string errorMessage2 = "Disease name not found.";
                Log.Error(errorMessage2);
                return(new DiseaseResponse(errorMessage2));
            }
            if (disease.Description == null)
            {
                string errorMessage3 = "Disease description not found.";
                Log.Error(errorMessage3);
                return(new DiseaseResponse(errorMessage3));
            }

            try
            {
                await _diseaseRepository.Create(disease);

                await _context.SaveChangesAsync();

                return(new DiseaseResponse(DiseaseMapper.Map(disease)));
            }
            catch (Exception exception)
            {
                string errorMessage = $"An error occured when creating the item: {exception.Message}";
                return(new DiseaseResponse(errorMessage));
            }
        }
Esempio n. 18
0
        public async Task <IActionResult> PutDisease([FromRoute] int id, [FromBody] DiseaseDTO disease)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != disease.DiseaseId)
            {
                return(BadRequest());
            }

            var dbDisease = await _diseaseService.GetByIdAsync(disease.DiseaseId);

            if (dbDisease == null)
            {
                return(NotFound());
            }

            try
            {
                await _diseaseService.Update(disease);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await DiseaseExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 19
0
 public ActionResult <List <DiseaseDTO> > Post(DiseaseDTO diseaseDTO)
 {
     dr.AddDisease(diseaseDTO);
     return(Ok(diseaseDTO.Diseaseid));
 }
Esempio n. 20
0
        public async Task <DiseaseDTO> GetByIdAsync(int id)
        {
            var disease = await _uow.Diseases.GetByIdWithSymptomsAsync(id);

            return(DiseaseDTO.CreateFromDomainWithDiseases(disease));
        }
Esempio n. 21
0
 public DiseaseResponse(DiseaseDTO disease) : base(string.Empty, true)
 {
     this.disease = disease;
 }