How to load CCD from Files and parser with HealthKit without going through HealthKit store?

Hi! Is there a way to import ccd from Files and using HealthKit library to parse the CCD's xml content? I do not want to store anything in the Health app itself. I am able to load my CCD's XML into a HKCDADocumentSample variable, but by design, a HKCDADocumentSample only parses basic information in its
HKCDADocment property, like authorName, custodianName, patientName, and title. The xml data gets stored as XML data, but none of the deeper and more useful values are parsed like the ones mentioned earlier. I'm trying to use HKDocumentQuery to load the cdcDoc data but no luck. Is this querying only restricted to what's stored in the device's Health app? Is it possible to do it without using the HealthKit store? I want to just import ccd from Files to the app and use HKDocumentQuery to parse the xml data for my app. My code is below.


Thanks!!



class importEHRVC: UIViewController {


var docName: String = ""


override func viewDidLoad() {

super.viewDidLoad()

printXML(source: docName)

}


func printXML(source: String) {

guard

let xmlPath = Bundle.main.path(forResource: source, ofType: "xml"),

let data = try? Data(contentsOf: URL(fileURLWithPath: xmlPath))

else { return }


do {


let cdcDoc = try HKCDADocumentSample(data: data, start: Date(), end: Date(), metadata: nil)


basicInfolabel.text = "Basic Information \n\nTitle: \(cdcDoc.document?.title ?? "")\nName: \(cdcDoc.document?.patientName ?? "")\nAuthor: \(cdcDoc.document?.authorName ?? "")\nOrganization: \(cdcDoc.document?.custodianName ?? "")"


guard let cdaType = HKObjectType.documentType(forIdentifier: .CDA) else {

fatalError("Unable to create a CDA document type.")

}


var allDocuments = [HKDocumentSample]()

let cdaQuery = HKDocumentQuery(documentType: cdcDoc.documentType,

predicate: nil,

limit: HKObjectQueryNoLimit,

sortDescriptors: nil,

includeDocumentData: false) { //only load it to here not doing the query 😟

(query, resultsOrNil, done, errorOrNil) in

guard let results = resultsOrNil else {

if let queryError = errorOrNil {

// Handle the query error here...

}

return

}

allDocuments += results

if done {

// the allDocuments array now contains all the samples returned by the query.

// Handle the documents here...

}

}


} catch {

print("\(error)")

}

}

}