public static CarePlanTemplateDTOA Convert(CarePlanTemplateEN en, NHibernate.ISession session = null) { CarePlanTemplateDTOA dto = null; CarePlanTemplateRESTCAD carePlanTemplateRESTCAD = null; CarePlanTemplateCEN carePlanTemplateCEN = null; CarePlanTemplateCP carePlanTemplateCP = null; if (en != null) { dto = new CarePlanTemplateDTOA(); carePlanTemplateRESTCAD = new CarePlanTemplateRESTCAD(session); carePlanTemplateCEN = new CarePlanTemplateCEN(carePlanTemplateRESTCAD); carePlanTemplateCP = new CarePlanTemplateCP(session); // // Attributes dto.Id = en.Id; dto.Status = en.Status; dto.Intent = en.Intent; dto.Title = en.Title; dto.Modified = en.Modified; dto.DurationDays = en.DurationDays; dto.Name = en.Name; dto.Description = en.Description; // // TravesalLink /* Rol: CarePlanTemplate o--> CareActivity */ dto.CareActivities = null; List <CareActivityEN> CareActivities = carePlanTemplateRESTCAD.CareActivities(en.Id).ToList(); if (CareActivities != null) { dto.CareActivities = new List <CareActivityDTOA>(); foreach (CareActivityEN entry in CareActivities) { dto.CareActivities.Add(CareActivityAssembler.Convert(entry, session)); } } /* Rol: CarePlanTemplate o--> Goal */ dto.Goals = null; List <GoalEN> Goals = carePlanTemplateRESTCAD.Goals(en.Id).ToList(); if (Goals != null) { dto.Goals = new List <GoalDTOA>(); foreach (GoalEN entry in Goals) { dto.Goals.Add(GoalAssembler.Convert(entry, session)); } } /* Rol: CarePlanTemplate o--> PatientProfileCare */ dto.Patient = PatientProfileCareAssembler.Convert((PatientProfileEN)en.PatientProfile, session); /* Rol: CarePlanTemplate o--> Condition_CarePlan */ dto.AddressConditions = null; List <ConditionEN> AddressConditions = carePlanTemplateRESTCAD.AddressConditions(en.Id).ToList(); if (AddressConditions != null) { dto.AddressConditions = new List <Condition_CarePlanDTOA>(); foreach (ConditionEN entry in AddressConditions) { dto.AddressConditions.Add(Condition_CarePlanAssembler.Convert(entry, session)); } } // // Service } return(dto); }
public HttpResponseMessage New_([FromBody] CarePlanTemplateDTO dto) { // CAD, CEN, returnValue, returnOID CarePlanTemplateRESTCAD carePlanTemplateRESTCAD = null; CarePlanTemplateCEN carePlanTemplateCEN = null; CarePlanTemplateDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); carePlanTemplateRESTCAD = new CarePlanTemplateRESTCAD(session); carePlanTemplateCEN = new CarePlanTemplateCEN(carePlanTemplateRESTCAD); // Create returnOID = carePlanTemplateCEN.New_( dto.Status //Atributo Primitivo: p_status , dto.Intent //Atributo Primitivo: p_intent , dto.Title //Atributo Primitivo: p_title , dto.Modified //Atributo Primitivo: p_modified , dto.DurationDays //Atributo Primitivo: p_durationDays , dto.Name //Atributo Primitivo: p_name , dto.Description //Atributo Primitivo: p_description ); SessionCommit(); // Convert return returnValue = CarePlanTemplateAssembler.Convert(carePlanTemplateRESTCAD.ReadOIDDefault(returnOID), session); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 201 - Created response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue); // Location Header /* * Dictionary<string, object> routeValues = new Dictionary<string, object>(); * * // TODO: y rolPaths * routeValues.Add("id", returnOID); * * uri = Url.Link("GetOIDCarePlanTemplate", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idCarePlanTemplate, [FromBody] CarePlanTemplateDTO dto) { // CAD, CEN, returnValue CarePlanTemplateRESTCAD carePlanTemplateRESTCAD = null; CarePlanTemplateCEN carePlanTemplateCEN = null; CarePlanTemplateDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); carePlanTemplateRESTCAD = new CarePlanTemplateRESTCAD(session); carePlanTemplateCEN = new CarePlanTemplateCEN(carePlanTemplateRESTCAD); // Modify carePlanTemplateCEN.Modify(idCarePlanTemplate, dto.Status , dto.Intent , dto.Title , dto.Modified , dto.DurationDays , dto.Name , dto.Description ); // Return modified object returnValue = CarePlanTemplateAssembler.Convert(carePlanTemplateRESTCAD.ReadOIDDefault(idCarePlanTemplate), session); SessionCommit(); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 404 - Not found if (returnValue == null) { return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } // Return 200 - OK else { response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue); return(response); } }
public HttpResponseMessage ReadOID(int idCarePlanTemplate) { // CAD, CEN, EN, returnValue CarePlanTemplateRESTCAD carePlanTemplateRESTCAD = null; CarePlanTemplateCEN carePlanTemplateCEN = null; CarePlanTemplateEN carePlanTemplateEN = null; CarePlanTemplateDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); carePlanTemplateRESTCAD = new CarePlanTemplateRESTCAD(session); carePlanTemplateCEN = new CarePlanTemplateCEN(carePlanTemplateRESTCAD); // Data carePlanTemplateEN = carePlanTemplateCEN.ReadOID(idCarePlanTemplate); // Convert return if (carePlanTemplateEN != null) { returnValue = CarePlanTemplateAssembler.Convert(carePlanTemplateEN, session); } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } else { throw new HttpResponseException(HttpStatusCode.InternalServerError); } } finally { SessionClose(); } // Return 404 - Not found if (returnValue == null) { return(this.Request.CreateResponse(HttpStatusCode.NotFound)); } // Return 200 - OK else { return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue)); } }