Skip to content

Commit

Permalink
Merge pull request #1148 from mozzy11/develop
Browse files Browse the repository at this point in the history
imrpove loading rule meatadata
  • Loading branch information
mozzy11 committed Jun 27, 2024
2 parents b44e2ce + eef7978 commit 602ff5d
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,31 +107,59 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
const loadCalculationList = (calculations) => {
if (componentMounted.current) {
// console.log(JSON.stringify(reflexRuleList))
const sampleList = [];
if (calculations.length > 0) {
setCalculationList(calculations);

calculations.forEach((calculation, index) => {
if (calculation.sampleId) {
getFromOpenElisServer(
"/rest/test-display-beans?sampleType=" + calculation.sampleId,
(resp) => fetchTests(resp, "FINAL_RESULT", index, 0),
);
sampleList.push(calculation.sampleId);
}

calculation.operations.forEach((operation, opeartionIdex) => {
if (operation.sampleId) {
getFromOpenElisServer(
"/rest/test-display-beans?sampleType=" + operation.sampleId,
(resp) => fetchTests(resp, "TEST_RESULT", index, opeartionIdex),
);
sampleList.push(operation.sampleId);
}
});
});
getFromOpenElisServer(
"/rest/test-display-beans-map?samplesTypes=" + sampleList.join(","),
(resp) => buildSampleTests(resp, calculations),
);
}
setLoading(false);
}
};

const buildSampleTests = (sampleTestsMap, calculations) => {
if (calculations.length > 0) {
setCalculationList(calculations);

calculations.forEach((calculation, index) => {
if (calculation.sampleId) {
sampleList.push(calculation.sampleId);
fetchTests(
sampleTestsMap[calculation.sampleId],
"FINAL_RESULT",
index,
0,
);
}

calculation.operations.forEach((operation, opeartionIdex) => {
if (operation.sampleId) {
fetchTests(
sampleTestsMap[operation.sampleId],
"TEST_RESULT",
index,
opeartionIdex,
);
}
});
});
}
};

const loadMathFunctions = (functions) => {
setMathFunctions(functions);
};
Expand Down Expand Up @@ -167,9 +195,6 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
};

const handleRuleRemove = (index, id) => {
const list = [...calculationList];
list.splice(index, 1);
setCalculationList(list);
if (id) {
postToOpenElisServer(
"/rest/deactivate-test-calculation/" + id,
Expand All @@ -187,6 +212,7 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
title: intl.formatMessage({ id: "notification.title" }),
message: intl.formatMessage({ id: "delete.success.msg" }),
});
window.location.reload()
} else {
addNotification({
kind: NotificationKinds.error,
Expand Down
65 changes: 40 additions & 25 deletions frontend/src/components/admin/reflexTests/ReflexRuleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,54 @@ function ReflexRule() {
}, [ruleList]);

const loadDefaultTestResultList = () => {
var sampleList = [];
ruleList.forEach(function (rule, index) {
if (rule.conditions) {
rule.conditions.forEach(function (condition, conditionIndex) {
if (condition.sampleId) {
getFromOpenElisServer(
"/rest/test-display-beans?sampleType=" + condition.sampleId,
(resp) =>
fetchDeafultTests(
resp,
index,
conditionIndex,
FIELD.conditions,
condition,
),
sampleList.push(condition.sampleId);
}
});
}
if (rule.actions) {
rule.actions.forEach(function (action, actionIndex) {
if (action.sampleId) {
sampleList.push(action.sampleId);
}
});
}
});

getFromOpenElisServer(
"/rest/test-display-beans-map?samplesTypes=" + sampleList.join(","),
(resp) => buildSampleTests(resp),
);
};

const buildSampleTests = (sampleTestsMap) => {
ruleList.forEach(function (rule, index) {
if (rule.conditions) {
rule.conditions.forEach(function (condition, conditionIndex) {
if (condition.sampleId) {
fetchDeafultTests(
sampleTestsMap[condition.sampleId],
index,
conditionIndex,
FIELD.conditions,
condition,
);
}
});
}
if (rule.actions) {
rule.actions.forEach(function (action, actionIndex) {
if (action.sampleId) {
getFromOpenElisServer(
"/rest/test-display-beans?sampleType=" + action.sampleId,
(resp) =>
fetchDeafultTests(
resp,
index,
actionIndex,
FIELD.actions,
null,
),
fetchDeafultTests(
sampleTestsMap[action.sampleId],
index,
actionIndex,
FIELD.actions,
null,
);
}
});
Expand Down Expand Up @@ -273,9 +290,6 @@ function ReflexRule() {
};

const handleRuleRemove = (index, id) => {
const list = [...ruleList];
list.splice(index, 1);
setRuleList(list);
if (id) {
postToOpenElisServer(
"/rest/deactivate-reflexrule/" + id,
Expand All @@ -291,13 +305,14 @@ function ReflexRule() {
addNotification({
kind: NotificationKinds.success,
title: intl.formatMessage({ id: "notification.title" }),
message: intl.formatMessage({ id: "success.deleted.msg" }),
message: intl.formatMessage({ id: "delete.success.msg" }),
});
window.location.reload()
} else {
addNotification({
kind: NotificationKinds.error,
title: intl.formatMessage({ id: "notification.title" }),
message: intl.formatMessage({ id: "error.deleted.msg" }),
message: intl.formatMessage({ id: "delete.error.msg" }),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.openelisglobal.common.rest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -478,6 +481,28 @@ public List<IdValuePair> getDepartmentsForReferingSite(@RequestParam String reff
@GetMapping(value = "test-display-beans", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<TestDisplayBean> getTestBeansBySample(@RequestParam(required = false) String sampleType) {
return getTestBeansForSample(sampleType);
}

@GetMapping(value = "test-display-beans-map", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, List<TestDisplayBean>> getTestBeansMap(@RequestParam(required = false) String samplesTypes) {

List<String> samplesList = new ArrayList<>();
if (StringUtils.isNotBlank(samplesTypes)) {
samplesList = Arrays.asList(samplesTypes.split(","));
}
Set<String> sampleSet = new HashSet<>(samplesList);
Map<String, List<TestDisplayBean>> testBeanMap = new HashMap<>();

sampleSet.forEach(sampleType -> {
testBeanMap.put(sampleType, getTestBeansForSample(sampleType));
});
return testBeanMap;
}

private List<TestDisplayBean> getTestBeansForSample(String sampleType) {

List<TestDisplayBean> testItems = new ArrayList<>();
List<Test> testList = new ArrayList<>();
if (StringUtils.isNotBlank(sampleType)) {
Expand Down Expand Up @@ -509,5 +534,6 @@ public int compare(TestDisplayBean o1, TestDisplayBean o2) {
});
}
return testItems;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ public void saveReflexRule(HttpServletRequest request, @RequestBody Calculation
@PostMapping(value = "deactivate-test-calculation/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public void deactivateReflexRule(@PathVariable Integer id) {
Calculation calculation = testCalculationService.get(id);
calculation.setActive(false);
testCalculationService.update(calculation);
try {
Calculation calculation = testCalculationService.get(id);
calculation.setActive(false);
testCalculationService.update(calculation);

} catch (Exception e) {

}

}

@GetMapping(value = "test-calculations", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ public void saveReflexRule(HttpServletRequest request, @RequestBody ReflexRule r
@PostMapping(value = "deactivate-reflexrule/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public void deactivateReflexRule(@PathVariable String id) {
reflexService.deactivateReflexRule(id);
try {
reflexService.deactivateReflexRule(id);
} catch (Exception e) {
}

}

@GetMapping(value = "reflexrules", produces = MediaType.APPLICATION_JSON_VALUE)
Expand Down

0 comments on commit 602ff5d

Please sign in to comment.