Exemplo n.º 1
0
        private void InformCaregivers(string enduserURI, string type, string severity, string msg, string desc)
        {
            var caregivers = storeAPI.GetCaregivers(enduserURI);

            foreach (string caregiverURIPath in caregivers)
            {
                int caregiverID = GetIdFromURI(caregiverURIPath);

                Console.WriteLine("[MeasurmentHandler] Informing caregiver: " + caregiverURIPath + " of: " + msg);
                storeAPI.PushJournalEntry(caregiverURIPath, type, severity, msg, desc);
                insertionAPI.InsertPushNotification(msg, caregiverID);
            }
        }
        public void Handle(string json)
        {
            string END_USER_URI = "/api/v1/user/2/";


            Console.WriteLine("Sensor handler invoked");

            var deserialized = JsonConvert.DeserializeObject <dynamic>(json);

            if (deserialized.category == "USER_ENVIRONMENT")
            {
                Console.WriteLine("USER_ENVIRONMENT");


                if (deserialized.content.name == "presence")
                {
                    Console.WriteLine("presence");

                    var msg = "User has entered the" + Map[deserialized.annotations.source.sensor];

                    storeAPI.PushJournalEntry(END_USER_URI, "environment", "low", msg, msg);

                    Console.WriteLine("Sensor to location: " + msg);
                }
            }
        }
        private void SendBPMeasurementNotification(string userURIPath)
        {
            var LANG = storeAPI.GetLang(userURIPath);

            string enduser_msg  = Loc.Get(LANG, Loc.MSG, Loc.REMINDER_SENT, Loc.USR);
            string enduser_desc = Loc.Get(LANG, Loc.DES, Loc.REMINDER_SENT, Loc.USR);

            string caregiver_msg  = Loc.Get(LANG, Loc.MSG, Loc.REMINDER_SENT, Loc.CAREGVR);
            string caregiver_desc = Loc.Get(LANG, Loc.DES, Loc.REMINDER_SENT, Loc.CAREGVR);

            string notification_type = "appointment";

            // get the user data to retrieve caregiver uri as well
            var userData = storeAPI.GetUserData(userURIPath);

            if (userData != null)
            {
                // send notification for end user
                int          enduserID           = GetIdFromURI(userURIPath);
                JournalEntry endUserJournalEntry = storeAPI.PushJournalEntry(userURIPath, notification_type, "low", enduser_msg, enduser_desc);
                insertionAPI.InsertPushNotification(JsonConvert.SerializeObject(new DSS.RMQ.INS.PushNotification()
                {
                    message = enduser_msg, user_id = enduserID
                }));

                // send notification to all caregivers
                List <int> caregiverJournalEntryIDs = new List <int>();
                var        profile = userData["enduser_profile"];
                if (profile["caregivers"] != null)
                {
                    foreach (var caregiverURIPath in profile["caregivers"])
                    {
                        int caregiverID = GetIdFromURI((string)caregiverURIPath);

                        var caregiverJournalEntry = storeAPI.PushJournalEntry((string)caregiverURIPath, notification_type, "low", caregiver_msg, caregiver_desc);
                        insertionAPI.InsertPushNotification(JsonConvert.SerializeObject(new DSS.RMQ.INS.PushNotification()
                        {
                            message = caregiver_msg, user_id = caregiverID
                        }));

                        caregiverJournalEntryIDs.Add(caregiverJournalEntry.id);
                    }
                }

                // generate reminder event
                var reminderEvent = new Event()
                {
                    category = "USER_NOTIFICATIONS",
                    content  = new Content()
                    {
                        uuid       = Guid.NewGuid().ToString(),
                        name       = "reminder_sent",
                        value_type = "complex",
                        val        = new Dictionary <string, dynamic>()
                        {
                            { "user", new Dictionary <string, int>()
                              {
                                  { "id", enduserID }
                              } },
                            { "journal", new Dictionary <string, dynamic>()
                              {
                                  { "id_enduser", endUserJournalEntry.id },
                                  { "id_caregivers", caregiverJournalEntryIDs.ToArray <int>() }
                              } },
                        }
                    },
                    annotations = new Annotations()
                    {
                        timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds,
                        source    = "DSS"
                    }
                };

                Console.WriteLine("[MotionEventHandler] Inserting new reminderEvent: " + reminderEvent);
                insertionAPI.InsertEvent(JsonConvert.SerializeObject(reminderEvent));
            }
            else
            {
                Console.WriteLine("[MotionEventHandler] Error - no information available on user with uri: " + userURIPath + ". Cannot send notification to end user and caregivers.");
            }
        }