Skip to content

Commit ddb7788

Browse files
Drop/Create EHR Index Page (#1084)
* Add new Postgres Migration admin page * Create actions for dropping and creating the EHR indices. * Only add clinical_observations index for now.
1 parent 4ecb104 commit ddb7788

File tree

5 files changed

+492
-82
lines changed

5 files changed

+492
-82
lines changed

EHR_App/test/src/org/labkey/test/tests/EHR_AppTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ protected List<String> skipLinksForValidation()
130130
links.add("ehr-colonyOverview.view");
131131
links.add("ehr-updateTable.view");
132132
links.add("ehr-populateLookupData.view");
133+
links.add("ehr-postgresMigration.view");
133134
return links;
134135
}
135136

ehr/resources/views/ehrAdmin.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ <h4><b>Admin:</b></h4>
1111
<div><a class="labkey-text-link" href="<%=contextPath%><%=containerPath%>/ehr-cacheLivingAnimals.view">Cache Demographics On All Living Animals</a></div>
1212
<div><a class="labkey-text-link" href="<%=contextPath%><%=containerPath%>/ehr-cacheLivingAnimals.view?includeAll=true">Cache Demographics On All Animals</a></div>
1313
<div><a class="labkey-text-link" href="<%=contextPath%><%=containerPath%>/ehr-geneticCalculationSettings.view">Genetics Calculations</a></div>
14+
<div><a class="labkey-text-link" href="<%=contextPath%><%=containerPath%>/ehr-postgresMigration.view">Postgres Migration</a></div>
1415
</div>
1516

1617
<div class="lead">
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<div class="col-lg-3">
2+
<div class="lead">
3+
<div><a id="dropIndicesLink" class="labkey-text-link" href="#">Drop Indices</a></div>
4+
<div><a id="addIndicesLink" class="labkey-text-link" href="#">Add Indices</a></div>
5+
</div>
6+
</div>
7+
<script type="text/javascript" nonce="<%=scriptNonce%>">
8+
function indexAction(operation) {
9+
LABKEY.Ajax.request({
10+
url: LABKEY.ActionURL.buildURL('ehr', 'updateEHRIndices'),
11+
method: 'POST',
12+
jsonData: {
13+
operation: operation
14+
},
15+
success: function(response) {
16+
var json = JSON.parse(response.responseText);
17+
if (json.success) {
18+
alert('Success!');
19+
} else {
20+
alert('Failure: ' + (json.message || 'Unknown error'));
21+
}
22+
},
23+
failure: function(response) {
24+
var message = 'Request failed';
25+
try {
26+
var json = JSON.parse(response.responseText);
27+
if (json.exception) {
28+
message = json.exception;
29+
}
30+
} catch (e) {
31+
// ignore parse error
32+
}
33+
alert('Failure: ' + message);
34+
}
35+
});
36+
}
37+
38+
LABKEY.Utils.attachEventHandler('dropIndicesLink', 'click', function(e) {
39+
e.preventDefault();
40+
indexAction('drop');
41+
}, 1);
42+
43+
LABKEY.Utils.attachEventHandler('addIndicesLink', 'click', function(e) {
44+
e.preventDefault();
45+
indexAction('add');
46+
}, 1);
47+
</script>

ehr/src/org/labkey/ehr/EHRController.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,70 @@ public ApiResponse execute(RecordDeleteForm form, BindException errors)
684684
}
685685
}
686686

687+
public static class UpdateEHRIndicesForm
688+
{
689+
private String _operation;
690+
691+
public String getOperation()
692+
{
693+
return _operation;
694+
}
695+
696+
public void setOperation(String operation)
697+
{
698+
_operation = operation;
699+
}
700+
}
701+
702+
@RequiresPermission(AdminPermission.class)
703+
public static class UpdateEHRIndicesAction extends MutatingApiAction<UpdateEHRIndicesForm>
704+
{
705+
@Override
706+
public void validateForm(UpdateEHRIndicesForm form, Errors errors)
707+
{
708+
super.validateForm(form, errors);
709+
710+
if (form.getOperation() == null)
711+
{
712+
errors.reject(ERROR_MSG, "Operation parameter is required.");
713+
}
714+
else if (!"add".equalsIgnoreCase(form.getOperation()) && !"drop".equalsIgnoreCase(form.getOperation()))
715+
{
716+
errors.reject(ERROR_MSG, "Invalid operation. Must be 'add' or 'drop'.");
717+
}
718+
}
719+
720+
@Override
721+
public ApiResponse execute(UpdateEHRIndicesForm form, BindException errors)
722+
{
723+
try
724+
{
725+
List<String> messages;
726+
727+
if ("drop".equalsIgnoreCase(form.getOperation()))
728+
{
729+
messages = EHRManager.get().dropEHRIndices(getContainer(), getUser());
730+
}
731+
else
732+
{
733+
messages = EHRManager.get().addEHRIndices(getContainer(), getUser());
734+
}
735+
736+
Map<String, Object> response = new HashMap<>();
737+
response.put("success", true);
738+
response.put("messages", messages);
739+
return new ApiSimpleResponse(response);
740+
}
741+
catch (Exception e)
742+
{
743+
Map<String, Object> response = new HashMap<>();
744+
response.put("success", false);
745+
response.put("message", e.getMessage());
746+
return new ApiSimpleResponse(response);
747+
}
748+
}
749+
}
750+
687751
public static class AnimalDetailsForm
688752
{
689753
private String[] _animalIds;

0 commit comments

Comments
 (0)