public async Task <IActionResult> UpdateAllergy(Guid uid, [FromBody] AllergyViewModel allergy) { if (!this.ModelState.IsValid) { return(this.BadRequest("Bad data")); } // Save to the database Allergy results = await this.unitOfWork.Allergies.Get(uid); if (results == null || results.Id.Equals(Guid.Empty)) { return(this.BadRequest("User does not exist")); } if (!string.IsNullOrWhiteSpace(allergy.Name)) { results.Name = allergy.Name; } if (!string.IsNullOrWhiteSpace(allergy.Signs)) { results.Signs = allergy.Signs; } if (!string.IsNullOrWhiteSpace(allergy.Symptoms)) { results.Symptoms = allergy.Symptoms; } await this.unitOfWork.Allergies.Update(results); return(this.Ok(this.mapper.Map <AllergyViewModel>(results))); }
public async Task <IActionResult> CreateAllergy([FromBody] AllergyViewModel allergy) { if (!this.ModelState.IsValid) { return(this.BadRequest("Bad data")); } try { // Save to the database Allergy newAllergy = this.mapper.Map <Allergy>(allergy); if (allergy.Id.Equals(Guid.Empty)) { newAllergy.Id = Guid.NewGuid(); } await this.unitOfWork.Allergies.Add(newAllergy); return(this.Ok(this.mapper.Map <AllergyViewModel>(newAllergy))); } catch (Exception ex) { this.logger.LogError($"Failed to create the allergy: {ex}"); return(this.BadRequest("Error Occurred")); } }
public ActionResult Allergies(string ID) { SearchViewModel m = new SearchViewModel(); List <AllergyViewModel> allergyList = new List <AllergyViewModel>(); var client = new FhirClient("http://fhirtest.uhn.ca/baseDstu1"); //get patient basic info Bundle resultsPatients = client.Search <Patient>(new string[] { "_id=" + ID }); foreach (var entry in resultsPatients.Entries) { ResourceEntry <Patient> patient = (ResourceEntry <Patient>)entry; m = getPatientInfo(patient); } //get patient allergy information Bundle resultsAllergies = client.Search <AllergyIntolerance>(new string[] { "subject=" + ID }); foreach (var entry in resultsAllergies.Entries) { AllergyViewModel allergies = new AllergyViewModel(); ResourceEntry <AllergyIntolerance> allergy = (ResourceEntry <AllergyIntolerance>)entry; allergies.AllergyName = allergy.Resource.Substance.DisplayElement.Value; if (allergy.Resource.Reaction != null) { allergies.Severity = allergy.Resource.Reaction.FirstOrDefault <ResourceReference>().Display; } else { allergies.Severity = "Unknown Sensitivity to"; } m.AllergiesCount++; allergyList.Add(allergies); } m.Allergies = allergyList; patients.Add(m); return(View(patients)); }