Skip to content

Commit

Permalink
Merge pull request #658 from Health-Informatics-UoN/fix/643/process-f…
Browse files Browse the repository at this point in the history
…unction

Fix ProcessQueue magic numbers
  • Loading branch information
AndyRae authored Mar 26, 2024
2 parents dc0d162 + eb6d02b commit 17180c5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/workers/CreateConcepts/reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ def select_concepts_to_post(
"description", "field_name") keys (for values), with entries (field_id, concept_id)
or (value_id, concept_id) respectively.
content_type (Literal["scanreportfield", "scanreportvalue"]): Controls whether to handle ScanReportFields (15), or ScanReportValues (17).
content_type (Literal["scanreportfield", "scanreportvalue"]): Controls whether to handle ScanReportFields, or ScanReportValues.
Returns:
A list of reused `Concepts` to create.
Raises:
Exception: ValueError: A content_type other than 15 or 17 was provided.
Exception: ValueError: A content_type other than scanreportfield or scanreportvalue was provided.
"""
concepts_to_post = []

Expand Down
29 changes: 14 additions & 15 deletions app/workers/ProcessQueue/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import asyncio
import json
import logging
import os

from collections import defaultdict
from datetime import datetime

import asyncio
import azure.functions as func
import httpx
import requests
import azure.functions as func

from requests.models import HTTPError
from shared_code import omop_helpers
from . import helpers, blob_parser

from . import blob_parser, helpers

# import memory_profiler
# root_logger = logging.getLogger()
Expand Down Expand Up @@ -152,13 +151,13 @@ def select_concepts_to_post(
for new_content_detail in new_content_details:
try:
# fields
if content_type == 15:
if content_type == "scanreportfield":
(
existing_content_id,
concept_id,
) = details_to_id_and_concept_id_map[str(new_content_detail["name"])]
# values
elif content_type == 17:
elif content_type == "scanreportvalue":
existing_content_id, concept_id = details_to_id_and_concept_id_map[
(
str(new_content_detail["name"]),
Expand All @@ -168,17 +167,17 @@ def select_concepts_to_post(
]
else:
raise RuntimeError(
f"content_type must be 15 or 17: you provided {content_type}"
f"content_type must be scanreportvalue or scanreportfield: you provided {content_type}"
)

new_content_id = str(new_content_detail["id"])
if content_type == 15:
if content_type == "scanreportfield":
logger.info(
f"Found existing field with id: {existing_content_id} with existing "
f"concept mapping: {concept_id} which matches new field id: "
f"{new_content_id}"
)
elif content_type == 17:
elif content_type == "scanreportvalue":
logger.info(
f"Found existing value with id: {existing_content_id} with existing "
f"concept mapping: {concept_id} which matches new value id: "
Expand Down Expand Up @@ -844,7 +843,7 @@ async def process_values_from_sheet(
# TODO: we should query this value from the API
# - via ORM it would be ContentType.objects.get(model='scanreportvalue').id,
# but that's not available from an Azure Function.
"content_type": 17,
"content_type": "scanreportvalue",
"creation_type": "V",
}
)
Expand All @@ -856,7 +855,7 @@ async def process_values_from_sheet(
# TODO: we should query this value from the API
# - via ORM it would be ContentType.objects.get(model='scanreportvalue').id,
# but that's not available from an Azure Function.
"content_type": 17,
"content_type": "scanreportfield",
"creation_type": "V",
}
)
Expand All @@ -878,8 +877,8 @@ async def process_values_from_sheet(

logger.info("POST concepts all finished")

reuse_existing_field_concepts(fieldnames_to_ids_dict, 15)
reuse_existing_value_concepts(values_response_content, 17)
reuse_existing_field_concepts(fieldnames_to_ids_dict, "scanreportfield")
reuse_existing_value_concepts(values_response_content, "scanreportvalue")


def post_field_entries(field_entries_to_post, scan_report_id):
Expand Down Expand Up @@ -1203,7 +1202,7 @@ def main(msg: func.QueueMessage):
For each row in Field Overview create an entry for scan_report_field,
Empty row signifies end of fields in a table
Append field entry to field_entries_to_post[] list,
Create JSON array with all the field entries,
Create JSON array with all the field entries,
Send POST request to API with JSON as input,
Save the response data(field ids,field names) in a dictionary
Set the current working sheet to be the same as the current table
Expand Down

0 comments on commit 17180c5

Please sign in to comment.