public PutThingsResponse PutThings(PutThingsRequest request)
        {
            PutThingsResponse response = new PutThingsResponse();

            try
            {
                if (string.IsNullOrEmpty(request.Token))
                {
                    throw (new System.ArgumentNullException("Token", AppSettings.NullInputEncountered));
                }

                if (request.PersonId.Equals(Guid.Empty))
                {
                    throw (new System.ArgumentNullException("PersonId", AppSettings.NullInputEncountered));
                }

                if (request.RecordId.Equals(Guid.Empty))
                {
                    throw (new System.ArgumentNullException("RecordId", AppSettings.NullInputEncountered));
                }

                response.CountReceived  = 0;
                response.IndexOnError   = 0;
                response.CountSucceeded = 0;
                foreach (string item in request.XmlInputs)
                {
                    response.CountReceived += 1;
                    response.IndexOnError   = response.CountReceived - 1;

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(item);
                    XPathNavigator nav = doc.CreateNavigator();

                    XPathNavigator navTypeId = nav.SelectSingleNode("//type-id");
                    Guid           typeId    = new Guid(navTypeId.InnerXml);

                    XPathNavigator navData = nav.SelectSingleNode("//data-xml");
                    navData.MoveToFirstChild();

                    HealthVaultConnection hv      = new HealthVaultConnection(request.Token, request.PersonId);
                    HealthRecordItem      newItem = new HealthRecordItem(typeId, navData);
                    hv.PutThings(request.RecordId, ref newItem);

                    response.CountSucceeded += 1;
                }
            }
            catch (Microsoft.Health.HealthServiceException hex)
            {
                response.Success = false;
                response.Message = hex.ToString();
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                response.Stack   = ex.StackTrace;
            }
            return(response);
        }
예제 #2
0
        public static void PostThing(HealthRecordItem thing, Guid personId, Guid recordId)
        {
            Guid appId = new Guid(Connections.ApplicationId);
            OfflineWebApplicationConnection connection = Connections.CreateConnection(appId, personId);

            HealthRecordAccessor accessor = new HealthRecordAccessor(connection, recordId);

            accessor.NewItem(thing);
        }
예제 #3
0
 public static int CompareByTimeAscending(HealthRecordItem a, HealthRecordItem b)
 {
     if (a.EffectiveDate < b.EffectiveDate)
     {
         return(-1);
     }
     else if (a.EffectiveDate > b.EffectiveDate)
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }
예제 #4
0
        private void GenerateCCDA()
        {
            XmlDocument ccdaDocumentData = new XmlDocument();

            ccdaDocumentData.Load(fileUpload.FileContent);

            HealthRecordItem ccda = new HealthRecordItem(new Guid("9c48a2b8-952c-4f5a-935d-f3292326bf54"), ccdaDocumentData);

            if (_overrideCCDAfields)
            {
                StringBuilder stringBuilder = new StringBuilder(150);
                string        extSource     = "hv-meaningfuluse";

                using (XmlWriter writer = XmlWriter.Create(stringBuilder, new XmlWriterSettings()
                {
                    OmitXmlDeclaration = true
                }))
                {
                    writer.WriteStartElement("extension");
                    writer.WriteAttributeString("source", extSource);
                    if (_eventTime != DateTime.MinValue)
                    {
                        writer.WriteElementString("event-date", _eventTime.ToString());
                    }
                    if (!string.IsNullOrEmpty(_patientID))
                    {
                        writer.WriteElementString("patient-id", _patientID);
                    }
                    writer.WriteEndElement();
                }

                HealthRecordItemExtension ext = new HealthRecordItemExtension(extSource);
                ext.ExtensionData.CreateNavigator().InnerXml = stringBuilder.ToString();

                ccda.CommonData.Extensions.Add(ext);
            }

            _newCcdaItem = ccda;
        }
예제 #5
0
 public void PutThings(Guid recordId, ref HealthRecordItem newItem)
 {
     HealthVaultPutThings.PutThings(_connection, recordId, ref newItem);
 }
        public static void PutThings(OfflineWebApplicationConnection connection, Guid recordId, ref HealthRecordItem newItem)
        {
            HealthRecordAccessor record = new HealthRecordAccessor(connection, recordId);

            record.NewItem(newItem);
            return;
        }
        public PutThingResponse PutThing(PutThingRequest request)
        {
            PutThingResponse response = new PutThingResponse();

            try
            {
                if (string.IsNullOrEmpty(request.Token))
                {
                    throw (new System.ArgumentNullException("Token", AppSettings.NullInputEncountered));
                }

                if (request.PersonId.Equals(Guid.Empty))
                {
                    throw (new System.ArgumentNullException("PersonId", AppSettings.NullInputEncountered));
                }

                if (request.RecordId.Equals(Guid.Empty))
                {
                    throw (new System.ArgumentNullException("RecordId", AppSettings.NullInputEncountered));
                }

                if (string.IsNullOrEmpty(request.TypeName))
                {
                    throw (new System.ArgumentNullException("TypeName", AppSettings.NullInputEncountered));
                }

                if (request.TypeId.Equals(Guid.Empty))
                {
                    throw (new System.ArgumentNullException("TypeId", AppSettings.NullInputEncountered));
                }

                if (string.IsNullOrEmpty(request.XmlItem))
                {
                    throw (new System.ArgumentNullException("XmlItem", AppSettings.NullInputEncountered));
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(request.XmlItem);
                XPathNavigator nav     = doc.CreateNavigator();
                XPathNavigator navData = nav.SelectSingleNode("//" + request.TypeName);

                if (navData.LocalName.CompareTo(request.TypeName) != 0)
                {
                    throw (new System.ArgumentException("Specified TypeName not found within input string argument.", "XmlItem"));
                }

                HealthVaultConnection hv      = new HealthVaultConnection(request.Token, request.PersonId);
                HealthRecordItem      newItem = new HealthRecordItem(request.TypeId, navData);
                hv.PutThings(request.RecordId, ref newItem);
            }
            catch (Microsoft.Health.HealthServiceException hex)
            {
                response.Success = false;
                response.Message = hex.ToString();
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
                response.Stack   = ex.StackTrace;
            }
            return(response);
        }
        /// <summary>
        /// Marks the specified health record item as deleted.
        /// </summary>
        /// 
        /// <param name="item">
        /// The health record item to remove.
        /// </param>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// <br/><br/>
        /// Health record items are never completely deleted. Instead, they 
        /// are marked as deleted and are ignored for most normal operations. 
        /// Items can be undeleted by contacting customer service.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="item"/> parameter is <b>null</b>.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// There are errors that remove the health record item from 
        /// the server.
        /// </exception>
        /// 
        public void RemoveItem(HealthRecordItem item)
        {
            Validator.ThrowIfArgumentNull(item, "item", "RemoveItemNull");

            RemoveItems(new HealthRecordItem[] { item });
        }
        /// <summary>
        /// Creates a new health record item associated with this record in the 
        /// HealthVault service.
        /// </summary>
        /// 
        /// <param name="item">
        /// The health record item to be created in the HealthVault service.
        /// </param>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// </remarks>
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error.
        /// </exception>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The HealthRecordItem supplied was null.
        /// </exception>
        /// 
        public void NewItem(HealthRecordItem item)
        {
            Validator.ThrowIfArgumentNull(item, "item", "NewItemNullItem");

            NewItems(new HealthRecordItem[] { item });
        }
        /// <summary>
        /// Deserializes the response XML into a <see cref="HealthRecordItem"/> or derived type
        /// based on the registered health record item handler.
        /// </summary>
        /// 
        /// <param name="thingReader">
        /// The XML representation of the item.
        /// </param>
        /// 
        /// <returns>
        /// The <see cref="HealthRecordItem"/> or derived class instance representing the data
        /// in the XML.
        /// </returns>
        /// 
        /// <exception cref="System.Reflection.TargetInvocationException">
        /// The constructor of the type being created throws an 
        /// exception. The inner exception is the exception thrown by the
        /// constructor.
        /// </exception>
        /// 
        /// <exception cref="MissingMethodException">
        /// The default constructor of the type being created is not public.
        /// If you registered the type handler, be sure that the type you
        /// registered for the item type class has a public default 
        /// constructor.
        /// </exception>
        /// 
        internal static HealthRecordItem DeserializeItem(XmlReader thingReader)
        {
            HealthRecordItem result = null;

            string thingString = thingReader.ReadOuterXml();

            XmlReaderSettings settings = SDKHelper.XmlReaderSettings;
            settings.IgnoreWhitespace = false;

            XPathNavigator thingNav;
            using (XmlReader reader =
                    XmlReader.Create(new StringReader(thingString), settings))
            {
                thingNav = new XPathDocument(reader, XmlSpace.Preserve).CreateNavigator();
            }

            thingNav.MoveToFirstChild();

            Guid typeId = GetTypeId(thingNav);

            HealthRecordItemTypeHandler handler = null;
            if (typeId == _applicationSpecificId)
            {
                // Handle application specific health item records by checking for handlers
                // for the application ID and subtype tag. If the handler doesn't exist
                // the default handler will be picked up below.

                AppDataKey appDataKey = GetAppDataKey(thingNav);

                if (appDataKey != null)
                {
                    if (_appSpecificHandlers.ContainsKey(appDataKey.AppId))
                    {
                        if (_appSpecificHandlers[appDataKey.AppId].ContainsKey(appDataKey.SubtypeTag))
                        {
                            handler =
                                _appSpecificHandlers[appDataKey.AppId][appDataKey.SubtypeTag];
                        }
                    }
                }
            }

            if (handler == null &&
                TypeHandlers.ContainsKey(typeId))
            {
                handler = TypeHandlers[typeId];
            }

            if (handler != null)
            {
                result = (HealthRecordItem)Activator.CreateInstance(handler.ItemTypeClass);
            }
            else
            {
                result = new HealthRecordItem(typeId);
            }
            result.ParseXml(thingNav, thingString);
            return result;
        }
예제 #11
0
파일: HVSync.cs 프로젝트: vaibhavb/walkme
        private static void ProcessStepsHealthItem(HealthRecordItem item, ProfileModel profile)
        {
            if (item.TypeId.Equals(AerobicSession.TypeId))
            {
                AerobicSession aerobic = (AerobicSession)item;

                // Only add items with Steps
                if (aerobic.Session.NumberOfSteps > 0)
                {

                    // Is Step in Cache ?
                    DataClassesDataContext db = new DataClassesDataContext();
                    var query = (from g in db.walk_logs
                                 where ((g.log_user == profile.UserCtx.user_id) &&
                                       (g.hv_item_id == item.Key.Id))
                                 select g).SingleOrDefault();
                    // Update or Insert?
                    if (query != null)
                    {
                        query =
                            PopulateWalkLogFromHV(
                                query, aerobic, profile);
                        db.SubmitChanges();
                    }
                    else
                    {
                        walk_log entity = new walk_log();
                        entity = PopulateWalkLogFromHV(
                            entity, aerobic, profile);
                        WalkLogModel.Insert(entity);
                    }
                }

            }
            else if (item.TypeId.Equals(Exercise.TypeId))
            {
                Exercise exercise = (Exercise)item;

                // Only add items with Steps
                double numberOfSteps = 0;
                try
                {
                    numberOfSteps =
                        exercise.Details[ExerciseDetail.Steps_count].Value.Value;
                }
                catch
                {
                    WlkMiTracer.Instance.Log("HVSync.cs:ProcessStepsHealthItem", WlkMiEvent.AppDomain, WlkMiCat.Warning,
                        string.Format("UserId {0} has no pedometer data in HV item", profile.UserCtx.user_id));
                    return;
                }

                if (numberOfSteps > 0)
                {

                    // Is Step in Cache ?
                    DataClassesDataContext db = new DataClassesDataContext();
                    var query = (from g in db.walk_logs
                                 where ((g.log_user == profile.UserCtx.user_id) &&
                                       (g.hv_item_id == item.Key.Id))
                                 select g).SingleOrDefault();
                    // Update or Insert?
                    if (query != null)
                    {
                        query =
                            PopulateWalkLogFromHV(
                                query, exercise, profile);
                        db.SubmitChanges();
                    }
                    else
                    {
                        walk_log entity = new walk_log();
                        entity = PopulateWalkLogFromHV(
                            entity, exercise, profile);
                        WalkLogModel.Insert(entity);
                    }
                }
            }
        }
        /// <summary>
        /// Transforms the XML of the specified health record item using the specified transform.
        /// </summary>
        /// 
        /// <param name="transformName">
        /// The name of the transform to use. Supported transforms for the type can be found in the
        /// <see cref="SupportedTransformNames"/> collection.
        /// </param>
        /// 
        /// <param name="item">
        /// The health record item to be transformed.
        /// </param>
        /// 
        /// <returns>
        /// A string containing the results of the transform.
        /// </returns>
        /// 
        /// <remarks>
        /// If the transform has been used before a cached instance of the compiled transform will
        /// be used. Compiled transforms are not thread safe. It is up to the caller to ensure
        /// that multiple threads do not attempt to use the same transform at the same time.
        /// </remarks>
        /// 
        /// <exception cref="KeyNotFoundException">
        /// If <paramref name="transformName"/> could not be found in the <see cref="TransformSource"/>
        /// collection.
        /// </exception>
        /// 
        public string TransformItem(string transformName, HealthRecordItem item)
        {
            XslCompiledTransform transform = GetTransform(transformName);

            string thingXml = item.GetItemXml();

            StringBuilder result = new StringBuilder();
            XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;
            XsltArgumentList args = new XsltArgumentList();

            args.AddParam("culture", String.Empty, System.Globalization.CultureInfo.CurrentUICulture.Name);
            args.AddParam("typename", String.Empty, this.Name);
            args.AddParam("typeid", String.Empty, this.TypeId.ToString());

            using (XmlWriter writer = XmlWriter.Create(result, settings))
            {
                XPathDocument thingXmlDoc = new XPathDocument(new StringReader(thingXml));
                transform.Transform(thingXmlDoc.CreateNavigator(), args, writer);
                writer.Flush();
            }
            return result.ToString();
        }