Beispiel #1
0
        public HttpResponseMessage Destroy(int p_patientprofile_oid)
        {
            // CAD, CEN
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;

            try
            {
                SessionInitializeTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                patientProfileCEN.Destroy(p_patientprofile_oid);
                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 204 - No Content
            return(this.Request.CreateResponse(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;

            List <PatientProfileEN>   patientProfileEN = null;
            List <PatientProfileDTOA> returnValue      = null;

            try
            {
                SessionInitializeWithoutTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                // Data
                // TODO: paginación

                patientProfileEN = patientProfileCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (patientProfileEN != null)
                {
                    returnValue = new List <PatientProfileDTOA>();
                    foreach (PatientProfileEN entry in patientProfileEN)
                    {
                        returnValue.Add(PatientProfileAssembler.Convert(entry, 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 204 - Empty
            if (returnValue == null || returnValue.Count == 0)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NoContent));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }
Beispiel #3
0
        public HttpResponseMessage Modify(int idPatientProfile, [FromBody] PatientProfileDTO dto)
        {
            // CAD, CEN, returnValue
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;
            PatientProfileDTOA    returnValue           = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                // Modify
                patientProfileCEN.Modify(idPatientProfile,
                                         dto.PreferredLanguage
                                         ,
                                         dto.Region
                                         ,
                                         dto.HazardAvoidance
                                         ,
                                         dto.Name
                                         ,
                                         dto.Description
                                         );

                // Return modified object
                returnValue = PatientProfileAssembler.Convert(patientProfileRESTCAD.ReadOIDDefault(idPatientProfile), 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);
            }
        }
Beispiel #4
0
        public HttpResponseMessage New_([FromBody] PatientProfileDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;
            PatientProfileDTOA    returnValue           = null;
            int returnOID = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                // Create
                returnOID = patientProfileCEN.New_(
                    dto.PreferredLanguage                                                                                //Atributo Primitivo: p_preferredLanguage
                    , dto.Region                                                                                         //Atributo Primitivo: p_region
                    , dto.HazardAvoidance                                                                                //Atributo Primitivo: p_hazardAvoidance
                    , dto.Name                                                                                           //Atributo Primitivo: p_name
                    , dto.Description                                                                                    //Atributo Primitivo: p_description
                    );
                SessionCommit();

                // Convert return
                returnValue = PatientProfileAssembler.Convert(patientProfileRESTCAD.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("GetOIDPatientProfile", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
Beispiel #5
0
        public HttpResponseMessage ReadOID(int idPatientProfile)
        {
            // CAD, CEN, EN, returnValue
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;
            PatientProfileEN      patientProfileEN      = null;
            PatientProfileDTOA    returnValue           = null;

            try
            {
                SessionInitializeWithoutTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);

                // Data
                patientProfileEN = patientProfileCEN.ReadOID(idPatientProfile);

                // Convert return
                if (patientProfileEN != null)
                {
                    returnValue = PatientProfileAssembler.Convert(patientProfileEN, 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));
            }
        }
        public HttpResponseMessage ProfileDisabilities(int idPatientProfile)
        {
            // CAD, EN
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileEN      patientProfileEN      = null;

            // returnValue
            List <DisabilityEN>   en          = null;
            List <DisabilityDTOA> returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                patientProfileRESTCAD = new PatientProfileRESTCAD(session);

                // Exists PatientProfile
                patientProfileEN = patientProfileRESTCAD.ReadOIDDefault(idPatientProfile);
                if (patientProfileEN == null)
                {
                    throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "PatientProfile#" + idPatientProfile + " not found"));
                }

                // Rol
                // TODO: paginación


                en = patientProfileRESTCAD.ProfileDisabilities(idPatientProfile).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new List <DisabilityDTOA>();
                    foreach (DisabilityEN entry in en)
                    {
                        returnValue.Add(DisabilityAssembler.Convert(entry, 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 204 - Empty
            if (returnValue == null || returnValue.Count == 0)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NoContent));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }
Beispiel #7
0
        public static PatientProfileDTOA Convert(PatientProfileEN en, NHibernate.ISession session = null)
        {
            PatientProfileDTOA    dto = null;
            PatientProfileRESTCAD patientProfileRESTCAD = null;
            PatientProfileCEN     patientProfileCEN     = null;
            PatientProfileCP      patientProfileCP      = null;

            if (en != null)
            {
                dto = new PatientProfileDTOA();
                patientProfileRESTCAD = new PatientProfileRESTCAD(session);
                patientProfileCEN     = new PatientProfileCEN(patientProfileRESTCAD);
                patientProfileCP      = new PatientProfileCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.PreferredLanguage = en.PreferredLanguage;


                dto.Region = en.Region;


                dto.HazardAvoidance = en.HazardAvoidance;


                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: PatientProfile o--> AccessMode */
                dto.AccessMode = null;
                List <AccessModeEN> AccessMode = patientProfileRESTCAD.AccessMode(en.Id).ToList();
                if (AccessMode != null)
                {
                    dto.AccessMode = new List <AccessModeDTOA>();
                    foreach (AccessModeEN entry in AccessMode)
                    {
                        dto.AccessMode.Add(AccessModeAssembler.Convert(entry, session));
                    }
                }

                /* Rol: PatientProfile o--> Condition */
                dto.Condition = null;
                List <ConditionEN> Condition = patientProfileRESTCAD.Condition(en.Id).ToList();
                if (Condition != null)
                {
                    dto.Condition = new List <ConditionDTOA>();
                    foreach (ConditionEN entry in Condition)
                    {
                        dto.Condition.Add(ConditionAssembler.Convert(entry, session));
                    }
                }

                /* Rol: PatientProfile o--> Disability */
                dto.Disabilities = null;
                List <DisabilityEN> Disabilities = patientProfileRESTCAD.Disabilities(en.Id).ToList();
                if (Disabilities != null)
                {
                    dto.Disabilities = new List <DisabilityDTOA>();
                    foreach (DisabilityEN entry in Disabilities)
                    {
                        dto.Disabilities.Add(DisabilityAssembler.Convert(entry, session));
                    }
                }


                //
                // Service
            }

            return(dto);
        }