Skip to content

Commit

Permalink
Merge branch 'fix-regression-bugs-in-pr-214' of github.com:onaio/fhir…
Browse files Browse the repository at this point in the history
…-tooling into fix-regression-bugs-in-pr-214
  • Loading branch information
hilpitome committed Jul 23, 2024
2 parents 2d83906 + b9cc0f0 commit ee000e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion importer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,12 @@ The coverage report `coverage.html` will be at the working directory
- The csv_file containing the exported resources is labelled using the current time, to know when the resources were exported for example, csv/exports/2024-02-21-12-21-export_Location.csv

### 10. Import products from openSRP 1
- Run `python3 main.py --csv_file csv/import/product.csv --setup products --log_level info`
- Run `python3 main.py --csv_file csv/import/product.csv --setup products --list_resource_id 123 --log_level info`
- See example csv [here](/importer/csv/import/product.csv)
- This creates a Group resource for each product imported, a Binary resource for any products with an image, and a List resource with references to all the Group and Binary resources created
- The first two columns __name__ and __active__ is the minimum required
- The last column __imageSourceUrl__ contains a url to the product image. If this source requires authentication, then you need to provide the `product_access_token` in the config file. The image is added as a binary resource and referenced in the product's Group resource
- You can pass in a `list_resource_id` to be used as the identifier for the List resource, or you can leave it empty and a random uuid will be generated

### 11. Import inventories from openSRP 1
- Run `python3 main.py --csv_file csv/import/inventory.csv --setup inventories --log_level info`
Expand Down
18 changes: 12 additions & 6 deletions importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,16 @@ def location_extras(resource, payload_string):
longitude = "longitude"

try:
if locationParentName and locationParentName != "parentName":
payload_string = payload_string.replace(
"$parentName", locationParentName
).replace("$parentID", locationParentId)
if locationParentId and locationParentId != "parentId":
payload_string = payload_string.replace("$parentID", locationParentId)
if not locationParentName or locationParentName == "parentName":
obj = json.loads(payload_string)
del obj["resource"]["partOf"]['display']
payload_string = json.dumps(obj, indent=4)
else:
payload_string = payload_string.replace(
"$parentName", locationParentName
)
else:
obj = json.loads(payload_string)
del obj["resource"]["partOf"]
Expand Down Expand Up @@ -1812,7 +1818,7 @@ def filter(self, record):
@click.option("--setup", required=False)
@click.option("--group", required=False)
@click.option("--roles_max", required=False, default=500)
@click.option("--defaultgroups", required=False, default=False)
@click.option("--default_groups", required=False, default=False)
@click.option("--cascade_delete", required=False, default=False)
@click.option("--only_response", required=False)
@click.option(
Expand Down Expand Up @@ -1986,7 +1992,7 @@ def main(
list_resource_id = str(uuid.uuid5(uuid.NAMESPACE_DNS, csv_file))

current_version = get_resource(list_resource_id, "List")
method = "create" if current_version == 0 else "update"
method = "create" if current_version == str(0) else "update"
resource = [["Supply Inventory List", "current", method, list_resource_id]]
result_payload = build_payload(
"List", resource, "json_payloads/product_list_payload.json")
Expand Down

0 comments on commit ee000e8

Please sign in to comment.