/// <summary>
        /// The delete.
        /// </summary>
        /// <param name="patientId"> Patient ID </param>
        /// <param name="id">
        /// The id.
        /// </param>
        /// <returns>
        /// The <see cref="HttpResponseMessage"/>.
        /// </returns>
        public HttpResponseMessage Delete(int patientId, int id)
        {
            try
            {
                AccessControl.VerifyUserAccessToPatient(patientId);
                if (id != 0)
                {
                    // Delete Insurance
                    // Insurance can not be deleted if it has been used in a previous transaction or claim
                    if (this.patientInsuranceManager.CanDeletePatientInsurance(id))
                    {
                        var relationshipsIt2Manager     = new PatientRelationshipsIt2Manager();
                        var matchingDependentInsurances = relationshipsIt2Manager.GetMatchingDependentInsurances(patientId, id);
                        //// Delete Dependents Insurance
                        if (matchingDependentInsurances != null && matchingDependentInsurances.Any())
                        {
                            foreach (var dependentInsurance in matchingDependentInsurances)
                            {
                                if (this.patientInsuranceManager.CanDeletePatientInsurance(dependentInsurance.ID))
                                {
                                    PatientManager.DeletePatientInsuranceAlsl(dependentInsurance.ID);
                                    this.patientInsuranceManager.DeletePatientInsuranceByPatientInsuranceId(dependentInsurance.PatientID.GetValueOrDefault(), dependentInsurance.ID);
                                }
                                else
                                {
                                    //// Inactivate dependent insurance as it can't be deleted
                                    var dependentPatientInsuranceExtension = PatientManager.GetPatientInsuranceExtension(dependentInsurance.PatientID.GetValueOrDefault(), dependentInsurance.ID);
                                    dependentPatientInsuranceExtension.IsActive = false;
                                    var alslInsurances = new List <PatientInsuranceAlsl> {
                                        dependentPatientInsuranceExtension
                                    };
                                    PatientManager.SavePatientInsuranceAlsl(alslInsurances);
                                }
                            }
                        }

                        //// Delete Parent Insurance
                        PatientManager.DeletePatientInsuranceAlsl(id);
                        this.patientInsuranceManager.DeletePatientInsuranceByPatientInsuranceId(patientId, id);
                        return(new HttpResponseMessage(HttpStatusCode.NoContent));
                    }

                    const string Message = "The insurance carrier/plan has associated eligibilities and cannot be deleted. Instead of deleting the insurance carrier/plan, you can inactivate it.";
                    return(Request.CreateResponse(HttpStatusCode.Conflict, Message));
                }

                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            catch (Exception ex)
            {
                var error = string.Format("Delete({0}, {1}{2} {3}", patientId, id, ")\n", ex);
                return(HandleExceptions.LogExceptions(error, Logger, ex));
            }
        }
        public HttpResponseMessage Put(string officeNumber, [FromBody] PatientRelationships patientRelationships)
        {
            var patientRelationshipsIt2Manager = new PatientRelationshipsIt2Manager();

            try
            {
                patientRelationshipsIt2Manager.InsertOrUpdateDependent(officeNumber, patientRelationships);
                return(this.Request.CreateResponse(HttpStatusCode.OK, "Dependent saved."));
            }
            catch (Exception ex)
            {
                var error = "Put( patientId=" + patientRelationships.PatientId + ")\n" + ex;
                return(HandleExceptions.LogExceptions(error, Logger, ex));
            }
        }
        public HttpResponseMessage Delete([FromBody] PatientRelationships relationshipsObj)
        {
            var patientRelationshipsIt2Manager = new PatientRelationshipsIt2Manager();

            try
            {
                var result = patientRelationshipsIt2Manager.DeleteDependent(relationshipsObj);
                return(result
                    ? this.Request.CreateResponse(HttpStatusCode.OK, "Dependent deleted.")
                    : this.Request.CreateResponse(HttpStatusCode.BadRequest, "Unable to delete this dependent."));
            }
            catch (Exception ex)
            {
                var error = "Put( patientId=" + relationshipsObj.PatientId + ")\n" + ex;
                return(HandleExceptions.LogExceptions(error, Logger, ex));
            }
        }
        public HttpResponseMessage GetAllDependents(string officeNumber, [FromUri] int patientId)
        {
            var patientRelationshipsIt2Manager = new PatientRelationshipsIt2Manager();

            try
            {
                patientRelationshipsIt2Manager.GetAllDependents(patientId);
                foreach (var dependent in patientRelationshipsIt2Manager.InvalidDependents.Dependents)
                {
                    Logger.Error(
                        "Found a Patient with a Dependent that belongs to a different office. [CompanyId="
                        + officeNumber + ", PatientId=" + patientId + ", DependentCompanyId=" + dependent.CompanyId
                        + ", DependentPatientId=" + dependent.PatientId + "] ");
                }

                return(Request.CreateResponse(HttpStatusCode.OK, patientRelationshipsIt2Manager.ValidDependents));
            }
            catch (Exception ex)
            {
                var error = "GetAllDependents( patientId=" + patientId + ")\n" + ex;
                return(HandleExceptions.LogExceptions(error, Logger, ex));
            }
        }