Ejemplo n.º 1
0
        public JsonResult AddUpdateAllergies(long allergiesID, PatientAllergies_Custom allergy)
        {
            try
            {
                if (allergy.allergyName == null || allergy.allergyName == "" || !Regex.IsMatch(allergy.allergyName, "^[0-9a-zA-Z ]+$"))
                {
                    ApiResultModel apiresult = new ApiResultModel();
                    apiresult.message = "Invalid allergy name.Only letters and numbers are allowed.";

                    return(Json(new { Success = true, ApiResultModel = apiresult }));
                }
                AllergiesRepository objRepo = new AllergiesRepository();
                if (allergiesID == 0)
                {
                    ApiResultModel apiresult = objRepo.AddPatientAllergy(allergy);
                    return(Json(new { Success = true, ApiResultModel = apiresult }));
                }
                else
                {
                    ApiResultModel apiresult = objRepo.EditPatientAllergy(allergiesID, allergy);
                    return(Json(new { Success = true, ApiResultModel = apiresult }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Message = ex.Message }));
            }
        }
        public async Task <HttpResponseMessage> AddPatientAllergy(PatientAllergies_Custom model)
        {
            PatientAllergy pallergy = new PatientAllergy();

            try
            {
                if (model.allergyName == "" || model.allergyName == null || !Regex.IsMatch(model.allergyName.Trim(), "^[0-9a-zA-Z ]+$"))
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "Invalid allergy name. Only letters and numbers are allowed."
                    });
                    return(response);
                }
                if (model.patientID == 0)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "Invalid patient ID."
                    });
                    return(response);
                }

                pallergy = db.PatientAllergies.Where(all => all.patientID == model.patientID && all.allergyName.Trim() == model.allergyName.Trim() && all.active == true).FirstOrDefault();

                if (pallergy == null)
                {
                    pallergy              = new PatientAllergy();
                    pallergy.active       = true;
                    pallergy.allergyName  = model.allergyName;
                    pallergy.severity     = model.severity;
                    pallergy.reaction     = model.reaction;
                    pallergy.patientID    = model.patientID;
                    pallergy.cd           = System.DateTime.Now;
                    pallergy.source       = "S";
                    pallergy.reportedDate = System.DateTime.Now;
                    pallergy.cb           = pallergy.patientID.ToString();

                    db.PatientAllergies.Add(pallergy);
                    await db.SaveChangesAsync();
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, new ApiResultModel {
                        ID = 0, message = "Allergy already exists."
                    });
                    response.ReasonPhrase = "Allergy already exists";
                    return(response);
                }
            }
            catch (Exception ex)
            {
                return(ThrowError(ex, "AddPatientAllergy in PatientAllergiesController."));
            }


            response = Request.CreateResponse(HttpStatusCode.OK, new ApiResultModel {
                ID = pallergy.allergiesID, message = ""
            });
            return(response);
        }
Ejemplo n.º 3
0
        public ApiResultModel EditPatientAllergy(long allergiesID, PatientAllergies_Custom condition)
        {
            var strContent = JsonConvert.SerializeObject(condition);
            var response   = ApiConsumerHelper.PostData("api/editPatientAllergy?allergyID=" + allergiesID, strContent);
            var result     = JsonConvert.DeserializeObject <ApiResultModel>(response);

            return(result);
        }
Ejemplo n.º 4
0
        public ApiResultModel AddPatientAllergy(PatientAllergies_Custom allergy)
        {
            var strContent = JsonConvert.SerializeObject(allergy);
            var response   = ApiConsumerHelper.PostData("api/addPatientAllergy", strContent);
            var result     = JsonConvert.DeserializeObject <ApiResultModel>(response);

            return(result);
        }