private bool GetDocumentId(string IHI, out string documentId, out string repositoryId) { // Obtain the certificate for use with TLS and signing X509Certificate2 cert = X509CertificateUtil.GetCertificate( "Serial Number", X509FindType.FindBySerialNumber, StoreName.My, StoreLocation.CurrentUser, true ); // Create PCEHR header CommonPcehrHeader header = PcehrHeaderHelper.CreateHeader(); // Instantiate the client GetDocumentListClient documentListClient = new GetDocumentListClient(new Uri("https://GetDocumentListEndpoint"), cert, cert); // Add server certificate validation callback ServicePointManager.ServerCertificateValidationCallback += ValidateServiceCertificate; // Create a query AdhocQueryBuilder adhocQueryBuilder = new AdhocQueryBuilder(IHI, new[] { DocumentStatus.Approved }); // Reduce documents returned to just SHS from yesterday onwards (Medicines View will always be returned in this query) // as cannot filter on Medicines View as a document adhocQueryBuilder.ClassCode = new List <ClassCodes>(); adhocQueryBuilder.ClassCode.Add(ClassCodes.SharedHealthSummary); adhocQueryBuilder.ServiceStopTimeFrom = new ISO8601DateTime(Convert.ToDateTime(DateTime.Now).AddDays(-1)); // Create the request using the query AdhocQueryRequest queryRequest = adhocQueryBuilder.BuildRequest(); // Initialise repositoryId = ""; documentId = ""; try { // Invoke the service AdhocQueryResponse queryResponse = documentListClient.GetDocumentList(header, queryRequest); if (queryResponse != null && queryResponse.status == "urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success" && queryResponse.RegistryObjectList != null) { const string XDS_DOCUMENT_ENTRY_CLASS_CODE = "urn:uuid:41a5887f-8865-4c09-adf7-e362475b143a"; const string XDS_DOCUMENT_ENTRY_UNIQUE_ID = "urn:uuid:2e82c1f6-a085-4c72-9da3-8640a32e42ab"; const string NCTIS_CLASS_CODE_MEDS_VIEW = "100.32002"; //Loop through responses foreach (var entry in queryResponse.RegistryObjectList.ExtrinsicObject) { var classification = entry.Classification.FirstOrDefault(o => o.classificationScheme == XDS_DOCUMENT_ENTRY_CLASS_CODE); if (classification != null && classification.nodeRepresentation == NCTIS_CLASS_CODE_MEDS_VIEW) { // Get Values var repid = entry.Slot.FirstOrDefault(o => o.name == "repositoryUniqueId"); var docId = entry.ExternalIdentifier.FirstOrDefault(o => o.identificationScheme == XDS_DOCUMENT_ENTRY_UNIQUE_ID); // Set Values repositoryId = (repid != null ? repid.ValueList.Value[0] : ""); documentId = (docId != null ? docId.value : ""); break; } } } return(true); } catch (FaultException e) { // Handle any errors return(false); } }
public void Run() { // NASH certificate should be used here, NOT the HI certificate the NASH certificate can be found in the NASH PKI Test Kit // certificate needs to be installed in the right place // The "Issue To" field of a NASH certificate looks like general (or something different)."HPI-O".electronichealth.net.au // "Serial Number" can be found in the details once the certificate is installed.e.g. in Windows, certificates can be found in Certs.msc //Get Certificate and Header objects CertAndHeaderInfo CertAndHeaderInfo = Support.CertAndHeaderFactory.Get( certSerial: "06fba6", serialHPIO: "8003629900019338", patientType: Support.PatientType.FrankHarding); // Obtain the certificate for use with TLS and signing X509Certificate2 cert = CertAndHeaderInfo.Certificate; // Create PCEHR header CommonPcehrHeader header = CertAndHeaderInfo.Header; // Instantiate the client // SVT endpoint is "https://b2b.ehealthvendortest.health.gov.au/getDocumentList" // production endpoint is "https://services.ehealth.gov.au/getDocumentList" GetDocumentListClient documentListClient = new GetDocumentListClient(new Uri("https://b2b.ehealthvendortest.health.gov.au/getDocumentList"), cert, cert); // Add server certificate validation callback ServicePointManager.ServerCertificateValidationCallback += Support.CertificateHelper.ValidateServiceCertificate; // Create a query AdhocQueryBuilder adhocQueryBuilder = new AdhocQueryBuilder(header.IhiNumber, new[] { DocumentStatus.Approved }); adhocQueryBuilder.ServiceStartTimeFrom = new ISO8601DateTime(new DateTime(2018, 03, 18)); adhocQueryBuilder.ServiceStopTimeTo = new ISO8601DateTime(new DateTime(2020, 07, 17)); adhocQueryBuilder.ClassCode = new List <ClassCodes>() { ClassCodes.AdvanceCareDirectiveCustodianRecord, ClassCodes.AdvanceCareInformation }; //adhocQueryBuilder.TypeCode = new List<ClassCodes>() //{ // ClassCodes.AdvanceCareDirectiveCustodianRecord, // ClassCodes.AdvanceCareInformation //}; // To further filter documents, build on the adhocQueryBuilder helper functions // For example, filtering on document type //adhocQueryBuilder.ClassCode = new List<ClassCodes>() {ClassCodes.AdvanceCareInformation}; // See Table 3 XDSDocumentEntry Document Type and Class Code value set from // the Document Exchange Service Technical Service Specification // Create the request using the query AdhocQueryRequest queryRequest = adhocQueryBuilder.BuildRequest(); try { // Invoke the service AdhocQueryResponse queryResponse = documentListClient.GetDocumentList(header, queryRequest); // Get the soap request and response string soapRequest = documentListClient.SoapMessages.SoapRequest; string soapResponse = documentListClient.SoapMessages.SoapResponse; // Process data into a more simple model if (queryResponse.RegistryObjectList.ExtrinsicObject == null) { Console.WriteLine($"Total Documents: 0"); } else { XdsRecord[] data = XdsMetadataHelper.ProcessXdsMetadata(queryResponse.RegistryObjectList.ExtrinsicObject); int UseTimeZone = 11; // For displaying the data in a list Console.WriteLine($"Total Documents {data.Count().ToString()}"); Console.WriteLine($"{"Document Date".PadRight(23)} | {"Service Date".PadRight(23)} | {"Document".PadRight(35)} | {"Org".PadRight(35)} | {"Org Type".PadRight(35)}|"); Console.WriteLine($"================================================================================================================================================================================"); foreach (var row in data.OrderByDescending(x => x.creationTimeUTC)) { Console.WriteLine($"{row.creationTimeUTC.Add(TimeSpan.FromHours(UseTimeZone)).ToString().PadRight(23)} | {row.serviceStartTimeUTC.Add(TimeSpan.FromHours(UseTimeZone)).ToString().PadRight(23)} | {row.typeCodeDisplayName.PadRight(35)} | {row.authorInstitution.institutionName.PadRight(35)} | {row.healthcareFacilityTypeCodeDisplayName.PadRight(35)}"); //Console.WriteLine($"DocumentId: {row.documentId}"); //Console.WriteLine($"ClassCode DisplayName: {row.classCodeDisplayName}"); //Console.WriteLine($"TypeCode DisplayName: {row.typeCodeDisplayName}"); //Console.WriteLine($"Creation Time UTC: {row.creationTimeUTC.Add(TimeSpan.FromHours(UseTimeZone)).ToString()}"); //Console.WriteLine($"Service Start Time UTC: {row.serviceStartTimeUTC.Add(TimeSpan.FromHours(UseTimeZone)).ToString()}"); //Console.WriteLine($"Service Stop Time UTC: {row.serviceStopTimeUTC.Add(TimeSpan.FromHours(UseTimeZone)).ToString()}"); //Console.WriteLine($"Healthcare Facility TypeCode DisplayName: {row.healthcareFacilityTypeCodeDisplayName}"); //Console.WriteLine($"Repository Unique Id: {row.repositoryUniqueId}"); //Console.WriteLine($"Status: {row.status}"); //Console.WriteLine($"Remove Reason: {row.removeReason}"); //Console.WriteLine($"Record Version: {row.recordVersion}"); //Console.WriteLine($"AuthorInstitution.InstitutionName: {row.authorInstitution.institutionName}"); // Convert dates from UTC to local time //row.creationTimeUTC.ToLocalTime(); //row.serviceStopTimeUTC.ToLocalTime(); // Document name //row.classCodeDisplayName // Organisation //row.authorInstitution.institutionName // Organisation Type //row.healthcareFacilityTypeCodeDisplayName // Identifiers to retrieve the document //row.repositoryUniqueId //row.documentId } } } catch (FaultException e) { // Handle any errors } }
public void Sample() { // NASH certificate should be used here, NOT the HI certificate the NASH certificate can be found in the NASH PKI Test Kit // certificate needs to be installed in the right place // The "Issue To" field of a NASH certificate looks like general (or something different)."HPI-O".electronichealth.net.au // "Serial Number" can be found in the details once the certificate is installed.e.g. in Windows, certificates can be found in Certs.msc // Obtain the certificate for use with TLS and signing X509Certificate2 cert = X509CertificateUtil.GetCertificate( "Serial Number", X509FindType.FindBySerialNumber, StoreName.My, StoreLocation.CurrentUser, true ); // Create PCEHR header CommonPcehrHeader header = PcehrHeaderHelper.CreateHeader(); // Override this value to the current patient's IHI. header.IhiNumber = "IHI"; // Instantiate the client // SVT endpoint is "https://b2b.ehealthvendortest.health.gov.au/getDocumentList" // production endpoint is "https://services.ehealth.gov.au/getDocumentList" GetDocumentListClient documentListClient = new GetDocumentListClient(new Uri("https://GetDocumentListEndpoint"), cert, cert); // Add server certificate validation callback ServicePointManager.ServerCertificateValidationCallback += ValidateServiceCertificate; // Create a query AdhocQueryBuilder adhocQueryBuilder = new AdhocQueryBuilder("patient IHI", new[] { DocumentStatus.Approved }); // To further filter documents, build on the adhocQueryBuilder helper functions // For example, filtering on document type // adhocQueryBuilder.ClassCode = new List<ClassCodes>() {ClassCodes.DischargeSummary}; // See Table 3 XDSDocumentEntry Document Type and Class Code value set from // the Document Exchange Service Technical Service Specification // Create the request using the query AdhocQueryRequest queryRequest = adhocQueryBuilder.BuildRequest(); try { // Invoke the service AdhocQueryResponse queryResponse = documentListClient.GetDocumentList(header, queryRequest); // Process data into a more simple model XdsRecord[] data = XdsMetadataHelper.ProcessXdsMetadata(queryResponse.RegistryObjectList.ExtrinsicObject); // For displaying the data in a list foreach (var row in data) { // Convert dates from UTC to local time //row.creationTimeUTC.ToLocalTime(); //row.serviceStopTimeUTC.ToLocalTime(); // Document name //row.classCodeDisplayName // Organisation //row.authorInstitution.institutionName // Organisation Type //row.healthcareFacilityTypeCodeDisplayName // Identifiers to retrieve the document //row.repositoryUniqueId //row.documentId } // Get the soap request and response string soapRequest = documentListClient.SoapMessages.SoapRequest; string soapResponse = documentListClient.SoapMessages.SoapResponse; } catch (FaultException e) { // Handle any errors } }