Apple Health via Healthkit recently introduce the ability to pull individual patient health records from hospitals and clinics using the same FHIR functionality as 1upHealth. (Note that Apple Health does not support all the health systems supported by 1upHealth) That patient data is stored on the device and does not natively support a cloud or RESTful API experience. That is a limiting experience because you cannot query your patient data across populations or for specific items within their medical record. To enable a cloud based functionality, you can push the FHIR healthcare records from the user's device to 1upHealth and store it in our cloud backend enabling your applications to interact with the data in a RESTful manner. Star by creating a free 1upHealth developer account. Then follow the other steps below.
Before beginning, you must understand the basics of making queries against the 1upHealth FHIR API. Here's a quick intro to FHIR APIs that shows you how to create a 1upHealth user and make requests with an access_token
.
let jsonDictionary = try JSONSerialization.jsonObject(with: fhirRecord.data, options: [])
access_token
. This Patient
resource endpoint must be changed if the resourceType
you are posting is another FHIR type.let jsonData = try? JSONSerialization.data(withJSONObject: jsonDictionary)
// create post request
let url = URL(string: "https://api.1up.health/fhir/dstu2/Patient")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
// set the header
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("Bearer your1uphealthusersbeareraccesstokenhere", forHTTPHeaderField: "Authorization")
// insert json data to the request
request.httpBody = jsonData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
print(error?.localizedDescription ?? "No data")
return
}
let responseJSON = try? JSONSerialization.jsonObject(with: data, options: [])
if let responseJSON = responseJSON as? [String: Any] {
print(responseJSON)
}
}
task.resume()
access_token
.We have a few other recommendations on how to structure this method of using Apple Health via a Cloud API.
access_token
per user (device)