Skip to content

Commit

Permalink
Moving active attribute change to api.py to correspond to how GET works;
Browse files Browse the repository at this point in the history
WIP: fixing attributes without active property to be displayed as active
  • Loading branch information
Filienko committed Jan 7, 2024
1 parent 48beb57 commit bf890d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
19 changes: 5 additions & 14 deletions patientsearch/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,9 @@ def post_resource(resource_type):
:param request.body: Must include the valid JSON FHIR Resource
"""
token = validate_auth()
active_patient_flag = current_app.config.get("ACTIVE_PATIENT_FLAG")
reactivate_patient = current_app.config.get("REACTIVATE_PATIENT")
params = dict(deepcopy(request.args)) # Necessary on ImmutableMultiDict

if active_patient_flag and reactivate_patient:
create_new_patient = params.pop("create_new", False)
else:
create_new_patient = False

token = validate_auth()
try:
resource = request.get_json()
if not resource:
Expand All @@ -329,26 +322,24 @@ def post_resource(resource_type):
f"{resource['resourceType']} != {resource_type}"
)

resource = new_resource_hook(resource, create_new_patient)
resource = new_resource_hook(resource)
method = request.method
if active_patient_flag:
if create_new_patient:
# Ensure it is a new active patient
method = "POST"
# Ensure it is an active patient
resource["active"] = True

audit_HAPI_change(
user_info=current_user_info(token),
method=method,
params=params,
params=request.args,
resource=resource,
resource_type=resource_type,
)
return jsonify(
HAPI_request(
token=token,
method=method,
params=params,
params=request.args,
resource_type=resource_type,
resource=resource,
)
Expand Down
4 changes: 2 additions & 2 deletions patientsearch/models/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,15 @@ def internal_patient_search(token, patient, active_only=False):
)


def new_resource_hook(resource, create_new_patient=False):
def new_resource_hook(resource):
"""Return modified version of resourse as per new resource rules
Products occasionally require customization of resources on creation.
This hook manages such, using environment to specialize.
:returns: modified resource
"""
if resource.get("id") and not create_new_patient:
if resource.get("id"):
# not a new resource, bail
return resource

Expand Down
5 changes: 2 additions & 3 deletions patientsearch/src/js/context/PatientListContextProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,13 @@ export default function PatientListContextProvider({ children }) {
.map((item) => item.resource)
.sort((a, b) => parseInt(b.id) - parseFloat(a.id));
const activeEntries = entries.filter((item) => {
if (typeof item.active === "undefined") {
if (item.hasOwnProperty('active')) {

Check failure on line 751 in patientsearch/src/js/context/PatientListContextProvider.js

View workflow job for this annotation

GitHub Actions / ESLint

patientsearch/src/js/context/PatientListContextProvider.js#L751

Do not access Object.prototype method 'hasOwnProperty' from target object (no-prototype-builtins)
return true;
}
return String(item.active).toLowerCase() === "true";
});
const inactiveEntries = entries.filter((item) => {
if (typeof item.active === "undefined") {
if (item.hasOwnProperty('active')) {

Check failure on line 757 in patientsearch/src/js/context/PatientListContextProvider.js

View workflow job for this annotation

GitHub Actions / ESLint

patientsearch/src/js/context/PatientListContextProvider.js#L757

Do not access Object.prototype method 'hasOwnProperty' from target object (no-prototype-builtins)
return false;
}
return String(item.active).toLowerCase() === "false";
Expand All @@ -781,7 +781,6 @@ export default function PatientListContextProvider({ children }) {
: getFirstResourceFromFhirBundle(bundleResult);
rowData.resource = {
...entryToUse,
active: true,
};
rowData.id = entryToUse.id;
}
Expand Down

0 comments on commit bf890d3

Please sign in to comment.