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

Load data dictionary case properties in chunks #34827

Merged
merged 18 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ hqDefine("data_dictionary/js/data_dictionary", [
moduleCount,
geoCaseProp,
isSafeToDelete,
changeSaveButton
changeSaveButton,
dataUrl
) {
var self = {};
self.name = name || gettext("No Name");
Expand All @@ -43,6 +44,7 @@ hqDefine("data_dictionary/js/data_dictionary", [
self.geoCaseProp = geoCaseProp;
self.canDelete = isSafeToDelete;
self.changeSaveButton = changeSaveButton;
self.dataUrl = dataUrl;

self.init = function (groupData) {
for (let group of groupData) {
Expand Down Expand Up @@ -82,10 +84,20 @@ hqDefine("data_dictionary/js/data_dictionary", [
);
groupObj.properties.push(propObj);
}
groupObj.properties.subscribe(self.changeSaveButton);
self.groups.push(groupObj);
}
};

self.fetchCaseProperties = function () {
if (self.groups().length === 0) {
zandre-eng marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admittedly don't have a lot of context around the data dictionary, hence me asking this: what is the group in this context and why do we check whether there is a group here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the user selects a case type, the viewmodel fetches its case properties.

The server returns the CaseProperty instances nested in their CasePropertyGroup instances ("data.groups" on line 96). (The CaseProperty instances that don't have a CasePropertyGroup are nested in a group with an empty name.)

So if self.groups() does not have a value, it means that the viewmodel has not fetched its case properties already, so it should do that now.

const caseTypeUrl = self.dataUrl + self.name + '/';
$.getJSON(caseTypeUrl, function (data) {
self.init(data.groups);
});
}
}

return self;
};

Expand Down Expand Up @@ -123,7 +135,7 @@ hqDefine("data_dictionary/js/data_dictionary", [
self.name.subscribe(changeSaveButton);
self.description.subscribe(changeSaveButton);
self.toBeDeprecated.subscribe(changeSaveButton);
zandre-eng marked this conversation as resolved.
Show resolved Hide resolved
self.properties.subscribe(changeSaveButton);
// Don't subscribe self.properties until they have been loaded

return self;
};
Expand Down Expand Up @@ -371,6 +383,7 @@ hqDefine("data_dictionary/js/data_dictionary", [
};

self.init = function (callback) {
// Get list of case types
$.getJSON(dataUrl, {load_deprecated_case_types: self.showDeprecatedCaseTypes()})
.done(function (data) {
_.each(data.case_types, function (caseTypeData) {
Expand All @@ -381,12 +394,14 @@ hqDefine("data_dictionary/js/data_dictionary", [
caseTypeData.module_count,
data.geo_case_property,
caseTypeData.is_safe_to_delete,
changeSaveButton
changeSaveButton,
dataUrl
);
caseTypeObj.init(caseTypeData.groups);
self.caseTypes.push(caseTypeObj);
});
if (self.caseTypes().length) {
// `self.goToCaseType()` calls `caseType.fetchCaseProperties()`
// to fetch the case properties of the first case type
self.goToCaseType(self.caseTypes()[0]);
}
self.caseGroupList.subscribe(changeSaveButton);
Expand Down Expand Up @@ -480,6 +495,7 @@ hqDefine("data_dictionary/js/data_dictionary", [
return;
}
}
caseType.fetchCaseProperties();
self.activeCaseType(caseType.name);
self.fhirResourceType(caseType.fhirResourceType());
self.removefhirResourceType(false);
Expand Down Expand Up @@ -656,7 +672,7 @@ hqDefine("data_dictionary/js/data_dictionary", [
};

$(function () {
var dataUrl = initialPageData.reverse('data_dictionary_json'),
var dataUrl = initialPageData.reverse('data_dictionary_json_case_types'),
casePropertyUrl = initialPageData.reverse('update_case_property'),
typeChoices = initialPageData.get('typeChoices'),
fhirResourceTypes = initialPageData.get('fhirResourceTypes'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h4 class="modal-title">{% trans "Create a new Case Type" %}</h4>
{% endblock %}

{% block page_content %}
{% registerurl 'data_dictionary_json' domain %}
{% registerurl 'data_dictionary_json_case_types' domain %}
{% registerurl 'update_case_property' domain %}
{% registerurl 'deprecate_or_restore_case_type' domain '---' %}
{% registerurl 'delete_case_type' domain '---' %}
Expand Down