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

Remove special characters from postgres password & turn on ReadSourceData for fhir data #325

Merged
merged 15 commits into from
Nov 2, 2023
64 changes: 28 additions & 36 deletions serverless-functions/ReadSourceData/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
)
import requests

# from phdi.fhir.harmonization.standardization import (
# standardize_names,
# standardize_phones,
# standardize_dob,
# )
from phdi.fhir.harmonization.standardization import (
standardize_names,
standardize_phones,
standardize_dob,
)
from lxml import etree
from typing import Tuple, Union
from azure.storage.queue import QueueClient

MESSAGE_TO_TEMPLATE_MAP = {
"fhir": "",
Expand Down Expand Up @@ -167,36 +166,23 @@ def main(message: func.QueueMessage) -> None:

# Handle FHIR messages.
elif message_type == "fhir":
# TODO Remove once the MPI is ready to continue seeding.
staging_queue_url = os.environ["STAGING_QUEUE_URL"]
credential = AzureCredentialManager(
resource_location=staging_queue_url
).get_credential_object()

staging_queue_client = QueueClient.from_queue_url(
queue_url=staging_queue_url, credential=credential
fhir_bundle, external_person_id = get_external_person_id(blob_contents)
fhir_bundle = standardize_dob(
standardize_phones(standardize_names(fhir_bundle))
)
geocoding_url = (
os.environ["INGESTION_URL"] + "/fhir/geospatial/geocode/geocode_bundle"
)
staging_queue_client.send_message(content=message.get_body().decode("utf-8"))

# TODO Uncomment once the MPI is ready to continue seeding.
# fhir_bundle, external_person_id = get_external_person_id(blob_contents)
# fhir_bundle = standardize_dob(
# standardize_phones(standardize_names(fhir_bundle))
# )
# geocoding_url = (
# os.environ["INGESTION_URL"] + "/fhir/geospatial/geocode/geocode_bundle"
# )
# record_linkage_url = os.environ["RECORD_LINKAGE_URL"] + "/link-record"

# geocoding_body = {"bundle": fhir_bundle, "geocode_method": "smarty"}
# geocoding_response = post_data_to_building_block(geocoding_url,
# geocoding_body)

# record_linkage_body = {
# "bundle": geocoding_response.get("bundle"),
# "external_person_id": external_person_id,
# }
# post_data_to_building_block(record_linkage_url, record_linkage_body)
record_linkage_url = os.environ["RECORD_LINKAGE_URL"] + "/link-record"

geocoding_body = {"bundle": fhir_bundle, "geocode_method": "smarty"}
geocoding_response = post_data_to_building_block(geocoding_url, geocoding_body)

record_linkage_body = {
"bundle": geocoding_response.get("bundle"),
"external_person_id": external_person_id,
}
post_data_to_building_block(record_linkage_url, record_linkage_body)
return

subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"]
Expand Down Expand Up @@ -431,7 +417,13 @@ def post_data_to_building_block(url: str, body: dict) -> dict:
if status_code < 400:
logging.info(f"{url.upper()} STATUS CODE: {response.status_code}")
else:
failed_request_message = f"{url.upper()} STATUS CODE: {response.status_code}"
failed_request_status_code = (
f"{url.upper()} STATUS CODE: {response.status_code}"
)
failed_request_reason = f"{url.upper()} REASON: {response.reason}"
failed_request_message = f"{url.upper()} MESSAGE: {response.json()['message']}"
logging.error(failed_request_status_code)
logging.error(failed_request_reason)
logging.error(failed_request_message)
raise Exception(failed_request_message)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,4 @@ def test_post_data_to_building_block(mocked_post, patched_azure_cred_manager):
mocked_post.return_value = mock.Mock(status_code=400, json=(lambda: fhir_bundle))
with pytest.raises(Exception) as e:
post_data_to_building_block(url="https://some_url", body=fhir_bundle)
assert "HTTPS://SOME_URL STATUS CODE: 400" in str(e.value)
assert "message" in str(e.value)
6 changes: 3 additions & 3 deletions terraform/modules/shared/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ locals {
"record-linkage",
])

phdi_version = "v1.0.14"
phdi_version = "v1.1.1"
}

data "docker_registry_image" "ghcr_data" {
Expand Down Expand Up @@ -323,8 +323,8 @@ resource "azurerm_container_app_environment" "phdi" {
##### Postgres #####
resource "random_password" "postgres_password" {
length = 32
special = true
override_special = "_%@"
special = false
override_special = "!#$%&*()-_=+[]{}<>:?"
}

resource "azurerm_postgresql_flexible_server" "mpi" {
Expand Down
Loading