Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

129 export resource uuids #148

Merged
merged 9 commits into from
Mar 4, 2024
Merged

129 export resource uuids #148

merged 9 commits into from
Mar 4, 2024

Conversation

TraciebelWairimu
Copy link
Contributor

IMPORTANT: Where possible all PRs must be linked to a Github issue

Fixes #129

Engineer Checklist

  • I have run ./gradlew spotlessApply to check my code follows the project's style guide
  • I have built and run the efsity jar to verify my change fixes the issue and/or does not break the application

@TraciebelWairimu TraciebelWairimu force-pushed the 129-Export-Resource-uuids branch from 1ba56be to 610a82a Compare February 22, 2024 07:43
importer/main.py Outdated
@click.option("--csv_file", required=True)
@click.option("--csv_file", required=False)
@click.option("--export_resources", required=False)
@click.option("--parameter", required=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add default values for parameter, value and batch_size so that the export works even when these are not passed

importer/main.py Outdated
def write_csv(data, resource_type, fieldnames):
logging.info("Writing to csv file")
current_time = datetime.now().strftime("%Y-%m-%d-%H-%M")
csv_file = f"csv/{current_time}-export_{resource_type}.csv"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's maybe create a folder inside /csv called exports just so this is cleaner and easier to find

importer/main.py Outdated
@click.option("--export_resources", required=False)
@click.option("--parameter", required=False)
@click.option("--value", required=False)
@click.option("--batch_size", required=False)
Copy link
Contributor

@Wambere Wambere Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this batch_size needs to be changed to limit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I label it as limit and not batch_size ?

importer/main.py Outdated
@@ -17,6 +17,7 @@

global_access_token = ""


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this, and run black on these files

importer/main.py Outdated
elements = ["name", "status", "id", "identifier", " organizations", "participants"]
else:
elements = []
for x in resources["entry"]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to handle a case where the response returned has 0 resources and thus does not have "entry"

importer/main.py Outdated
elif resource_type == "Organization":
elements = ["name", "active", "id", "identifier", "alias"]
elif resource_type == "CareTeam":
elements = ["name", "status", "id", "identifier", " organizations", "participants"]
Copy link
Contributor

@Wambere Wambere Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like we are exporting the organizations and participants here, are we?

importer/main.py Outdated

# This function exports resources from the API to a csv file
def export_resources_to_csv(resource_type, parameter, value, batch_size):
resource_type = get_valid_resource_type(resource_type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change this (include in the doc ) to require the resource type exactly as it would be/work in a url so we don't have to do this. Might be a it confusing

importer/main.py Outdated
@@ -974,5 +1052,6 @@ def main(
total_time = end_time - start_time
logging.info("Total time: " + str(total_time.total_seconds()) + " seconds")


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I black format the files the spaces are added back

@TraciebelWairimu TraciebelWairimu force-pushed the 129-Export-Resource-uuids branch 2 times, most recently from 26596a8 to 74d6f73 Compare February 28, 2024 08:39
@Wambere Wambere force-pushed the 129-Export-Resource-uuids branch 2 times, most recently from 74d6f73 to 9075ede Compare February 29, 2024 07:28
@TraciebelWairimu TraciebelWairimu force-pushed the 129-Export-Resource-uuids branch from 8a5daf1 to 63fd41a Compare February 29, 2024 09:06
- `export_resources` can either be True or False, checks if it is True and exports the resources
- The `parameter` is used as a filter for the resources. The set default parameter is "_lastUpdated", other examples include, "name"
- The `value` is where you pass the actual parameter value to filter the resources. The set default value is "gt2023-01-01", other examples include, "Good Health Clinic 1"
- The `limit` is the number of resources exported at a time
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add the default here as well

importer/main.py Outdated
if response[1] == 200:
resources = json.loads(response[0])
data = []
if "entry" in resources:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we check this with resources["entry"] instead ?

importer/main.py Outdated
rl.append(value)
data.append(rl)
write_csv(data, resource_type, elements)
logging.info("Successfully written to csv")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is nothing here checking that this was actually successful
I tried exporting with an invalid date time, python3 main.py --export_resources True --parameter _lastUpdated --value gt2023-02-29 --limit 20 --resource_type Location --log_level info
I got an error and no export but this still printed successful

self.test_fieldnames = ["name", "active", "method", "id", "identifier", "alias"]
write_csv(self.test_data, self.test_resource_type, self.test_fieldnames)
self.assertIsInstance(self.test_data, list)
self.assertEqual(len(self.test_data), 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these assert statements are not testing the result of your function call

self.assertEqual(len(self.test_data), 2)
current_time = datetime.now().strftime("%Y-%m-%d-%H-%M")
expected_csv_file_path = (
f"csv/exports/{current_time}-export_{self.test_resource_type}.csv"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that this current_time gotten in the test is different from the current_time gotten when the function was called

pld
pld previously approved these changes Mar 4, 2024
@Wambere Wambere merged commit f2e5290 into main Mar 4, 2024
4 checks passed
@Wambere Wambere deleted the 129-Export-Resource-uuids branch March 4, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export resource uuids
3 participants