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

117 remove version #118

Merged
merged 4 commits into from
Feb 2, 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
14 changes: 6 additions & 8 deletions importer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,8 @@ The coverage report `coverage.html` will be at the working directory
- The first column __name__ is the only one reqired
- [organizations_full](/importer/csv/organizations/organizations_full.csv) shows more options available
- The third column is the request method, can be either create or update. Default is set to create
- The fourth column is the version. Default is set to 1 for creation, needs to be set when updating
- The fifth column is the id, which is required when updating
- The sixth columns in the identifier, in some cases this is different from the id
- The fourth column is the id, which is required when updating
- The fifth columns in the identifier, in some cases this is different from the id

### 4. Create care teams in bulk
- Run `python3 main.py --csv_file csv/careteams/careteam_min.csv --resource_type careTeams --log_level info`
Expand All @@ -95,11 +94,10 @@ The coverage report `coverage.html` will be at the working directory
- If the status is not set it will default to __active__
- [careteam_full](/importer/csv/careteams/careteam_full.csv) shows more options available
- The third column is the request method, can be either create or update. Default is set to create
- The fourth column is the version. Default is set to 1 for creation, needs to be set when updating
- The fifth column is the id, which is required when updating
- The sixth columns is the identifier, in some cases this is different from the id
- The seventh column is the organizations. This is only useful when you want to assign a few organizations when creating careteams. The format expected is a string like `orgId1:orgName1|orgId2:orgName2|orgId3:orgNam3`. Otherwise use the "Assign careTeams to organizations" csv below.
- The eighth column is the participants. This is only useful when you want to assign a few users when creating careteams. The format expected is a string like `userId1:fullName1|userId2:fullName2|userId3:fullName3`. Otherwise use the "Assign users to careteams" csv below
- The fourth column is the id, which is required when updating
- The fifth columns is the identifier, in some cases this is different from the id
- The sixth column is the organizations. This is only useful when you want to assign a few organizations when creating careteams. The format expected is a string like `orgId1:orgName1|orgId2:orgName2|orgId3:orgNam3`. Otherwise use the "Assign careTeams to organizations" csv below.
- The seventh column is the participants. This is only useful when you want to assign a few users when creating careteams. The format expected is a string like `userId1:fullName1|userId2:fullName2|userId3:fullName3`. Otherwise use the "Assign users to careteams" csv below



Expand Down
4 changes: 2 additions & 2 deletions importer/csv/careteams/careteam_full.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name,status,method,version,id,identifier,organizations,participants
Knee care,active,update,1,b323df51-b515-46a0-b4e6-dd29d515ae5e,,1767:test|1766:test 2,2210:Jane Doe|2204:Jane Doe
name,status,method,id,identifier,organizations,participants
Knee care,active,update,b323df51-b515-46a0-b4e6-dd29d515ae5e,,1767:test|1766:test 2,2210:Jane Doe|2204:Jane Doe
8 changes: 4 additions & 4 deletions importer/csv/organizations/organizations_full.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name,active,method,version,id,identifier,alias
New Organization,true,create,1,,,Brand new
Some other Organization,true,create,1,,,
Health Organization,true,update,4,8342dd77-aecd-48ab-826b-75c7c33039ed,bbafb691-efcf-4d7f-8c03-569c5ab2caf1,Health Org
name,active,method,id,identifier,alias
New Organization,true,create,,,Brand new
Some other Organization,true,create,,,
Health Organization,true,update,8342dd77-aecd-48ab-826b-75c7c33039ed,bbafb691-efcf-4d7f-8c03-569c5ab2caf1,Health Org
46 changes: 33 additions & 13 deletions importer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def create_user_resources(user_id, user):
# custom extras for organizations
def organization_extras(resource, payload_string):
try:
if resource[6]:
payload_string = payload_string.replace("$alias", resource[6])
if resource[5]:
payload_string = payload_string.replace("$alias", resource[5])
except IndexError:
obj = json.loads(payload_string)
del obj["resource"]["alias"]
Expand All @@ -211,9 +211,9 @@ def organization_extras(resource, payload_string):
# custom extras for locations
def location_extras(resource, payload_string):
try:
if resource[5]:
payload_string = payload_string.replace("$parentName", resource[5]).replace(
"$parentID", resource[6]
if resource[4]:
payload_string = payload_string.replace("$parentName", resource[4]).replace(
"$parentID", resource[5]
)
else:
obj = json.loads(payload_string)
Expand Down Expand Up @@ -255,11 +255,11 @@ def location_extras(resource, payload_string):
else:
logging.error("Unsupported location physical type provided for " + resource[0])
obj = json.loads(payload_string)
del obj["resource"]["physicalType"]
del obj["resource"]["type"]
payload_string = json.dumps(obj, indent=4)
except IndexError:
obj = json.loads(payload_string)
del obj["resource"]["physicalType"]
del obj["resource"]["type"]
payload_string = json.dumps(obj, indent=4)

return payload_string
Expand All @@ -276,13 +276,13 @@ def care_team_extras(

if load_type == "min":
try:
if resource[6]:
elements = resource[6].split("|")
if resource[5]:
elements = resource[5].split("|")
except IndexError:
pass
try:
if resource[7]:
elements2 = resource[7].split("|")
if resource[6]:
elements2 = resource[6].split("|")
except IndexError:
pass
elif load_type == "full":
Expand Down Expand Up @@ -456,6 +456,24 @@ def build_org_affiliation(resources, resource_list):
return fp


# This function is used to Capitalize the 'resource_type'
# and remove the 's' at the end, a version suitable with the API
def get_valid_resource_type(resource_type):
logging.info("Modify the string resource_type")
modified_resource_type = resource_type[0].upper() + resource_type[1:-1]
return modified_resource_type


# This function gets the current resource version from the API
def get_resource_version(resource_id, resource_type):
logging.info("Getting resource version")
modified_resource_type = get_valid_resource_type(resource_type)
resource_url = config.fhir_base_url + "/" + modified_resource_type + "/" + resource_id
response = handle_request("GET", "", resource_url)
json_response = json.loads(response[0])
return json_response["meta"]["versionId"]


# This function builds a json payload
# which is posted to the api to create resources
def build_payload(resource_type, resources, resource_payload_file):
Expand Down Expand Up @@ -502,9 +520,11 @@ def build_payload(resource_type, resources, resource_payload_file):
except IndexError:
ps = ps.replace("$status", "active")

# Get resource versions from API
try:
ps = ps.replace("$version", resource[3])
except IndexError:
version = get_resource_version(resource[3], resource_type)
ps = ps.replace("$version", version)
except Exception:
ps = ps.replace("$version", "1")

if resource_type == "organizations":
Expand Down
Loading