コード例 #1
0
        public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                log.Info("Anagraphic request...calling Health Vault server");
                HVClient clientSample            = new HVClient();
                HealthRecordItemCollection items = clientSample.GetWeightFromHealthVault();

                // Get list of authorized people
                ApplicationConnection connection       = clientSample.HealthClientApplication.ApplicationConnection;
                List <PersonInfo>     authorizedPeople = new List <PersonInfo>(connection.GetAuthorizedPeople());

                if (authorizedPeople.Count == 0)
                {
                    log.Info("No records were authorized.  Application setup process did not complete.");
                    return(req.CreateResponse(HttpStatusCode.BadRequest, ""));
                }
                PersonInfo personInfo   = authorizedPeople[0];
                JObject    jsonResponse = CreateJsonResponse(personInfo);

                return(req.CreateResponse(HttpStatusCode.OK, jsonResponse));
            }
            catch (global::System.Exception)
            {
//                JObject jsonResponse = CreateUnauthorizedResponse();

                return(req.CreateResponse(HttpStatusCode.Unauthorized, ""));
            }
        }
コード例 #2
0
ファイル: HVClient.cs プロジェクト: gcarboni1/swsi-health
        /// <summary>
        /// Provisions the application.
        /// If application does not exist, it launches the application
        /// creation process.
        /// </summary>
        public void ProvisionApplication()
        {
            // generate a GUID that will be used for the application creation.
            _applicationId = Guid.NewGuid();

            HealthClientApplication client = HealthClientApplication.Create(_applicationId, _masterApplicationId);

            client.StartApplicationCreationProcess();



            // launch dialog box to wait
            MessageBox.Show("After completing application setup in browser, click OK");

            // check if the app is provisioned now
            HealthServiceInstance instance = FindProvisionedServiceInstance();

            if (instance == null)
            {
                MessageBox.Show("The application setup in your browser did not complete.");
                return;
            }

            _serviceInstance         = instance;
            _healthClientApplication = client;

            // the app was provisioned
            _healthClientApplication = HealthClientApplication.Create(
                _applicationId,
                _masterApplicationId,
                _serviceInstance);

            // Get list of authorized people
            ApplicationConnection connection       = HealthClientApplication.ApplicationConnection;
            List <PersonInfo>     authorizedPeople = new List <PersonInfo>(connection.GetAuthorizedPeople());

            if (authorizedPeople.Count == 0)
            {
                MessageBox.Show("No records were authorized.  Application setup process did not complete.");
                return;
            }

            // save person ID, record ID, and service instance ID
            // assumption is the first person is the current person ID and there is only
            // one recordid for the person. For more persons and records, a selection
            // UI would need to be shown
            PersonInfo personInfo = authorizedPeople[0];

            _personId      = personInfo.PersonId;
            _recordId      = personInfo.SelectedRecord.Id;
            _isProvisioned = true;

            SaveUserSettings();

            MessageBox.Show("Application + " + _applicationId + " is now provisioned");
        }
コード例 #3
0
ファイル: Default.aspx.cs プロジェクト: krzysieq/carehomes
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            ApplicationInfo info = ApplicationConnection.GetApplicationInfo();
            AppName.Text += info.Name;
            AppId.Text   += info.Id.ToString();

            StartupData.SetActiveView(StartupData.Views[0]);
        }
        catch (HealthServiceException ex)
        {
            Error.Text += ex.ToString();
            StartupData.SetActiveView(StartupData.Views[1]);
        }
    }
コード例 #4
0
        /// <summary>
        /// --------------------------- CONSTRUCTORS ---------------------------
        /// </summary>
        public LoadProfileGUI()
        {
            this.authorizer     = new Authorizer();
            this.sessionCreator = new SessionCreator();
            this.profileHandler = new ProfileHandler();
            this.headsetFinder  = new HeadsetFinder();


            this.licenseId       = "";
            this.cortexToken     = "";
            this.sessionId       = "";
            this.isActiveSession = false;
            Array.Clear(previousTriggerTime, 0, previousTriggerTime.Length);

            this.streams = new List <string>();

            this.applicationConnection = ApplicationConnection.Instance;

            stopwatch.Start();

            this.cortexClient = CortexClient.Instance;
            SubscribeToEvents();
            this.authorizer.Start(licenseId);
        }
        /// <summary>
        /// Creates a new open query using the specified 
        /// connection, definition, expiration time,
        /// personal identification number (PIN), description, and XSL.
        /// </summary>
        /// 
        /// <param name="connection">
        /// A <see cref="ApplicationConnection"/> instance that creates the 
        /// new open query.
        /// </param>
        /// 
        /// <param name="searcher">
        /// A <see cref="HealthRecordSearcher"/> instance that defines the open query.
        /// </param>
        ///
        /// <param name="expires">
        /// The number of minutes the query will expire from the creation time.
        /// A value of Int32.MaxValue denotes that the query does not expire.
        /// </param>
        ///
        /// <param name="pinCode">
        /// The PIN that protects the query.  
        /// </param>
        ///
        /// <param name="note">
        /// The note describing the query.
        /// </param>
        /// 
        /// <param name="finalXsl">
        /// The XSL that transforms the results of the query when the 
        /// <see cref="OpenQuery"/> is invoked.
        /// </param>
        /// 
        /// <returns>
        /// An <see cref="OpenQuery"/> instance that represents the newly created query.
        /// </returns>
        /// 
        /// <remarks>
        /// The creation of an open query makes public the data returned by that 
        /// query. However, the query URL must be known to retrieve the data.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="connection"/> or <paramref name="searcher"/> 
        /// parameter is <b>null</b>.
        /// </exception>
        /// 
        /// 
        /// <exception cref="ArgumentException">
        /// The <paramref name="searcher"/> parameter contains no valid search
        /// filters or the <paramref name="pinCode"/> parameter is <b>null</b> 
        /// or empty.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// An error occurred when HealthVault processed the request.
        /// </exception>
        /// 
        public virtual OpenQuery NewOpenQuery(
            ApplicationConnection connection,
            HealthRecordSearcher searcher,
            int expires,
            string pinCode,
            string note,
            string finalXsl)
        {
            Validator.ThrowIfArgumentNull(connection, "connection", "NewQueryNullService");
            Validator.ThrowIfArgumentNull(searcher, "searcher", "NewQueryNullSearcher");

            Validator.ThrowArgumentExceptionIf(
                searcher.Filters == null ||
                searcher.Filters.Count == 0,
                "searcher.Filters",
                "NewQuerySearcherNoFilters");

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "SaveOpenQuery", 1, searcher.Record);

            request.Parameters =
                GetSaveOpenQueryParameters(
                    searcher,
                    expires,
                    pinCode,
                    note,
                    finalXsl);
            request.Execute();

            return
                CreateOpenQueryFromSaveOpenQueryResponse(
                    request.Response.InfoNavigator);
        }
コード例 #6
0
        /// <summary>
        /// Releases the authorization of the application on the health record.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <exception cref="HealthServiceException">
        /// Errors during the authorization release.
        /// </exception>
        /// 
        /// <remarks>
        /// Once the application releases the authorization to the health record, 
        /// calling any methods of this <see cref="HealthRecordAccessor"/> will result 
        /// in a <see cref="HealthServiceAccessDeniedException"/>."
        /// </remarks>
        public virtual void RemoveApplicationAuthorization(
            ApplicationConnection connection,
            HealthRecordAccessor accessor)
        {
            HealthServiceRequest request =
                new HealthServiceRequest(connection, "RemoveApplicationRecordAuthorization", 1, accessor);

            request.Execute();
        }
コード例 #7
0
        /// <summary>
        /// Gets the permissions which the authenticated person 
        /// has when using the calling application for the specified item types
        /// in this  record.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        ///
        /// <param name="healthRecordItemTypeIds">
        /// A collection of unique identifiers to identify the health record  
        /// item types, for which the permissions are being queried. 
        /// </param>
        /// 
        /// <returns>
        /// Returns a dictionary of <see cref="HealthRecordItemTypePermission"/> 
        /// with health record item types as the keys. 
        /// </returns>
        /// 
        /// <remarks> 
        /// If the list of health record item types is empty, an empty dictionary is 
        /// returned. If for a health record item type, the person has 
        /// neither online access nor offline access permissions, 
        /// <b> null </b> will be returned for that type in the dictionary.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="healthRecordItemTypeIds"/> is <b>null</b>.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// If there is an exception during executing the request to HealthVault. 
        /// </exception>
        /// 
        public virtual IDictionary<Guid, HealthRecordItemTypePermission> QueryPermissionsByTypes(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            IList<Guid> healthRecordItemTypeIds)
        {
            Validator.ThrowIfArgumentNull(healthRecordItemTypeIds, "healthRecordItemTypeIds", "CtorhealthRecordItemTypeIdsArgumentNull");

            Dictionary<Guid, HealthRecordItemTypePermission> permissions =
                new Dictionary<Guid, HealthRecordItemTypePermission>();

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "QueryPermissions", 1, accessor);

            for (int i = 0; i < healthRecordItemTypeIds.Count; ++i)
            {
                if (!permissions.ContainsKey(healthRecordItemTypeIds[i]))
                {
                    permissions.Add(healthRecordItemTypeIds[i], null);
                }
            }

            request.Parameters =
                GetQueryPermissionsParametersXml(healthRecordItemTypeIds);

            request.Execute();

            XPathNavigator infoNav =
                request.Response.InfoNavigator.SelectSingleNode(
                    GetQueryPermissionsInfoXPathExpression(
                        request.Response.InfoNavigator));

            XPathNodeIterator thingTypePermissionsNodes =
                infoNav.Select("thing-type-permission");

            foreach (XPathNavigator nav in thingTypePermissionsNodes)
            {
                HealthRecordItemTypePermission thingTypePermissions =
                    HealthRecordItemTypePermission.CreateFromXml(nav);
                permissions[thingTypePermissions.TypeId] = thingTypePermissions;
            }
            return permissions;
        }
コード例 #8
0
        /// <summary>
        /// Gets the permissions which the authenticated person 
        /// has when using the calling application for the specified item types 
        /// in this health record.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="healthRecordItemTypeIds">
        /// A collection of uniqueidentifiers to identify the health record  
        /// item types, for which the permissions are being queried. 
        /// </param>
        /// 
        /// <returns>
        /// A list of <see cref="HealthRecordItemTypePermission"/> 
        /// objects which represent the permissions that the current
        /// authenticated person has for the HealthRecordItemTypes specified
        /// in the current health record when using the current application.
        /// </returns>
        /// 
        /// <remarks> 
        /// If the list of health record item types is empty, an empty list is 
        /// returned. If for a health record item type, the person has 
        /// neither online access nor offline access permissions, 
        /// HealthRecordItemTypePermission object is not returned for that
        /// health record item type. 
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="healthRecordItemTypeIds"/> is <b>null</b>.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// If there is an exception during executing the request to HealthVault. 
        /// </exception>
        /// 
        public virtual Collection<HealthRecordItemTypePermission> QueryPermissions(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            IList<Guid> healthRecordItemTypeIds)
        {
            Validator.ThrowIfArgumentNull(healthRecordItemTypeIds, "healthRecordItemTypeIds", "CtorhealthRecordItemTypeIdsArgumentNull");

            Collection<HealthRecordItemTypePermission> permissions =
                new Collection<HealthRecordItemTypePermission>();

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "QueryPermissions", 1, accessor);

            request.Parameters =
                GetQueryPermissionsParametersXml(healthRecordItemTypeIds);

            request.Execute();

            XPathNavigator infoNav =
                request.Response.InfoNavigator.SelectSingleNode(
                    GetQueryPermissionsInfoXPathExpression(
                        request.Response.InfoNavigator));

            XPathNodeIterator thingTypePermissionsNodes =
                infoNav.Select("thing-type-permission");

            foreach (XPathNavigator nav in thingTypePermissionsNodes)
            {
                HealthRecordItemTypePermission thingTypePermissions =
                    HealthRecordItemTypePermission.CreateFromXml(nav);
                permissions.Add(thingTypePermissions);
            }
            return permissions;
        }
コード例 #9
0
        /// <summary>
        /// Gets the health record items that match the filters as specified by 
        /// the properties of this class.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="searcher">
        /// The searcher that defines what items to return.
        /// </param>
        /// 
        /// <returns>
        /// A collection of health record items that match the applied filters.
        /// </returns>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// </remarks>
        /// 
        /// <exception cref="HealthServiceException">
        /// The response from the server was anything but 
        /// <see cref="HealthServiceStatusCode.Ok"/>.
        /// -or-
        /// <see cref="Microsoft.Health.HealthRecordSearcher.Filters"/> is empty
        /// or contains invalid filters.
        /// </exception>
        /// 
        public virtual ReadOnlyCollection<HealthRecordItemCollection> GetMatchingItems(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            HealthRecordSearcher searcher)
        {
            ValidateFilters(searcher);

            return Execute(connection, accessor, searcher);
        }
コード例 #10
0
        /// <summary>
        /// Gets the information about the person specified.
        /// </summary>
        /// 
        /// <param name="connection">The connection to use to perform the operation. This connection
        /// must be authenticated. </param>
        /// 
        /// <returns>
        /// Information about the person's HealthVault account.
        /// </returns>
        /// 
        /// <remarks>
        /// This method always calls the HealthVault service to get the latest 
        /// information. It is recommended that the calling application cache 
        /// the return value and only call this method again if it needs to 
        /// refresh the cache.
        /// </remarks>
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returns an error.
        /// </exception>
        /// 
        public virtual PersonInfo GetPersonInfo(ApplicationConnection connection)
        {
            HealthServiceRequest request =
                new HealthServiceRequest(connection, "GetPersonInfo", 1);

            request.Execute();

            XPathExpression personPath =
                GetPersonXPathExpression(request.Response.InfoNavigator);

            XPathNavigator infoNav =
                request.Response.InfoNavigator.SelectSingleNode(personPath);

            return PersonInfo.CreateFromXml(connection, infoNav);
        }
コード例 #11
0
        /// <summary>
        /// Creates new health record items associated with the record.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="items">
        /// The health record items from which to create new instances.
        /// </param>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// </remarks>
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error. 
        /// The exception's Error property will contain the index of the
        /// item on which the failure occurred in the ErrorInfo property. If any failures occur, 
        /// no items will have been created.
        /// </exception>
        /// 
        /// <exception cref="ArgumentNullException">
        /// At least one HealthRecordItem in the supplied list was null.
        /// </exception>
        /// 
        public virtual void NewItems(
            ApplicationConnection connection,
            HealthRecordAccessor accessor, 
            IList<HealthRecordItem> items)
        {
            Validator.ThrowIfArgumentNull(items, "items", "NewItemsNullItem");

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "PutThings", 2, accessor);

            StringBuilder infoXml = new StringBuilder();
            XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;

            using (XmlWriter infoXmlWriter =
                XmlWriter.Create(infoXml, settings))
            {
                foreach (HealthRecordItem item in items)
                {
                    Validator.ThrowIfArgumentNull(item, "items", "NewItemsNullItem");

                    item.WriteItemXml(infoXmlWriter);
                }
                infoXmlWriter.Flush();
            }

            // Add the XML to the request.
            request.Parameters = infoXml.ToString();

            // Call the web-service
            request.Execute();

            // Now update the Id for the new item
            XPathNodeIterator thingIds =
                request.Response.InfoNavigator.Select(
                    GetThingIdXPathExpression(request.Response.InfoNavigator));

            int thingIndex = 0;
            foreach (XPathNavigator thingIdNav in thingIds)
            {
                if (items[thingIndex] != null)
                {
                    items[thingIndex].Key =
                        new HealthRecordItemKey(
                            new Guid(thingIdNav.Value),
                            new Guid(thingIdNav.GetAttribute(
                                    "version-stamp", String.Empty)));
                }
                thingIndex++;
            }
        }
        /// <summary>
        /// Disassociates an alternate ID with a record.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="alternateId">
        /// The alternate ID.
        /// </param>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The connection, accessor, or alternateId parameters are null.
        /// </exception>
        /// 
        /// <exception cref="ArgumentException">
        /// The alternateId parameter is empty, all whitespace, or more than 255 characters in length.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error. 
        /// If the alternate Id is not associated with a person and record id, the ErrorCode property
        /// will be set to AlternateIdNotFound.
        /// </exception>
        /// 
        public virtual void DisassociateAlternateId(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            string alternateId)
        {
            Validator.ThrowIfArgumentNull(connection, "connection", "AlternateIdConnectionNull");
            Validator.ThrowIfArgumentNull(accessor, "accessor", "AccessorNull");
            Validator.ThrowIfArgumentNull(alternateId, "alternateId", "AlternateIdNull");

            Validator.ThrowIfStringIsEmptyOrWhitespace(alternateId, "alternateId");
            Validator.ThrowArgumentExceptionIf(alternateId.Length > 255, "alternateId", "AlternateIdTooLong");

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "DisassociateAlternateId", 1, accessor);

            request.Parameters = "<alternate-id>" + alternateId + "</alternate-id>";
            request.Execute();
        }
コード例 #13
0
        /// <summary>
        /// Gets the health record items that match the filters as specified by 
        /// the properties of this class.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="searcher">
        /// The searcher that defines what items to return.
        /// </param>
        /// 
        /// <returns>
        /// An XmlReader representing the raw results of the search.
        /// </returns>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// <br/><br/>
        /// This method is typically used when the calling application wants to
        /// handle the raw health record item XML directly instead of using the 
        /// object model.
        /// </remarks>
        /// 
        public virtual XmlReader GetMatchingItemsReader(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            HealthRecordSearcher searcher)
        {
            HealthServiceRequest request = PrepareRequest(connection, accessor, searcher);
            request.Execute();

            return request.Response.InfoReader;
        }
コード例 #14
0
        /// <summary>
        /// Gets the request object including the necessary parameters for
        /// the "GetThings" request.
        /// </summary>
        /// 
        /// <returns>
        /// The request object for the thing search with the parameters filled
        /// in.
        /// </returns>
        /// 
        /// <exception cref="HealthServiceException">
        /// No filters have been specified.
        /// </exception>
        ///         
        private static HealthServiceRequest PrepareRequest(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            HealthRecordSearcher searcher)
        {
            HealthServiceRequest request =
                new HealthServiceRequest(connection, "GetThings", 3, accessor);

            request.Parameters = GetParametersXml(searcher);
            return request;
        }
コード例 #15
0
        /// <summary>
        /// Executes the search using the filters supplied.
        /// </summary>
        /// 
        /// <exception cref="HealthServiceException">
        /// The response from the server was anything but 
        /// HealthServiceStatusCode.OK, or no filters have been specified.
        /// </exception>
        ///         
        private static ReadOnlyCollection<HealthRecordItemCollection> Execute(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            HealthRecordSearcher searcher)
        {
            HealthServiceRequest request = PrepareRequest(connection, accessor, searcher);

            request.Execute();

            XmlReader infoReader = request.Response.InfoReader;

            Collection<HealthRecordItemCollection> result =
                new Collection<HealthRecordItemCollection>();

            if ((infoReader != null) && (infoReader.ReadToDescendant("group")))
            {
                while (infoReader.Name == "group")
                {
                    XmlReader groupReader = infoReader.ReadSubtree();

                    groupReader.MoveToContent();

                    HealthRecordItemCollection resultGroup =
                        HealthRecordItemCollection.CreateResultGroupFromResponse(
                            accessor,
                            groupReader,
                            searcher.Filters);

                    groupReader.Close();

                    // infoReader will normally be at the end element of
                    // the group at this point, and needs a read to get to
                    // the next element. If the group was empty, infoReader
                    // will be at the beginning of the group, and a
                    // single read will still move to the next element.
                    infoReader.Read();
                    if (resultGroup != null)
                    {
                        result.Add(resultGroup);
                    }
                }
            }

            return new ReadOnlyCollection<HealthRecordItemCollection>(result);
        }
コード例 #16
0
        /// <summary>
        /// Updates the specified health record items in one batch call to 
        /// the service.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="itemsToUpdate">
        /// The health record items to be updated.
        /// </param>
        /// 
        /// <remarks>
        /// Only new items are updated with the appropriate unique identifier. 
        /// All other sections must be updated manually.
        /// <br/><br/>
        /// This method accesses the HealthVault service across the network.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="itemsToUpdate"/> parameter is <b>null</b>.
        /// </exception>
        /// 
        /// <exception cref="ArgumentException">
        /// The <paramref name="itemsToUpdate"/> contains a <b>null</b> member or
        /// a <see cref="HealthRecordItem"/> instance that does not have an ID.
        /// </exception>
        ///
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error.
        /// The exception's Error property will contain the index of the
        /// item on which the failure occurred in the ErrorInfo property. If any failures occur, 
        /// no items will have been updated.
        /// </exception>
        /// 
        public virtual void UpdateItems(
            ApplicationConnection connection,
            HealthRecordAccessor accessor, 
            IList<HealthRecordItem> itemsToUpdate)
        {
            Validator.ThrowIfArgumentNull(itemsToUpdate, "itemsToUpdate", "UpdateItemsArgumentNull");

            StringBuilder infoXml = new StringBuilder(128);
            XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;

            bool somethingRequiresUpdate = false;

            using (XmlWriter infoXmlWriter =
                XmlWriter.Create(infoXml, settings))
            {
                foreach (HealthRecordItem item in itemsToUpdate)
                {
                    Validator.ThrowIfArgumentNull(item, "items", "UpdateItemsArgumentNull");

                    Validator.ThrowArgumentExceptionIf(
                        item.Key == null,
                        "itemsToUpdate",
                        "UpdateItemsWithNoId");

                    if (item.WriteItemXml(infoXmlWriter, false))
                    {
                        somethingRequiresUpdate = true;
                    }
                }
                infoXmlWriter.Flush();
            }

            if (somethingRequiresUpdate)
            {
                HealthServiceRequest request =
                    new HealthServiceRequest(connection, "PutThings", 2, accessor);

                // Add the XML to the request.
                request.Parameters = infoXml.ToString();

                // Call the web-service
                request.Execute();

                XPathNodeIterator thingIds =
                    request.Response.InfoNavigator.Select(
                        GetThingIdXPathExpression(request.Response.InfoNavigator));

                int index = 0;

                foreach (XPathNavigator thingIdNav in thingIds)
                {
                    HealthRecordItem thing = itemsToUpdate[index];
                    thing.Key = new HealthRecordItemKey(
                        new Guid(thingIdNav.Value),
                        new Guid(thingIdNav.GetAttribute(
                            "version-stamp", String.Empty)));
                    thing.ClearDirtyFlags();
                    ++index;
                }

            }
        }
コード例 #17
0
        /// <summary>
        /// Marks the specified health record item as deleted.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="itemsToRemove">
        /// The unique item identifiers of the items to remove.
        /// </param>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// <br/><br/>
        /// Health record items are never completely deleted. They are marked 
        /// as deleted and are ignored for most normal operations. Items can 
        /// be undeleted by contacting customer service.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentException">
        /// The <paramref name="itemsToRemove"/> parameter is empty.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// Errors removed the health record items from the server.
        /// The exception's Error property will contain the index of the
        /// item on which the failure occurred in the ErrorInfo property. If any failures occur, 
        /// no items will have been removed.
        /// </exception>
        /// 
        public virtual void RemoveItems(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            IList<HealthRecordItemKey> itemsToRemove)
        {
            Validator.ThrowArgumentExceptionIf(
                itemsToRemove == null || itemsToRemove.Count == 0,
                "itemsToRemove",
                "RemoveItemsListNullOrEmpty");

            StringBuilder parameters = new StringBuilder(128 * itemsToRemove.Count);
            for (int i = 0; i < itemsToRemove.Count; ++i)
            {
                parameters.Append("<thing-id version-stamp=\"");
                parameters.Append(itemsToRemove[i].VersionStamp);
                parameters.Append("\">");
                parameters.Append(itemsToRemove[i].Id);
                parameters.Append("</thing-id>");
            }

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "RemoveThings", 1, accessor);

            request.Parameters = parameters.ToString();
            request.Execute();
        }
コード例 #18
0
        /// <summary>
        /// Removes the saved open query from the server.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection instance to use to remove the <see cref="OpenQuery"/>.
        /// </param>
        /// 
        /// <param name="id">
        /// The id of the open query to remove.
        /// </param>
        /// 
        /// <remarks>
        /// The person authenticated with the <paramref name="connection"/> 
        /// must have permission to remove the open query.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The <paramref name="connection"/> parameter is <b>null</b>.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// An error occurred when HealthVault processed the request.
        /// </exception>
        /// 
        public virtual void RemoveOpenQuery(
            ApplicationConnection connection,
            Guid id)
        {
            Validator.ThrowIfArgumentNull(connection, "connection", "NewQueryNullService");
            Validator.ThrowArgumentExceptionIf(
                id == Guid.Empty,
                "id",
                "QueryIdInvalid");

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "DeleteOpenQuery", 1);

            request.Parameters = "<query-id>" + id.ToString() + "</query-id>";
            request.Execute();
        }
        /// <summary>
        /// Gets the person and record IDs that were previosly associated
        /// with an alternate ID.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="alternateId">
        /// The alternate ID.
        /// </param>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// The connection, accessor, or alternateId parameters are null
        /// </exception>
        /// 
        /// <exception cref="ArgumentException">
        /// The alternateId parameter is empty, all whitespace, or more than 255 characters in length.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error. 
        /// If the alternate Id is not associated with a person and record id, the ErrorCode property
        /// will be set to AlternateIdNotFound.
        /// </exception>
        /// 
        public virtual PersonInfo GetPersonAndRecordForAlternateId(
            ApplicationConnection connection,
            string alternateId)
        {
            Validator.ThrowIfArgumentNull(connection, "connection", "AlternateIdConnectionNull");
            Validator.ThrowIfArgumentNull(alternateId, "alternateId", "AlternateIdNull");

            Validator.ThrowIfStringIsEmptyOrWhitespace(alternateId, "alternateId");
            Validator.ThrowArgumentExceptionIf(alternateId.Length > 255, "alternateId", "AlternateIdTooLong");

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "GetPersonAndRecordForAlternateId", 1);

            request.Parameters = "<alternate-id>" + alternateId + "</alternate-id>";

            request.Execute();

            XPathNavigator infoNav = request.Response.InfoNavigator.SelectSingleNode(
                        SDKHelper.GetInfoXPathExpressionForMethod(
                                request.Response.InfoNavigator,
                                "GetPersonAndRecordForAlternateId"));

            XPathNavigator personInfoNav = infoNav.SelectSingleNode("person-info");

            return PersonInfo.CreateFromXml(connection, personInfoNav);
        }
コード例 #20
0
        /// <summary>
        /// Gets the health record items specified by the 
        /// <see cref="HealthRecordSearcher"/> and runs them through the specified 
        /// transform.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="searcher">
        /// The searcher that defines what items to return.
        /// </param>
        /// 
        /// <param name="transform">
        /// A URL to a transform to run on the resulting XML. This can be
        /// a fully-qualified URL or the name of one of the standard XSLs
        /// provided by the HealthVault system.
        /// </param>
        /// 
        /// <returns>
        /// The string resulting from performing the specified transform on
        /// the XML representation of the items.
        /// </returns>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// <br/><br/>
        /// Any call to HealthVault may specify a transform to be run on the
        /// response XML. The transform can be specified as a XSL fragment or
        /// a well-known transform tag provided by the HealthVault service. If a
        /// XSL fragment is specified, it gets compiled and cached on the server.
        /// <br/>
        /// <br/>
        /// A final-xsl is useful when you want to convert the result from XML to
        /// HTML so that you can display the result directly in a web page.
        /// You may also use it to generate other data formats like CCR, CCD, CSV,
        /// RSS, etc.
        /// <br/>
        /// <br/>
        /// Transform fragments cannot contain embedded script. The following set
        /// of parameters are passed to all final-xsl transforms:<br/>
        /// <ul>
        ///     <li>currentDateTimeUtc - the date and time just before the transform 
        ///     started executing</li>
        ///     <li>requestingApplicationName - the name of the application that
        ///     made the request to HealthVault.</li>
        ///     <li>countryCode - the ISO 3166 country code from the request.</li>
        ///     <li>languageCode - the ISO 639-1 language code from the request.</li>
        ///     <li>personName - the name of the person making the request.</li>
        ///     <li>recordName - if the request identified a HealthVault record to 
        ///     be used, this parameter contains the name of that record.</li>
        /// </ul>
        /// </remarks>
        /// 
        /// <exception cref="ArgumentException">
        /// The <paramref name="transform"/> parameter is <b>null</b> or empty.
        /// </exception>
        /// 
        /// <exception cref="ArgumentException">
        /// <see cref="Microsoft.Health.HealthRecordView.Sections"/> does not
        /// contain the XML section in the view.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// There is a failure retrieving the items.
        /// -or-
        /// No filters have been specified.
        /// </exception>
        /// 
        public virtual string GetTransformedItems(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            HealthRecordSearcher searcher,
            string transform)
        {
            Validator.ThrowIfStringNullOrEmpty(transform, "transform");

            HealthServiceRequest request = PrepareRequest(connection, accessor, searcher);

            return request.ExecuteForTransform(transform);
        }
        /// <summary>
        /// Gets the list of alternate IDs that are associated with a record.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <remarks>
        /// This method accesses the HealthVault service across the network.
        /// </remarks>
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error. 
        /// If the alternate Id is not associated with a person and record id, the ErrorCode property
        /// will be set to AlternateIdNotFound.
        /// </exception>
        /// 
        public virtual Collection<string> GetAlternateIds(
            ApplicationConnection connection,
            HealthRecordAccessor accessor)
        {
            HealthServiceRequest request =
                new HealthServiceRequest(connection, "GetAlternateIds", 1, accessor);

            request.Execute();

            Collection<string> alternateIds = new Collection<string>();

            XPathNavigator infoNav = request.Response.InfoNavigator.SelectSingleNode(
                        SDKHelper.GetInfoXPathExpressionForMethod(
                                request.Response.InfoNavigator,
                                "GetAlternateIds"));

            // Get the alternate ids that came back
            XPathNodeIterator alternateIdsNav = infoNav.Select("alternate-ids/alternate-id");

            foreach (XPathNavigator alternateIdNode in alternateIdsNav)
            {
                alternateIds.Add(alternateIdNode.Value);
            }

            return alternateIds;
        }
        /// <summary>
        /// Gets information about people authorized for an application.
        /// </summary>                
        /// 
        /// <remarks>
        /// The returned IEnumerable iterator will access the HealthVault service 
        /// across the network. See <see cref="GetAuthorizedPeopleSettings"/> for applicable 
        /// settings.
        /// </remarks>
        /// 
        /// <param name="connection">The connection to use to perform the operation. This connection
        /// must be application-level. </param>
        ///
        /// <param name="settings">
        /// The <see cref="GetAuthorizedPeopleSettings" /> object used to configure the 
        /// IEnumerable iterator returned by this method.
        /// </param>
        /// 
        /// <returns>
        /// An IEnumerable iterator of <see cref="PersonInfo"/> objects representing 
        /// people authorized for the application.
        /// </returns>        
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returned an error. The retrieval can be retried from the 
        /// current position by calling this method again and using the last successfully 
        /// retrieved person Id for <see cref="GetAuthorizedPeopleSettings.StartingPersonId"/>.        
        /// </exception>
        /// 
        /// <exception cref="ArgumentNullException">
        /// <paramref name="settings"/> is null.
        /// </exception>
        /// 
        public virtual IEnumerable<PersonInfo> GetAuthorizedPeople(
            ApplicationConnection connection,
            GetAuthorizedPeopleSettings settings)
        {
            Validator.ThrowIfArgumentNull(settings, "settings", "GetAuthorizedPeopleSettingsNull");

            Boolean moreResults = true;
            Guid cursor = settings.StartingPersonId;
            DateTime authCreatedSinceDate = settings.AuthorizationsCreatedSince;
            Int32 batchSize = settings.BatchSize;

            while (moreResults)
            {
                Collection<PersonInfo> personInfos =
                    GetAuthorizedPeople(
                        connection,
                        cursor,
                        authCreatedSinceDate,
                        batchSize,
                        out moreResults);

                if (personInfos.Count > 0)
                {
                    cursor = personInfos[personInfos.Count - 1].PersonId;
                }

                for (int i = 0; i < personInfos.Count; i++)
                {
                    yield return personInfos[i];
                }
            }
        }
コード例 #23
0
        /// <summary>
        /// Gets the <see cref="HealthRecordInfo"/> for the records identified
        /// by the specified <paramref name="recordIds"/>.
        /// </summary>
        /// 
        /// <param name="connection">The connection to use to perform the operation. This connection
        /// must be authenticated. </param>
        ///
        /// <param name="recordIds">
        /// The unique identifiers for the records to retrieve.
        /// </param>
        /// 
        /// <returns>
        /// A collection of the records matching the specified record 
        /// identifiers and authorized for the authenticated person.
        /// </returns>
        /// 
        /// <remarks>
        /// This method is useful in cases where the application is storing
        /// record identifiers and needs access to the functionality provided
        /// by the object model.
        /// </remarks>
        /// 
        public virtual Collection<HealthRecordInfo> GetAuthorizedRecords(
            ApplicationConnection connection,
            IList<Guid> recordIds)
        {
            HealthServiceRequest request =
                new HealthServiceRequest(connection, "GetAuthorizedRecords", 1);

            StringBuilder parameters = new StringBuilder(128);
            foreach (Guid id in recordIds)
            {
                parameters.Append(
                    "<id>" + id.ToString() + "</id>");
            }
            request.Parameters = parameters.ToString();

            request.Execute();

            Collection<HealthRecordInfo> results =
                new Collection<HealthRecordInfo>();

            XPathNodeIterator records =
                request.Response.InfoNavigator.Select(
                    GetRecordXPathExpression(request.Response.InfoNavigator));

            foreach (XPathNavigator recordNav in records)
            {
                results.Add(HealthRecordInfo.CreateFromXml(connection, recordNav));
            }
            return results;
        }
        internal static Collection<PersonInfo> GetAuthorizedPeople(
            ApplicationConnection connection,
            Guid personIdCursor,
            DateTime authCreatedSinceDate,
            Int32 numResults,
            out Boolean moreResults)
        {
            Validator.ThrowArgumentOutOfRangeIf(
                numResults < 0,
                "numResults",
                "GetAuthorizedPeopleNumResultsNegative");

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "GetAuthorizedPeople", 1);
            StringBuilder requestParameters = new StringBuilder(256);
            XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;
            settings.OmitXmlDeclaration = true;
            settings.ConformanceLevel = ConformanceLevel.Fragment;

            using (XmlWriter writer = XmlWriter.Create(requestParameters, settings))
            {
                writer.WriteStartElement("parameters");

                if (personIdCursor != Guid.Empty)
                {
                    writer.WriteElementString("person-id-cursor", personIdCursor.ToString());
                }

                if (authCreatedSinceDate != DateTime.MinValue)
                {
                    writer.WriteElementString(
                        "authorizations-created-since",
                        SDKHelper.XmlFromDateTime(authCreatedSinceDate));
                }

                if (numResults != 0)
                {
                    writer.WriteElementString("num-results", numResults.ToString(CultureInfo.InvariantCulture));
                }

                writer.WriteEndElement(); // parameters
                writer.Flush();
            }
            request.Parameters = requestParameters.ToString();

            request.Execute();

            Collection<PersonInfo> personInfos = new Collection<PersonInfo>();

            XPathExpression navExp =
                 SDKHelper.GetInfoXPathExpressionForMethod(
                     request.Response.InfoNavigator, "GetAuthorizedPeople");
            XPathNavigator infoNav = request.Response.InfoNavigator.SelectSingleNode(navExp);
            XPathNavigator nav = infoNav.SelectSingleNode("response-results/person-info");

            if (nav != null)
            {
                do
                {
                    PersonInfo personInfo = PersonInfo.CreateFromXml(connection, nav);
                    personInfos.Add(personInfo);

                } while (nav.MoveToNext("person-info", String.Empty));

                nav.MoveToNext();
            }
            else
            {
                nav = infoNav.SelectSingleNode("response-results/more-results");
            }

            moreResults = nav.ValueAsBoolean;

            return personInfos;
        }
コード例 #25
0
        /// <summary>
        /// Gets valid group memberships for a record.
        /// </summary>
        /// 
        /// <remarks>
        /// Group membership thing types allow an application to signify that the
        /// record belongs to an application defined group.  A record in the group may be 
        /// eligible for special programs offered by other applications, for example.  
        /// Applications then need a away to query for valid group memberships.
        /// <br/>
        /// Valid group memberships are those memberships which are not expired, and whose
        /// last updating application is authorized by the the last updating person to 
        /// read and delete the membership.
        /// </remarks>
        /// 
        /// <param name="connection">
        /// The connection to use to access the data.
        /// </param>
        /// 
        /// <param name="accessor">
        /// The record to use.
        /// </param>
        /// 
        /// <param name="applicationIds">
        /// A collection of unique application identifiers for which to 
        /// search for group memberships.  For a null or empty application identifier 
        /// list, return all valid group memberships for the record.  Otherwise, 
        /// return only those group memberships last updated by one of the 
        /// supplied application identifiers.
        /// </param>
        /// 
        /// <returns>
        /// A List of HealthRecordItems representing the valid group memberships.
        /// </returns>
        /// <exception cref="HealthServiceException">
        /// If an error occurs while contacting the HealthVault service.
        /// </exception>
        public virtual Collection<HealthRecordItem> GetValidGroupMembership(
            ApplicationConnection connection,
            HealthRecordAccessor accessor,
            IList<Guid> applicationIds)
        {
            StringBuilder parameters = new StringBuilder(128);
            if (applicationIds != null)
            {
                XmlWriterSettings settings = SDKHelper.XmlUnicodeWriterSettings;
                XmlWriter writer = null;
                try
                {
                    writer = XmlWriter.Create(parameters, settings);
                    for (int i = 0; i < applicationIds.Count; i++)
                    {
                        writer.WriteElementString(
                            "application-id",
                            applicationIds[i].ToString());
                    }
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Flush();
                        writer.Close();
                    }
                    writer = null;
                }
            }

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "GetValidGroupMembership", 1, accessor);

            request.Parameters = parameters.ToString();
            request.Execute();

            XPathExpression infoPath =
                SDKHelper.GetInfoXPathExpressionForMethod(
                    request.Response.InfoNavigator,
                    "GetValidGroupMembership");

            XPathNavigator infoNav =
                request.Response.InfoNavigator.SelectSingleNode(infoPath);

            Collection<HealthRecordItem> memberships = new Collection<HealthRecordItem>();

            XPathNodeIterator membershipIterator = infoNav.Select("thing");
            if (membershipIterator != null)
            {
                foreach (XPathNavigator membershipNav in membershipIterator)
                {
                    memberships.Add(ItemTypeManager.DeserializeItem(membershipNav.OuterXml));
                }
            }

            return memberships;
        }
        /// <summary>
        /// Updates the application's configuration in HealthVault.
        /// </summary>
        /// 
        /// <param name="connection">
        /// The connection to use to make the update.
        /// </param>
        /// 
        /// <param name="applicationInfo">
        /// The <see cref="ApplicationInfo"/> to update.
        /// </param>
        /// 
        /// <remarks>
        /// This method makes a remote call to the HealthVault service.
        /// The calling application in the <paramref name="connection"/> must be the same as
        /// the application specified by this ApplicationInfo instance or its master application.
        /// Note, this update will replace all configuration elements for the application. It is 
        /// advised that <see cref="ApplicationProvisioning.Provisioner.GetApplication"/> is 
        /// called to retrieve the existing application configuration before changing values and 
        /// calling Update.
        /// </remarks>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="connection"/> is <b>null</b>.
        /// </exception>
        /// 
        /// <exception cref="HealthServiceException">
        /// The HealthVault service returns an error.
        /// </exception>
        /// 
        public virtual void UpdateChildApplication(
            ApplicationConnection connection,
            ApplicationInfo applicationInfo)
        {
            Validator.ThrowIfArgumentNull(connection, "connection", "ProvisionerNullConnection");
            Validator.ThrowInvalidIf(applicationInfo.Id == Guid.Empty, "ProvisionerEmptyAppId");

            HealthServiceRequest request =
                new HealthServiceRequest(connection, "UpdateApplication", 2);

            request.Parameters = applicationInfo.GetRequestParameters(applicationInfo.Id);
            request.Execute();
        }