Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiagoTrabach committed Aug 3, 2023
1 parent 9649a6c commit 1f8e9e9
Showing 1 changed file with 14 additions and 30 deletions.
44 changes: 14 additions & 30 deletions fhir_utils/healthcare_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ def create(

response = self.session.post(resource_path, headers=self.header, json=payload)

return_payload = response.json()

print(f"Created Patient resource with ID {return_payload['id']}")

return {"response": response.status_code, "payload": return_payload}
return {"status_code": response.status_code, "body": response.json()}

def update(
self,
Expand All @@ -52,11 +48,7 @@ def update(

response = self.session.put(resource_path, headers=self.header, json=payload)

return_payload = response.json()

print(f"Updated {resource} resource with ID {resource_id}")

return {"response": response.status_code, "payload": return_payload}
return {"status_code": response.status_code, "body": response.json()}

def update_conditional(
self,
Expand Down Expand Up @@ -94,9 +86,7 @@ def update_conditional(

response = self.session.put(resource_path, headers=self.header, json=payload)

return_payload = response.json()

return {"response": response.status_code, "payload": return_payload}
return {"status_code": response.status_code, "body": response.json()}

def read(
self,
Expand All @@ -110,11 +100,7 @@ def read(

response = self.session.get(resource_path, headers=self.header)

return_payload = response.json()

print(f"Got contents of {resource} resource with ID {resource_id}:\n")

return {"response": response.status_code, "payload": return_payload}
return {"status_code": response.status_code, "body": response.json()}

def read_conditional(
self,
Expand All @@ -132,11 +118,7 @@ def read_conditional(

response = self.session.get(resource_path, headers=self.header)

return_payload = response.json()

print(f"Got {return_payload['total']} entries from {resource}")

return {"response": response.status_code, "payload": return_payload}
return {"status_code": response.status_code, "body": response.json()}

def delete(
self,
Expand All @@ -145,14 +127,18 @@ def delete(
resource: str,
resource_id: str
) -> dict:
"""Delete a resource from the FHIR store"""
"""
Delete a resource from the FHIR store
Response code:
200 Success
If the resource was deleted or not found
"""
resource_path = f"{self.url}/datasets/{dataset_id}/fhirStores/{fhir_store_id}/fhir/{resource}/{resource_id}"

response = self.session.delete(resource_path, headers=self.header)

print(f"Deleted {resource} resource with ID {resource_id}.")

return {"response": response.status_code}
return {"status_code": response.status_code, "body": response.json()}


class FastCRUD(HealthcareApi):
Expand Down Expand Up @@ -191,6 +177,4 @@ def patient_update(
) -> dict:
"""Update the entries from Patient resource in the FHIR store based on tax id (CPF)"""
parameter = f"identifier=https://rnds-fhir.saude.gov.br/NamingSystem/cpf|{cpf}"
return self.update_conditional(
dataset_id, fhir_store_id, "Patient", parameter, payload
)
return self.update_conditional(dataset_id, fhir_store_id, "Patient", parameter, payload)

0 comments on commit 1f8e9e9

Please sign in to comment.