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

Fix card export errors sage 248 #44

Merged
merged 3 commits into from
Mar 11, 2022
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
54 changes: 22 additions & 32 deletions src/dialogs/export-dialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,25 @@ class ExportDialog extends React.Component {
buildJson() {
let [resource, errCount, errFields] = Array.from(
SchemaUtils.toFhir(this.props.bundle.resources[this.props.bundle.pos], true)
);
);

function removeEmptyFields(obj) {
return function remove(current) {
_.forOwn(current, function (value, key) {
if (_.isUndefined(value) || _.isNull(value) || _.isNaN(value) ||
(_.isString(value) && _.isEmpty(value)) ||
(_.isObject(value) && _.isEmpty(remove(value)))) {
delete current[key];
}
});
if (_.isArray(current)) _.pull(current, undefined);

return current;

}(_.cloneDeep(obj));
}



// Convert all resources to FHIR JSON
const resourcesJson = [];
Expand Down Expand Up @@ -66,14 +84,14 @@ class ExportDialog extends React.Component {
}
}
}

var bundleJson;
if (this.props.bundle) {
bundleJson = BundleUtils.generateBundle(
resourcesJson
);
}
const jsonString = JSON.stringify(bundleJson, null, 3);

const jsonString = JSON.stringify(removeEmptyFields(bundleJson), null, 3);
return {jsonString, errCount, errFields, resourceType: resource.resourceType};
}

Expand All @@ -85,26 +103,6 @@ class ExportDialog extends React.Component {
return saveAs(blob, fileName);
}

handleUpdate(e) {
e.preventDefault();
const resid = $("#resource_id").val();
const posturl = `/fhir/fhir/${$("#resource_type").val()}/${resid}`;
//postdata = JSON.stringify( { "resource-create-body": jsonString, "resource-create-id": resid } )
const {jsonString, resourceType} = this.buildJson();
return $.ajax(posturl, {
type: "PUT",
//dataType: 'json'
contentType: "application/json+fhir",
data: jsonString,
error(jqXHR, textStatus, errorThrown) {
return $("body").append(`AJAX Error: ${textStatus}`);
},
success(data, textStatus, jqXHR) {
return $("body").append(`Successful AJAX call: ${data}`);
}
});
}

//help the user with a select all if they hit the
//control key with nothing selected
handleKeyDown(e) {
Expand Down Expand Up @@ -178,15 +176,7 @@ class ExportDialog extends React.Component {
<button
className="btn btn-default"
onClick={this.handleDownload.bind(this)}
>{`\
\t\t\t\t\tDownload\
`}</button>
<button
className="btn btn-default"
onClick={this.handleUpdate.bind(this)}
>{`\
\t\t\t\t\tUpdate\
`}</button>
>Download</button>
</Modal.Footer>
</Modal>
);
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/schema-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,12 @@ export function toFhir(decorated: SageNodeInitialized, validate: boolean): [Sage
}

if (err) {
errFields.push(child.schemaPath.substring(child.schemaPath.indexOf(".") + 1));
errFields.push(child.schemaPath + ' - ' + err);
errCount++;
}
return child.value;
}
})();

if (parent instanceof Array) {
parent.push(value);
} else {
Expand Down