Skip to content

Commit

Permalink
Print final response
Browse files Browse the repository at this point in the history
  • Loading branch information
Wambere committed Feb 20, 2024
1 parent 721d7fe commit f8c69e8
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -851,11 +851,12 @@ def clean_duplicates(users, cascade_delete):
@click.option("--group", required=False)
@click.option("--roles_max", required=False, default=500)
@click.option("--cascade_delete", required=False, default=False)
@click.option("--only_response", required=False)
@click.option(
"--log_level", type=click.Choice(["DEBUG", "INFO", "ERROR"], case_sensitive=False)
)
def main(
csv_file, resource_type, assign, setup, group, roles_max, cascade_delete, log_level
csv_file, resource_type, assign, setup, group, roles_max, cascade_delete, only_response, log_level
):
if log_level == "DEBUG":
logging.basicConfig(level=logging.DEBUG)
Expand All @@ -867,6 +868,8 @@ def main(
start_time = datetime.now()
logging.info("Start time: " + start_time.strftime("%H:%M:%S"))

final_response = ""

logging.info("Starting csv import...")
resource_list = read_csv(csv_file)
if resource_list:
Expand All @@ -883,14 +886,14 @@ def main(
practitioner_exists = confirm_practitioner(user, user_id)
if not practitioner_exists:
payload = create_user_resources(user_id, user)
handle_request("POST", payload, config.fhir_base_url)
final_response = handle_request("POST", payload, config.fhir_base_url)
logging.info("Processing complete!")
elif resource_type == "locations":
logging.info("Processing locations")
json_payload = build_payload(
"locations", resource_list, "json_payloads/locations_payload.json"
)
handle_request("POST", json_payload, config.fhir_base_url)
final_response = handle_request("POST", json_payload, config.fhir_base_url)
logging.info("Processing complete!")
elif resource_type == "organizations":
logging.info("Processing organizations")
Expand All @@ -899,32 +902,32 @@ def main(
resource_list,
"json_payloads/organizations_payload.json",
)
handle_request("POST", json_payload, config.fhir_base_url)
final_response = handle_request("POST", json_payload, config.fhir_base_url)
logging.info("Processing complete!")
elif resource_type == "careTeams":
logging.info("Processing CareTeams")
json_payload = build_payload(
"careTeams", resource_list, "json_payloads/careteams_payload.json"
)
handle_request("POST", json_payload, config.fhir_base_url)
final_response = handle_request("POST", json_payload, config.fhir_base_url)
logging.info("Processing complete!")
elif assign == "organization-Location":
logging.info("Assigning Organizations to Locations")
matches = extract_matches(resource_list)
json_payload = build_org_affiliation(matches, resource_list)
handle_request("POST", json_payload, config.fhir_base_url)
final_response = handle_request("POST", json_payload, config.fhir_base_url)
logging.info("Processing complete!")
elif assign == "careTeam-Organization":
logging.info("Assigning CareTeam to Organization")
matches = extract_matches(resource_list)
json_payload = fetch_and_build(matches, "orgs")
handle_request("POST", json_payload, config.fhir_base_url)
final_response = handle_request("POST", json_payload, config.fhir_base_url)
logging.info("Processing complete!")
elif assign == "user-careTeam":
logging.info("Assigning users to careTeam")
matches = extract_matches(resource_list)
json_payload = fetch_and_build(matches, "users")
handle_request("POST", json_payload, config.fhir_base_url)
final_response = handle_request("POST", json_payload, config.fhir_base_url)
logging.info("Processing complete!")
elif setup == "roles":
logging.info("Setting up keycloak roles")
Expand All @@ -945,6 +948,9 @@ def main(
else:
logging.error("Empty csv file!")

if only_response:
print(final_response.text)

end_time = datetime.now()
logging.info("End time: " + end_time.strftime("%H:%M:%S"))
total_time = end_time - start_time
Expand Down

0 comments on commit f8c69e8

Please sign in to comment.