-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from kids-first/custom-search-parameters
✨ Add patient us-core-race and us-core-ethnicity search params
- Loading branch information
Showing
5 changed files
with
300 additions
and
4 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
smilecdr/search_parameters/SearchParameter-us-core-ethnicity.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"resourceType": "SearchParameter", | ||
"id": "us-core-ethnicity", | ||
"url": "http://hl7.org/fhir/us/core/SearchParameter/us-core-ethnicity", | ||
"version": "7.0.0", | ||
"name": "USCoreEthnicity", | ||
"status": "active", | ||
"date": "2022-04-14", | ||
"publisher": "HL7 International / Cross-Group Projects", | ||
"contact": [ | ||
{ | ||
"name": "HL7 International / Cross-Group Projects", | ||
"telecom": [ | ||
{ | ||
"system": "url", | ||
"value": "http://www.hl7.org/Special/committees/cgp" | ||
}, | ||
{ | ||
"system": "email", | ||
"value": "[email protected]" | ||
} | ||
] | ||
} | ||
], | ||
"description": "Returns patients with an ethnicity extension matching the specified code.", | ||
"jurisdiction": [ | ||
{ | ||
"coding": [ | ||
{ | ||
"system": "urn:iso:std:iso:3166", | ||
"code": "US" | ||
} | ||
] | ||
} | ||
], | ||
"code": "ethnicity", | ||
"base": ["Patient"], | ||
"type": "token", | ||
"expression": "Patient.extension.where(url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-ethnicity').extension.value.code", | ||
"xpathUsage": "normal", | ||
"multipleOr": true, | ||
"_multipleOr": { | ||
"extension": [ | ||
{ | ||
"url": "http://hl7.org/fhir/StructureDefinition/capabilitystatement-expectation", | ||
"valueCode": "MAY" | ||
} | ||
] | ||
}, | ||
"multipleAnd": true, | ||
"_multipleAnd": { | ||
"extension": [ | ||
{ | ||
"url": "http://hl7.org/fhir/StructureDefinition/capabilitystatement-expectation", | ||
"valueCode": "MAY" | ||
} | ||
] | ||
} | ||
} | ||
|
60 changes: 60 additions & 0 deletions
60
smilecdr/search_parameters/SearchParameter-us-core-race.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"resourceType": "SearchParameter", | ||
"id": "us-core-race", | ||
"url": "http://hl7.org/fhir/us/core/SearchParameter/us-core-race", | ||
"version": "7.0.0", | ||
"name": "USCoreRace", | ||
"status": "active", | ||
"date": "2022-04-14", | ||
"publisher": "HL7 International / Cross-Group Projects", | ||
"contact": [ | ||
{ | ||
"name": "HL7 International / Cross-Group Projects", | ||
"telecom": [ | ||
{ | ||
"system": "url", | ||
"value": "http://www.hl7.org/Special/committees/cgp" | ||
}, | ||
{ | ||
"system": "email", | ||
"value": "[email protected]" | ||
} | ||
] | ||
} | ||
], | ||
"description": "Returns patients with a race extension matching the specified code.", | ||
"jurisdiction": [ | ||
{ | ||
"coding": [ | ||
{ | ||
"system": "urn:iso:std:iso:3166", | ||
"code": "US" | ||
} | ||
] | ||
} | ||
], | ||
"code": "race", | ||
"base": ["Patient"], | ||
"type": "token", | ||
"expression": "Patient.extension.where(url = 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-race').extension.value.code", | ||
"xpathUsage": "normal", | ||
"multipleOr": true, | ||
"_multipleOr": { | ||
"extension": [ | ||
{ | ||
"url": "http://hl7.org/fhir/StructureDefinition/capabilitystatement-expectation", | ||
"valueCode": "MAY" | ||
} | ||
] | ||
}, | ||
"multipleAnd": true, | ||
"_multipleAnd": { | ||
"extension": [ | ||
{ | ||
"url": "http://hl7.org/fhir/StructureDefinition/capabilitystatement-expectation", | ||
"valueCode": "MAY" | ||
} | ||
] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import argparse | ||
from pprint import pprint | ||
|
||
from requests.auth import HTTPBasicAuth | ||
|
||
from src.config import ( | ||
SEARCH_PARAMETER_DIR, | ||
REINDEX_PAYLOAD, | ||
BASE_URL, | ||
REINDEX_ENDPOINT, | ||
FHIR_APP_ADMIN, | ||
FHIR_APP_ADMIN_PW | ||
) | ||
from src.misc import ( | ||
read_json, | ||
send_request | ||
) | ||
|
||
|
||
def upsert_search_parameters( | ||
client_id, client_secret, search_parameter_dir=SEARCH_PARAMETER_DIR | ||
): | ||
""" | ||
Read search parameters from file, then upsert them in server | ||
Last, reindex the resources so that SearchParameters take effect | ||
""" | ||
print("Loading search parameters") | ||
|
||
for fn in os.listdir(search_parameter_dir): | ||
if not fn.endswith(".json"): | ||
continue | ||
filepath = os.path.join(search_parameter_dir, fn) | ||
search_param = read_json(filepath) | ||
|
||
# Load search parameter | ||
id_ = search_param["id"] | ||
endpoint = "/".join( | ||
part.strip("/") for part in [BASE_URL, "SearchParameter", id_] | ||
) | ||
resp = send_request( | ||
"put", | ||
endpoint, | ||
json=search_param, | ||
auth=HTTPBasicAuth(client_id, client_secret), | ||
) | ||
print( | ||
f"PUT {endpoint}" | ||
) | ||
|
||
# Start reindexing operation | ||
endpoint = f"{BASE_URL}/$reindex" | ||
resp = send_request( | ||
"post", | ||
endpoint, | ||
json=REINDEX_PAYLOAD, | ||
auth=HTTPBasicAuth(client_id, client_secret), | ||
) | ||
pprint(resp.json()) | ||
|
||
|
||
def cli(): | ||
""" | ||
CLI for running this script | ||
""" | ||
parser = argparse.ArgumentParser( | ||
description='Load SearchParameters in FHIR server' | ||
) | ||
parser.add_argument( | ||
"--client_id", | ||
default=FHIR_APP_ADMIN, | ||
help="Admin ID to authenticate with FHIR server", | ||
) | ||
parser.add_argument( | ||
"--client_secret", | ||
default=FHIR_APP_ADMIN_PW, | ||
help="Admin secret to authenticate with FHIR server", | ||
) | ||
parser.add_argument( | ||
"--search_parameter_dir", | ||
default=SEARCH_PARAMETER_DIR, | ||
help="Path to dir with SearchParameters", | ||
) | ||
args = parser.parse_args() | ||
|
||
upsert_search_parameters( | ||
args.client_id, args.client_secret, args.search_parameter_dir | ||
) | ||
|
||
print("✅ Load SearchParameters complete") | ||
|
||
|
||
if __name__ == "__main__": | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters