/// <summary>
        /// Makes a call to the Health REST service to edit another user who has authorized this application.
        /// This is the type of call that a hospital would make on the behalf of a patient.
        /// </summary>
        public static HealthServiceRestResponseData CallHeathServiceRestOffline(Guid personId, Guid recordId, PersonInfo loggedInPersonInfo, string httpVerb, string path, NameValueCollection queryStringParameters = null, string requestBody = null, NameValueCollection optionalHeaders = null)
        {
            CheckOfflineAuthorization(loggedInPersonInfo);

            // Person and record ID identify the patient for whom to retrieve the plans.
            var connection = new OfflineWebApplicationConnection(
                HealthWebApplicationConfiguration.Current.ApplicationId,
                HealthWebApplicationConfiguration.Current.HealthVaultMethodUrl,
                personId);

            // Authenticate with HealthVault using the connection generated above
            connection.Authenticate();

            // Using the HealthVault SDK, make a HTTP call.
            // The root URL comes from the web.config (RestHealthServiceUrl).
            var request = new HealthServiceRestRequest(
                connection,
                httpVerb,
                path,
                queryStringParameters,
                requestBody,
                optionalHeaders: optionalHeaders)
            {
                // Person and record ID identify the patient for whom to retrieve the plans.
                RecordId = recordId
            };

            request.Execute();

            return(request.Response);
        }
Ejemplo n.º 2
0
        // Calls HealthVault to a View, Download, Transmit report
        private string GetVDTReports()
        {
            DateTime reportStart = DateTime.MinValue;
            DateTime reportEnd   = DateTime.MaxValue;

            if (!string.IsNullOrWhiteSpace(tbReportStart.Text) && !DateTime.TryParse(tbReportStart.Text.Trim(), out reportStart))
            {
                OutputMessage(lblErrorOutput, "Invalid reporting period start date. Please specify a date in mm/dd/yyyy format.");
                return(null);
            }

            if (!string.IsNullOrWhiteSpace(tbReportEnd.Text) && !DateTime.TryParse(tbReportEnd.Text.Trim(), out reportEnd))
            {
                OutputMessage(lblErrorOutput, "Invalid reporting period end date. Please specify a date in mm/dd/yyyy format.");
                return(null);
            }

            DateRange dateFilter = new DateRange(reportStart, reportEnd);
            OfflineWebApplicationConnection connection = new OfflineWebApplicationConnection(HealthWebApplicationConfiguration.Current.ApplicationId,
                                                                                             HealthWebApplicationConfiguration.Current.HealthVaultMethodUrl,
                                                                                             Guid.Empty);
            IEnumerable <PatientActivity> resultActivities = connection.GetMeaningfulUseVDTReport(dateFilter);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(string.Join(",", "Report Start = " + reportStart.ToString(), "Report End = " + reportEnd.ToString()));
            sb.AppendLine(string.Join(",", "Source", "PatientID", "Organization"));
            foreach (PatientActivity p in resultActivities)
            {
                sb.AppendLine(string.Join(",", p.Source, p.PatientId, p.OrganizationId));
            }

            return(sb.ToString());
        }
        public static List <string> GetThings(OfflineWebApplicationConnection connection,
                                              Guid recordId, Guid[] typeIds, DateTime updatedSinceUtc)
        {
            HealthRecordAccessor record   = new HealthRecordAccessor(connection, recordId);
            HealthRecordSearcher searcher = record.CreateSearcher();
            HealthRecordFilter   filter   = new HealthRecordFilter();

            searcher.Filters.Add(filter);

            foreach (Guid typeId in typeIds)
            {
                filter.TypeIds.Add(typeId);
            }

            filter.UpdatedDateMin = DateTime.SpecifyKind(updatedSinceUtc, DateTimeKind.Utc);

            filter.View.Sections = HealthRecordItemSections.All | Microsoft.Health.HealthRecordItemSections.Xml;

            //HealthRecordItemSections.Core |
            //HealthRecordItemSections.Xml |
            //HealthRecordItemSections.Audits;

            HealthRecordItemCollection things = searcher.GetMatchingItems()[0];

            List <string> items = new List <string>();

            foreach (HealthRecordItem thing in things)
            {
                items.Add(thing.GetItemXml(filter.View.Sections));
            }
            return(items);
        }
        public static void PutThings(OfflineWebApplicationConnection connection, Guid recordId, ref HealthRecordItem newItem)
        {
            HealthRecordAccessor record = new HealthRecordAccessor(connection, recordId);

            record.NewItem(newItem);
            return;
        }
Ejemplo n.º 5
0
        public static JObject GetAllThings(Guid personId, Guid recordId)
        {
            Guid appId = new Guid(Connections.ApplicationId);
            OfflineWebApplicationConnection connection = Connections.CreateConnection(appId, personId);

            HealthRecordAccessor accessor = new HealthRecordAccessor(connection, recordId);
            HealthRecordSearcher searcher = new HealthRecordSearcher(accessor);

            List <Guid> queryOrder = Types.TypeDefinitions.Keys.ToList();

            queryOrder.Add(CustomType.Id);

            foreach (Guid thingType in queryOrder)
            {
                HealthRecordFilter filter = new HealthRecordFilter(thingType);
                if (thingType.Equals(CustomType.Id) || (Types.TypeDefinitions.ContainsKey(thingType) && !Types.TypeDefinitions[thingType].Persistent))
                {
                    filter.EffectiveDateMin = GetMinTime();
                }
                searcher.Filters.Add(filter);
            }

            ReadOnlyCollection <HealthRecordItemCollection> things = searcher.GetMatchingItems();

            return(TransformThings(things, queryOrder));
        }
Ejemplo n.º 6
0
    /// <summary>
    /// Create Offline Web Application Connection
    /// </summary>
    /// <param name="applicationId">Application ID used for creating the offline connection</param>
    /// <returns>reference to OfflineWebApplicationConnection </returns>
    public static OfflineWebApplicationConnection CreateConnection(Guid applicationId)
    {
        OfflineWebApplicationConnection offlineConn = new OfflineWebApplicationConnection(applicationId,
                                                                                          WebApplicationConfiguration.HealthServiceUrl, Guid.Empty);

        offlineConn.Authenticate();
        return(offlineConn);
    }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        public static void PurgeCustomData(Guid personId, Guid recordId)
        {
            Guid appId = new Guid(Connections.ApplicationId);
            OfflineWebApplicationConnection connection = Connections.CreateConnection(appId, personId);

            HealthRecordAccessor accessor = new HealthRecordAccessor(connection, recordId);

            foreach (ApplicationSpecific item in accessor.GetItemsByType(ApplicationSpecific.TypeId))
            {
                accessor.RemoveItem(item);
            }
        }
Ejemplo n.º 9
0
    /// <summary>
    /// Create a participant code. A participant can authorize this application by entering this code
    /// on HealthVault and answering the security question
    /// </summary>
    /// <param name="friendlyName">Participant's Name</param>
    /// <param name="securityQuestion">Security question</param>
    /// <param name="securityAnswer">Security Answer</param>
    /// <param name="applicationPatientId">Application Specific ID for Participant</param>
    /// <returns>Returns 20 digit identity code</returns>
    public static string CreateParticipantIdentityCode(string friendlyName,
                                                       string securityQuestion,
                                                       string securityAnswer,
                                                       string applicationPatientId)
    {
        Guid applicationId = new Guid(ApplicationId);
        OfflineWebApplicationConnection offlineConnection = CreateConnection(applicationId);
        string identityCode = string.Empty;

        identityCode = PatientConnection.Create(offlineConnection, friendlyName, securityQuestion, securityAnswer, null, applicationPatientId);
        return(identityCode);
    }
Ejemplo n.º 10
0
    /// <summary>
    /// Get all the application authorizatons that happend in last n days as specified by the pastDays parameter.
    /// pastDays is set to 0, this function gets ALL the validatations that has happend to date.
    /// </summary>
    /// <param name="pastDays">Specify the last number of days since when the validations needs to be fetched. Specify 0 to fetch all validations</param>
    /// <returns></returns>
    public static Collection <ValidatedPatientConnection> GetValidatedConnectionsInPastDays(int pastDays)
    {
        Guid appId = new Guid(ApplicationId);
        OfflineWebApplicationConnection offlineConnection = CreateConnection(appId);


        if (pastDays > 0)
        {
            DateTime dtSince = DateTime.Now.AddDays(-1 * pastDays);
            return(PatientConnection.GetValidatedConnections(offlineConnection, dtSince));
        }

        return(PatientConnection.GetValidatedConnections(offlineConnection));
    }
Ejemplo n.º 11
0
 public HealthVaultConnection(string token, Guid personId)
 {
     if (AppSettings.IsValidToken(token))
     {
         _connection = new OfflineWebApplicationConnection(HealthWebApplicationConfiguration.Current.ApplicationId,
                                                           HealthWebApplicationConfiguration.Current.HealthVaultMethodUrl,
                                                           personId);
         _connection.Authenticate();
     }
     else
     {
         throw (new ArgumentException("Your application token is invalid.", "token"));
     }
 }
Ejemplo n.º 12
0
        static void Main(string[] args)
        {
            var                      appSettings = ConfigurationManager.AppSettings;
            Guid                     appId       = new Guid(appSettings["ApplicationId"]);
            var                      certbytes   = System.IO.File.ReadAllBytes(ConfigurationManager.AppSettings["ApplicationCertificateFilename"]);
            X509Certificate2         cert        = new X509Certificate2(certbytes, ConfigurationManager.AppSettings["AppCertPassword"]);
            WebApplicationCredential cred        = new WebApplicationCredential(appId, cert);

            OfflineWebApplicationConnection connection = new OfflineWebApplicationConnection(cred, Guid.Empty);
            string id = CHBase.SDK.PatientConnect.PatientConnection.Create(connection, "John Doe", "Question", "Answer", null, "some-patient-id");

            Console.WriteLine(id);
            Console.ReadKey();
        }
Ejemplo n.º 13
0
        public static string DropOffToPatient(OfflineWebApplicationConnection connection,
                                              string fromName,
                                              string localPatientId,
                                              string secretQuestion,
                                              string secretAnswer,
                                              ref List<HealthRecordItem> newItems)
        {
            ConnectPackageCreationParameters parameters = new ConnectPackageCreationParameters(connection,
                                                                fromName,
                                                                secretQuestion,
                                                                secretAnswer,
                                                                localPatientId);

            String secretCode = ConnectPackage.Create(parameters, newItems);
            return (secretCode);
        }
        /// <summary>
        /// Gets a list of people who have authorized this application to access their data.
        /// </summary>
        private List <PersonInfo> GetAuthorizedPeople()
        {
            HealthServiceRestHelper.CheckOfflineAuthorization(User.PersonInfo());

            var connection = new OfflineWebApplicationConnection(
                HealthWebApplicationConfiguration.Current.ApplicationId,
                HealthWebApplicationConfiguration.Current.HealthVaultMethodUrl,
                Guid.Empty);

            // Authenticate with HealthVault using the certificate generated above
            connection.Authenticate();

            // Iterate through all authorized users
            var people = connection.GetAuthorizedPeople().ToList();

            return(people);
        }
Ejemplo n.º 15
0
        private void ContributeCCDAViaDOPU()
        {
            OfflineWebApplicationConnection connection = new OfflineWebApplicationConnection(HealthWebApplicationConfiguration.Current.ApplicationId,
                                                                                             HealthWebApplicationConfiguration.Current.HealthVaultMethodUrl,
                                                                                             Guid.Empty);

            connection.Authenticate();
            string packageId = ConnectPackage.Create(connection, "friendly name", _DOPUQuestion, _DOPUAnswer, "patientID", new[] { _newCcdaItem });

            Uri pickupUrl = new Uri(HealthApplicationConfiguration.Current.HealthVaultShellUrl, "patientwelcome.aspx?packageid=" + packageId);

            OutputMessage(lblSuccessOutput, "Successfully sent a DOPU package containing CCDA document to HealthVault. Visit the following URL to add the CCDA to a HealthVault record:");

            HyperLink link = new HyperLink();

            link.Text        = pickupUrl.ToString();
            link.NavigateUrl = pickupUrl.ToString();
            link.Target      = "_blank";
            divSuccess.Controls.Add(link);
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            Guid appId    = new Guid(ConfigurationManager.AppSettings["ApplicationId"]);
            Guid personID = new Guid(ConfigurationManager.AppSettings["PersonID"]);

            var certbytes         = System.IO.File.ReadAllBytes(ConfigurationManager.AppSettings["ApplicationCertificateFilename"]);
            X509Certificate2 cert = new X509Certificate2(certbytes, ConfigurationManager.AppSettings["AppCertPassword"]);

            WebApplicationCredential        cred       = new WebApplicationCredential(appId, cert);
            OfflineWebApplicationConnection connection = new OfflineWebApplicationConnection(cred, personID);
            PersonInfo personInfo = connection.GetPersonInfo();

            AddRandomHeightEntry(personInfo);
            var items = ReadHeight(personInfo);

            foreach (var item in items[0])
            {
                Console.WriteLine("Heights :");
                Console.WriteLine(((Height)item).Value.ToString());
            }

            Console.ReadKey();
        }
Ejemplo n.º 17
0
        private void ContributeCCDAViaRecordAuthorization()
        {
            // Note: Applications can store the HealthVault personID and recordID and use this to make offline requests to store new information
            // in the patient's record whenever new data is available. In this sample, since we don't maintain offline storage (i.e. a DB) to associate
            // the data source organization's patient identifier with the HealthVault person and record ID, we instead sign-in the user to determine the
            // person and record ID everytime a request to send a new CCDA to HealthVault happens (i.e. clicking the "Send CCDA to HealthVault" button);

            PersonInfo pi = WebApplicationUtilities.LoadPersonInfoFromCookie(HttpContext.Current);

            if (pi == null)
            {
                OutputMessage(lblErrorOutput, "Must login first");
                return;
            }

            // Make the offline call to stor the CCDA in the patient's HealthVault record.
            OfflineWebApplicationConnection connection      = new OfflineWebApplicationConnection(pi.PersonId);
            HealthRecordAccessor            receordAccessor = new HealthRecordAccessor(connection, pi.SelectedRecord.Id);

            receordAccessor.NewItem(_newCcdaItem);

            OutputMessage(lblSuccessOutput, "Successfully sent CCDA document to HealthVault via Record Authorization.");
        }
Ejemplo n.º 18
0
 public static string AllocatePackageId(OfflineWebApplicationConnection connection)
 {
     return (ConnectPackage.AllocatePackageId(connection));
 }
Ejemplo n.º 19
0
 public static void DeletePendingForPackageId(OfflineWebApplicationConnection connection, string packageId)
 {
     ConnectPackage.DeletePendingForIdentityCode(connection, packageId);
 }
Ejemplo n.º 20
0
 public static void DeletePendingForPatientId(OfflineWebApplicationConnection connection, string PatientId)
 {
     ConnectPackage.DeletePending(connection, PatientId);
 }