public HttpResponseMessage AddPatientProfile(int p_careplantemplate_oid, int p_patientprofile_oid)
        {
            // CAD, CEN, returnValue
            CarePlanTemplateRESTCAD carePlanTemplateRESTCAD = null;
            CarePlanTemplateCEN     carePlanTemplateCEN     = null;

            try
            {
                SessionInitializeTransaction();


                carePlanTemplateRESTCAD = new CarePlanTemplateRESTCAD(session);
                carePlanTemplateCEN     = new CarePlanTemplateCEN(carePlanTemplateRESTCAD);

                // Relationer
                carePlanTemplateCEN.AddPatientProfile(p_careplantemplate_oid, 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 200 - OK
            return(this.Request.CreateResponse(HttpStatusCode.OK));
        }
Exemple #2
0
        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 ReadAll()
        {
            // CAD, CEN, EN, returnValue
            CarePlanTemplateRESTCAD carePlanTemplateRESTCAD = null;
            CarePlanTemplateCEN     carePlanTemplateCEN     = null;

            List <CarePlanTemplateEN>   carePlanTemplateEN = null;
            List <CarePlanTemplateDTOA> returnValue        = null;

            try
            {
                SessionInitializeWithoutTransaction();


                carePlanTemplateRESTCAD = new CarePlanTemplateRESTCAD(session);
                carePlanTemplateCEN     = new CarePlanTemplateCEN(carePlanTemplateRESTCAD);

                // Data
                // TODO: paginación

                carePlanTemplateEN = carePlanTemplateCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (carePlanTemplateEN != null)
                {
                    returnValue = new List <CarePlanTemplateDTOA>();
                    foreach (CarePlanTemplateEN entry in carePlanTemplateEN)
                    {
                        returnValue.Add(CarePlanTemplateAssembler.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));
            }
        }
        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 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 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));
            }
        }
        public static void InitializeData()
        {
            /*PROTECTED REGION ID(initializeDataMethod) ENABLED START*/
            try
            {
                // Insert the initilizations of entities using the CEN classes



                UserCEN userCEN = new UserCEN();
                userCEN.New_("shahabsur", true, false, "1234", "shahab", "Shahab", "*****@*****.**");

                int idUser = userCEN.New_("Lucas Grijander", true, true, "1234", "Chiquito", "Paciente Alzheimer", "*****@*****.**");


                DeviceTemplateCEN deviceTCEN = new DeviceTemplateCEN();
                int deviceT1 = deviceTCEN.New_("Smartring", DeviceTypeEnum.sensor, false);
                int deviceT2 = deviceTCEN.New_("Smartphone", DeviceTypeEnum.actuator, false);
                int deviceT3 = deviceTCEN.New_("Voice Assistance", DeviceTypeEnum.actuator, false);


                CommandCEN commandCEN = new CommandCEN();
                commandCEN.New_(deviceT1, "Command 1", true, OperationTypeEnum.GetByID, "get device by id");

                PropertyCEN propertyCEN = new PropertyCEN();
                propertyCEN.New_(deviceT1, "property 1", true, true);

                TelemetryCEN telemetryCEN = new TelemetryCEN();
                int          idTelemetry  = telemetryCEN.New_(deviceT1, 2, MoSIoTGenNHibernate.Enumerated.MosIoT.DataTypeEnum.Integer, TypeUnitEnum.steps, "Heart beats", TelemetryTypeEnum.event_);


                EventTelemetryCEN eventTelemetry = new EventTelemetryCEN();
                int eventTel1 = eventTelemetry.New_(idTelemetry, "evento", MoSIoTGenNHibernate.Enumerated.MosIoT.SeverityEventEnum.info);


                PatientProfileCEN patientProfile = new PatientProfileCEN();
                int idPatientProfile             = patientProfile.New_(LanguageCodeEnum.es, "Espana", HazardValueEnum.olfactoryHazard, "patient with Alzheimer", "patient with a mild Alzheimer with a cognitive disability");

                ConditionCEN conditionCEN = new ConditionCEN();
                int          idCondition  = conditionCEN.New_(idPatientProfile, "Alzheimer", ClinicalStatusEnum.active, DiseaseEnum.Alzheimer, "Alzheimer");

                DisabilityCEN disabilityCEN = new DisabilityCEN();
                int           idDisability  = disabilityCEN.New_(idPatientProfile, "cognitive", DisabilityTypeEnum.cognitive, SeverityEnum.mild, "Cognitive Disability");

                AccessModeCEN accessMode   = new AccessModeCEN();
                int           idAccessMode = accessMode.New_(idPatientProfile, AccessModeValueEnum.textual, "Acceso al Smartphone", idDisability, "accessMode Smartphone");

                AdaptationRequestCEN adaptRequest = new AdaptationRequestCEN();
                adaptRequest.New_(AccessModeValueEnum.auditory, idAccessMode, LanguageCodeEnum.es, "adaptation auditive");

                AdaptationTypeRequiredCEN adapTypeReq = new AdaptationTypeRequiredCEN();
                adapTypeReq.New_(AdaptationTypeValueEnum.audioDescription, "Describe el contenido con voz", idAccessMode);

                AdaptationDetailRequiredCEN adaptationDetail = new AdaptationDetailRequiredCEN();
                adaptationDetail.New_(AdaptationDetailValueEnum.record, idAccessMode, "Se graba el la voz generada");


                CarePlanTemplateCEN carePlan = new CarePlanTemplateCEN();
                int idCarePlanT = carePlan.New_(CareStatusEnum.active, CarePlanIntentEnum.proposal, "Plan de cuidados para persona con Alzheimer", DateTime.Now, 100, "cuidadosAlzheimer", "Se describen todos los objetivos y actividades necesarias para que se cuide a una persona que presenta Alzheimer");


                carePlan.AddCondition(idCarePlanT, new List <int> {
                    idCondition
                });


                CareActivityCEN careActivity = new CareActivityCEN();
                careActivity.New_(idCarePlanT, TypePeriodicityEnum.daily, "Realizar un paseo", 40, "parque", "", TypeActivityEnum.sportActivity, " ", "Paseo");

                int idActivityMed = careActivity.New_(idCarePlanT, TypePeriodicityEnum.perHour, "Tomar Ceregumil", 0, "en casa", "", TypeActivityEnum.medication, "", "Tomar medicamento mente activa");

                MedicationCEN medicationCEN = new MedicationCEN();
                medicationCEN.New_(idActivityMed, 346864, "Ceregumil Original 500 ml", " ", "Tomar una cucharada 3 veces al dia", "cucharada", FormTypeEnum.powder, "346864");

                GoalCEN goal   = new GoalCEN();
                int     idGoal = goal.New_(idCarePlanT, PriorityTypeEnum.high, CareStatusEnum.active, idCondition, "Mejorar los indicadores cognitivos", CategoryGoalEnum.behavioral, " ", "Mejora cognitiva");

                TargetCEN target = new TargetCEN();

                int idTarget = target.New_(idGoal, "70", "Reducir las pulsaciones a 70", DateTime.Today.AddDays(60));


                MeasureCEN measureCEN = new MeasureCEN();
                int        idMeasure  = measureCEN.New_("Pulsaciones_minuto", "Pulsaciones por minuto", " ");

                target.AddMeasure(idTarget, idMeasure);

                measureCEN.AddTelemetries(idMeasure, new List <int> {
                    idTelemetry
                });



                // SCENARIO

                IoTScenarioCEN scenarioCEN   = new IoTScenarioCEN();
                int            idScenarioIoT = scenarioCEN.New_("Escenario Paciente con Alzheimer", "Se reproducen los elementos de un enfermo de alzheimer con discapacidad cognitiva");


                PatientCEN patientCEN = new PatientCEN();
                patientCEN.New_("Juan Lucas", idScenarioIoT, "Es un paciente nuevo", idPatientProfile, idUser);

                PatientAccessCEN patientAccessCEN = new PatientAccessCEN();
                patientAccessCEN.New_("PatientAccessSmartphone", idScenarioIoT, "patient Access Smartphone", idAccessMode);


                DeviceCEN deviceCEN = new DeviceCEN();
                deviceCEN.New_("Iphone 12", idScenarioIoT, "Iphone 12 120 Gb", false, "1212", true, "1818181818181", "firm1", "Apple", deviceT2);

                CarePlanCEN carePlanCEN = new CarePlanCEN();
                carePlanCEN.New_("Care Plan Alzheimer", idScenarioIoT, "El carePlan adecuado para el alzheimer", idCarePlanT);

                /*PROTECTED REGION END*/
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.InnerException);
                throw ex;
            }
        }