Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiagoTrabach committed Aug 1, 2023
1 parent 94606fd commit 24466b2
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
44 changes: 44 additions & 0 deletions fhir_utils/healthcare_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from googleapiclient import discovery
import json

class HealthcareApi:
def __init__(self, project_id, location, dataset_id, fhir_store_id):
self.api_version = "v1"
self.service_name = "healthcare"
self.header = "application/fhir+json;charset=utf-8"
self.fhir_store_parent = f"projects/{project_id}/locations/{location}/datasets/{dataset_id}"
self.fhir_store_name = f"{self.fhir_store_parent}/fhirStores/{fhir_store_id}"
self.client = discovery.build(self.service_name, self.api_version)


def create(self, resource: str, body: dict):
request = self.client.projects().locations().datasets().fhirStores().fhir().create(parent = self.fhir_store_name,
type = resource,
body = body)
request.headers["content-type"] = self.header

response = request.execute()
print(f"Created Patient resource with ID {response['id']}")

return response


def update(self, resource: str, resource_id: str, body: dict):
fhir_resource_path = f"{self.fhir_store_name}/fhir/{resource}/{resource_id}"

request = self.client.projects().locations().datasets().fhirStores().fhir().update(name = fhir_resource_path,
body = body)

request.headers["content-type"] = self.header
response = request.execute()

print(f"Updated {resource} resource with ID {resource_id}:\n {json.dumps(response, indent=2)}")

return response


def read(self):
return None

def delete(self):
return None
19 changes: 19 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cachetools==5.3.1
certifi==2023.7.22
charset-normalizer==3.2.0
google-api-core==2.11.1
google-api-python-client==2.95.0
google-auth==2.22.0
google-auth-httplib2==0.1.0
googleapis-common-protos==1.60.0
httplib2==0.22.0
idna==3.4
protobuf==4.23.4
pyasn1==0.5.0
pyasn1-modules==0.3.0
pyparsing==3.1.1
requests==2.31.0
rsa==4.9
six==1.16.0
uritemplate==4.1.1
urllib3==1.26.16

0 comments on commit 24466b2

Please sign in to comment.