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

process calculation rules #481

Merged
merged 12 commits into from
Jul 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,15 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
}


function resetCalculationValues(index: number, calculation: CalculatedValueFormModel) {
function resetCalculationValue(index: number, calculation: CalculatedValueFormModel) {
const list = [...calculationList];
list[index].result = ""
list[index].result = null
list[index].testId = null
}

function resetOperationValue(index: number, operationIndex: number, operation: OperationModel) {
const list = [...calculationList];
list[index].operations[operationIndex].value = ""
list[index].operations[operationIndex].value = null;
}

const handleCalculationFieldChange = (e: any, index: number) => {
Expand Down Expand Up @@ -260,6 +260,11 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
}
};

function replaceString(string : string, sequenceToReplace:string, replacement:string) {
const regex = new RegExp(sequenceToReplace, 'g');
return string.replace(regex, replacement);
}

const handleSubmit = (event: any, index: number) => {
event.preventDefault();
var mathematicalOpeartion = "";
Expand All @@ -269,6 +274,12 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
mathematicalOpeartion = mathematicalOpeartion + operation.value + " ";
}
)
// for the function validation , remove text values
mathematicalOpeartion = replaceString(mathematicalOpeartion ,"AGE" , "0");
mathematicalOpeartion = replaceString(mathematicalOpeartion ,"WEIGHT" , "0")
mathematicalOpeartion = replaceString(mathematicalOpeartion ,"IS_IN_NORMAL_RANGE" , ">=0 && 1<=10")
mathematicalOpeartion = replaceString(mathematicalOpeartion ,"IS_OUTSIDE_NORMAL_RANGE" , "<0 || 1>10")

try {
// Code that might throw an error
eval(mathematicalOpeartion)
Expand All @@ -291,7 +302,7 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
labelText={<FormattedMessage id="rulebuilder.label.selectSample" />}
value={operation.sampleId}
className="inputSelect"
onChange={(e) => { handleSampleSelected(e, "TEST_RESULT", index, operationIndex); handleOperationFieldChange(e, index, operationIndex); resetOperationValue(index, operationIndex, operation) }}
onChange={(e) => { handleSampleSelected(e, "TEST_RESULT", index, operationIndex); handleOperationFieldChange(e, index, operationIndex); /*resetOperationValue(index, operationIndex, operation)*/ }}
required
>
<SelectItem
Expand Down Expand Up @@ -515,11 +526,11 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
</div>
<div className="section">
<div className="inlineDiv">
{"[ "} &nbsp; {calculation.operations.map((operation, opearationIndex) => (
&nbsp; {calculation.operations.map((operation, opearationIndex) => (
<div>
{operation.type === 'PATIENT_ATTRIBUTE' ? "patientAttr=" : ""}{operation.type === 'TEST_RESULT' ? "testId=" : ""}{operation.value} &nbsp;
{operation.type === 'PATIENT_ATTRIBUTE' ? "patientAttribute#" : ""}{operation.type === 'TEST_RESULT' ? "test#" : ""}{operation.value} &nbsp;
</div>
))} {"] => testId=" + calculation.testId}
))} {" => test#" + calculation.testId}
</div>
</div>
{calculation.operations.map((operation, operation_index) => (
Expand Down Expand Up @@ -580,7 +591,7 @@ const CalculatedValue: React.FC<CalculatedValueProps> = () => {
labelText={<FormattedMessage id="rulebuilder.label.selectSample" />}
value={calculation.sampleId}
className="inputSelect"
onChange={(e) => { handleSampleSelected(e, "FINAL_RESULT", index, 0); handleCalculationFieldChange(e, index); resetCalculationValues(index, calculation) }}
onChange={(e) => { handleSampleSelected(e, "FINAL_RESULT", index, 0); handleCalculationFieldChange(e, index); /*resetCalculationValue(index, calculation)*/ }}
required
>
<SelectItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,17 @@ public List<ResultTree> getResultTreeArray(@RequestParam String patientId) {

for (Result result : testResultentry.getValue()) {
ResultDisplay resultDisplay = new ResultDisplay();
if(result.getResultType().equals("N")){
resultDisplay.setValue(result.getValue(true));
}else {
String dict = dictionaryService.get(result.getValue()).getDictEntry();
resultDisplay.setValue(dict);
String resultType =testService.getResultType(result.getTestResult().getTest());
if (resultType.equals("N")) {
resultDisplay.setValue(result.getValue() != null ? result.getValue(true) : "");
} else {
if (result.getValue() != null) {
String dict = dictionaryService.get(result.getValue()).getDictEntry();
resultDisplay.setValue(dict);
}else{
resultDisplay.setValue("");
}

}

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Expand All @@ -130,7 +136,7 @@ public List<ResultTree> getResultTreeArray(@RequestParam String patientId) {
TestDisplay testDisplay = new TestDisplay();
testDisplay.setDisplay(testResultentry.getKey().getLocalizedName());
testDisplay.setConceptUuid(testResultentry.getKey().getId());
testDisplay.setDatatype(testResultentry.getValue().iterator().next().getResultType());
testDisplay.setDatatype(testService.getResultType(testResultentry.getValue().iterator().next().getTestResult().getTest()));
testDisplay.setHiNormal(testResultentry.getValue().iterator().next().getMaxNormal());
testDisplay.setLowNormal(testResultentry.getValue().iterator().next().getMinNormal());
testDisplay.setHighCritical(testResultentry.getValue().iterator().next().getMaxNormal());
Expand Down Expand Up @@ -201,7 +207,7 @@ public PanelDisplay getTestResultTree(@RequestParam String patientId, @RequestPa

for (Result result : testResultentry.getValue()) {
ResultDisplay resultDisplay = new ResultDisplay();
resultDisplay.setValue(result.getValue(true));
resultDisplay.setValue(result.getValue(true) != null ? result.getValue(true) : "");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
resultDisplay.setObsDatetime(dateFormat.format(result.getLastupdated()));
resultDisplays.add(resultDisplay);
Expand All @@ -210,7 +216,7 @@ public PanelDisplay getTestResultTree(@RequestParam String patientId, @RequestPa
TestDisplay testDisplay = new TestDisplay();
testDisplay.setDisplay(testResultentry.getKey().getLocalizedName());
testDisplay.setConceptUuid(testResultentry.getKey().getId());
testDisplay.setDatatype(testResultentry.getValue().iterator().next().getResultType());
testDisplay.setDatatype(testService.getResultType(testResultentry.getValue().iterator().next().getTestResult().getTest()));
testDisplay.setHiNormal(testResultentry.getValue().iterator().next().getMaxNormal());
testDisplay.setLowNormal(testResultentry.getValue().iterator().next().getMinNormal());
testDisplay.setHighCritical(testResultentry.getValue().iterator().next().getMaxNormal());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.openelisglobal.sample.valueholder.Sample;
import org.openelisglobal.sampleitem.valueholder.SampleItem;
import org.openelisglobal.spring.util.SpringContext;
import org.openelisglobal.testcalculated.action.util.TestCalculatedUtil;
import org.openelisglobal.testreflex.action.util.TestReflexBean;
import org.openelisglobal.testreflex.action.util.TestReflexUtil;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -167,13 +168,16 @@ private void saveReferralsWithRequiredObjects(ReferralSet referralSet, String sy

protected List<Analysis> setTestReflexes(ResultsUpdateDataSet actionDataSet, String sysUserId) {
TestReflexUtil testReflexUtil = new TestReflexUtil();
TestCalculatedUtil testCallatedUtil = new TestCalculatedUtil();
List allResults = actionDataSet.getNewResults();
allResults.addAll(actionDataSet.getModifiedResults());
List<Analysis> reflexAnalysises = testReflexUtil
.addNewTestsToDBForReflexTests(convertToTestReflexBeanList(allResults), sysUserId);
testReflexUtil.updateModifiedReflexes(convertToTestReflexBeanList(actionDataSet.getModifiedResults()),
sysUserId);
return reflexAnalysises;
List<Analysis> caclculatedAnalyses = testCallatedUtil.addNewTestsToDBForCalculatedTests(allResults, sysUserId) ;
reflexAnalysises.addAll(caclculatedAnalyses);
return reflexAnalysises;
}

private List<TestReflexBean> convertToTestReflexBeanList(List<ResultSet> resultSetList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public String getValue() {
}

public String getValue(Boolean getActualNumericValue) {
if (getActualNumericValue) {
if (getActualNumericValue && this.resultType != null) {
if ((this.resultType.equals("N") || this.resultType.equals("D") || this.resultType.equals("A"))
&& this.value != null) {
return StringUtil.getActualNumericValue(value);
Expand Down
Loading
Loading