Beispiel #1
0
 public IEnumerable <PmsAppointment> MatchPatient(ArrivalsModel model, string mobile)
 {
     if (String.IsNullOrEmpty(StandardiseMobileNumber(mobile)))
     {
         return(null);
     }
     return(model.Expecting.Where(a => StandardiseMobileNumber(a.PatientMobilePhone) == StandardiseMobileNumber(mobile))
            .Union(model.Waiting.Where(a => StandardiseMobileNumber(a.PatientMobilePhone) == StandardiseMobileNumber(mobile))));
 }
Beispiel #2
0
        public async System.Threading.Tasks.Task CheckForMessages(ArrivalsModel model)
        {
            ISmsProcessor sms = GetSmsProcessor();
            // sms.Initialize();
            // TODO: Thread this into the background, but report errors back to the status screen
            // TODO: If this needs paging or something, repeat this call till its complete, or similar
            var messages = sms.ReceiveMessages();

            foreach (var item in messages)
            {
                var appts = MatchPatient(model, item.phone);
                foreach (var appt in appts)
                {
                    if (ActionForMessage(item.message) == "arrived")
                    {
                        await ArriveAppointment(appt);

                        appt.LastPatientMessage = item.message;
                    }
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Check for outgoing messages
        /// If new appts are found, they will be added, missing ones will be removed
        /// (not a flush and add in again - as this will lose data)
        /// </summary>
        /// <param name="model"></param>
        public static async System.Threading.Tasks.Task CheckAppointments(ArrivalsModel model)
        {
            var oldexptecting = model.Expecting.ToList();
            var oldwaiting    = model.Waiting.ToList();

            var server   = GetServerConnection();
            var criteria = new SearchParams();

            criteria.Add("date", "2020-03-19"); // TODO: Change this to today's date
            criteria.Include.Add("Appointment:actor");
            var bundle = await server.SearchAsync <Appointment>(criteria);

            // Debugging
            var doc = System.Xml.Linq.XDocument.Parse(new Hl7.Fhir.Serialization.FhirXmlSerializer().SerializeToString(bundle));

            Console.WriteLine(doc.ToString(System.Xml.Linq.SaveOptions.None));

            Func <ResourceReference, System.Threading.Tasks.Task <Resource> > resolveReference = async(reference) =>
            {
                if (string.IsNullOrEmpty(reference.Reference))
                {
                    return(null);
                }
                ResourceIdentity ri = new ResourceIdentity(reference.Reference);
                var resource        = bundle.Entry.FirstOrDefault(e => e.Resource.ResourceType.GetLiteral() == ri.ResourceType && e.Resource.Id == ri.Id)?.Resource;
                if (resource == null)
                {
                    // wasn't returned in the bundle, so go searching for it
                    resource = await server.ReadAsync <Resource>(reference.Reference);
                }
                return(resource);
            };

            foreach (var entry in bundle.Entry.Select(e => e.Resource as Appointment).Where(e => e != null))
            {
                if (entry.Status == Appointment.AppointmentStatus.Booked)
                {
                    PmsAppointment app = await ToPmsAppointment(entry, resolveReference);

                    if (app != null && !model.Expecting.Contains(app))
                    {
                        model.Expecting.Add(app);
                    }
                }
                if (entry.Status == Appointment.AppointmentStatus.Arrived)
                {
                    PmsAppointment app = await ToPmsAppointment(entry, resolveReference);

                    if (app != null && !model.Waiting.Contains(app))
                    {
                        model.Waiting.Add(app);
                    }
                }
            }

            // finished processing all the items, so remove any that are left
            foreach (var item in oldexptecting)
            {
                model.Expecting.Remove(item);
            }
            foreach (var item in oldwaiting)
            {
                model.Waiting.Remove(item);
            }
        }