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

Ensure all resources are correctly added to the list resources #299

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 35 additions & 9 deletions importer/importer/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,10 +1009,31 @@ def build_group_list_resource(
current_version = get_resource(list_resource_id, "List")
method = "create" if current_version == str(0) else "update"
resource = [[title, "current", method, list_resource_id]]
result_payload = build_payload(
"List", resource, "json_payloads/group_list_payload.json"
)
return process_resources_list(result_payload, full_list_created_resources)

if method == "create":
result_payload = build_payload(
"List", resource, "json_payloads/group_list_payload.json"
)
return process_resources_list(result_payload, full_list_created_resources)
if method == "update":
resource_url = "/".join([get_base_url(), "List", list_resource_id])
response = handle_request("GET", "", resource_url)
payload = {
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"request": {
"method": "PUT",
"url": "List/" + list_resource_id,
"ifMatch": current_version
},
"resource": json.loads(response[0])
}
]
}
resource_payload = json.dumps(payload, indent=4)
return process_resources_list(resource_payload, full_list_created_resources)


# This function takes a 'created_resources' array and a response string
Expand All @@ -1034,13 +1055,18 @@ def extract_resources(created_resources, response_string):
# then returns the full resource payload
def process_resources_list(payload, resources_list):
entry = []
json_payload = json.loads(payload)
entries = json_payload["entry"][0]["resource"]["entry"]
if len(entries) > 0:
entry = entries

for resource in resources_list:
item = {"item": {"reference": resource}}
entry.append(item)
if resource not in str(entries):
item = {"item": {"reference": resource}}
entry.append(item)

payload = json.loads(payload)
payload["entry"][0]["resource"]["entry"] = entry
return payload
json_payload["entry"][0]["resource"]["entry"] = entry
return json_payload


def link_to_location(resource_list):
Expand Down
7 changes: 6 additions & 1 deletion importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,14 @@ def main(
del _["code"]
issues.append(_)
logging.error(json_response)
logging.info(inventory_creation_response.text)
logging.info("GROUPS: " + str(groups_created))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding these to help with debugging. If you are running an import and the Groups or Lists are empty, then there is obviously an issue somewhere


lists_created = []
link_payload = link_to_location(resource_list)
if len(link_payload) > 0:
link_response = handle_request("POST", link_payload, fhir_base_url)
if link_response.status_code == 200:
if link_response.status_code == 200 or link_response.status_code == 201:
lists_created = extract_resources(lists_created, link_response.text)
else:
fail_count = fail_count + 1
Expand All @@ -271,8 +273,10 @@ def main(
del _["code"]
issues.append(_)
logging.info(link_response.text)
logging.info("LISTS: " + str(lists_created))

full_list_created_resources = groups_created + lists_created
logging.info("FULL LIST: " + str(full_list_created_resources))
if len(full_list_created_resources) > 0:
list_payload = build_group_list_resource(
list_resource_id,
Expand All @@ -281,6 +285,7 @@ def main(
"Supply Chain commodities",
)
final_response = handle_request("POST", "", fhir_base_url, list_payload)
logging.info(final_response.text)
logging.info("Processing complete!")
else:
message = "Unsupported request!"
Expand Down