From 1f8e9e9f68ce80260bab4578005a7c5733eb4c05 Mon Sep 17 00:00:00 2001 From: thiagotrabach Date: Thu, 3 Aug 2023 13:20:18 -0300 Subject: [PATCH] minor changes --- fhir_utils/healthcare_api.py | 44 ++++++++++++------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/fhir_utils/healthcare_api.py b/fhir_utils/healthcare_api.py index 1a3da59..5b42cb5 100644 --- a/fhir_utils/healthcare_api.py +++ b/fhir_utils/healthcare_api.py @@ -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, @@ -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, @@ -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, @@ -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, @@ -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, @@ -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): @@ -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)