Skip to content

Commit

Permalink
Merge pull request #1289 from CalebSLane/develop
Browse files Browse the repository at this point in the history
Panel FHIR ordering
  • Loading branch information
mozzy11 authored Oct 28, 2024
2 parents f3f13ea + 5360020 commit 17d8adf
Show file tree
Hide file tree
Showing 30 changed files with 286 additions and 167 deletions.
8 changes: 6 additions & 2 deletions frontend/src/components/addOrder/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,18 @@ const Index = () => {
let nodes =
elements[tag] instanceof Array ? elements[tag] : [elements[tag]];
let objList = [];

for (let j = 0; j < nodes.length; j++) {
let name = nodes[j].name;
let id = nodes[j].id;
if (tag == "panel") {
objList[j] = newPanel(id, name);
let testNodes = elements.panelTests;
let testNodes = nodes[j].panelTests;
if (testNodes.length === undefined) {
testNodes = [testNodes];
}
for (let x = 0; x < testNodes.length; x++) {
let ptNodes = elements.test;
let ptNodes = testNodes[x].test;
for (let y = 0; y < ptNodes.length; y++) {
let pName = ptNodes[y].name;
let pId = ptNodes[y].id;
Expand Down
89 changes: 49 additions & 40 deletions frontend/src/components/addOrder/SampleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,17 @@ const SampleType = (props) => {

const handleRemoveSelectedTest = (test) => {
removedTestFromSelectedTests(test);
updateSampleTypeTests(test, false);
};

const handleFilterSelectTest = (test) => {
setTestSearchTerm("");
addTestToSelectedTests(test);
updateSampleTypeTests(test, true);
};

function updateSampleTypeTests(test, userBenchChoice = false) {
let tests = [...sampleTypeTests.tests];
let testIndex = findTestIndex(test.id);
tests[testIndex].userBenchChoice = userBenchChoice;
setSampleTypeTests({ ...sampleTypeTests, tests: tests });
}

const handleTestCheckbox = (e, test) => {
if (e.currentTarget.checked) {
updateSampleTypeTests(test, true);
addTestToSelectedTests(test);
} else {
updateSampleTypeTests(test, false);
removedTestFromSelectedTests(test);
}
};
Expand All @@ -181,17 +170,36 @@ const SampleType = (props) => {
return sampleTypeTests.tests.findIndex((test) => test.id === testId);
}

const triggerPanelCheckBoxChange = (isChecked, testMaps) => {
const testIds = testMaps.split(",").map((id) => id.trim());
testIds.map((testId) => {
const panelIsSelected = (panelId) => {
for (let i in selectedPanels) {
if (selectedPanels[i].id === panelId) {
return true;
}
}
return false;
};

const testIsSelected = (testId) => {
for (let i in selectedTests) {
if (selectedTests[i].id === testId) {
return true;
}
}
return false;
};

const triggerPanelCheckBoxChange = (isChecked, testIds) => {
const testIdsList = testIds.split(",").map((id) => id.trim());
testIdsList.map((testId) => {
let testIndex = findTestIndex(testId);
let test = findTestById(testId);
if (testIndex !== -1) {
updateSampleTypeTests(test, isChecked);
if (isChecked) {
setSelectedTests((prevState) => {
return [...prevState, { id: test.id, name: test.name }];
});
if (!testIsSelected(test.id)) {
setSelectedTests((prevState) => {
return [...prevState, { id: test.id, name: test.name }];
});
}
} else {
removedTestFromSelectedTests(test);
}
Expand Down Expand Up @@ -288,13 +296,6 @@ const SampleType = (props) => {
}
}, [requestTestReferral]);

useEffect(() => {
props.sampleTypeObject({
selectedTests: selectedTests,
sampleObjectIndex: index,
});
}, [selectedTests]);

useEffect(() => {
props.sampleTypeObject({
referralItems: referralRequests,
Expand Down Expand Up @@ -331,11 +332,9 @@ const SampleType = (props) => {

const removedPanelFromSelectedPanels = (panel) => {
let index = 0;
let panelId = panel.id !== undefined ? panel.id : panel.panelId;

for (let i in selectedPanels) {
if (selectedPanels[i].id === panelId) {
triggerPanelCheckBoxChange(false, selectedPanels[i].testMaps);
if (selectedPanels[i].id === panel.id) {
triggerPanelCheckBoxChange(false, selectedPanels[i].testIds);
const newPanels = selectedPanels;
newPanels.splice(index, 1);
setSelectedPanels([...newPanels]);
Expand All @@ -359,8 +358,8 @@ const SampleType = (props) => {
addPanelToSelectedPanels(panel);
};

const handlePanelCheckbox = (e, panel) => {
if (e.currentTarget.checked) {
const handlePanelCheckbox = (panel) => {
if (!panelIsSelected(panel.id)) {
addPanelToSelectedPanels(panel);
} else {
removedPanelFromSelectedPanels(panel);
Expand All @@ -372,15 +371,16 @@ const SampleType = (props) => {
};

function addTestToSelectedTests(test) {
setSelectedTests([...selectedTests, { id: test.id, name: test.name }]);
if (!testIsSelected(test.id)) {
setSelectedTests([...selectedTests, { id: test.id, name: test.name }]);
}
}

const addPanelToSelectedPanels = (panel) => {
setSelectedPanels([
...selectedPanels,
{ id: panel.panelId, name: panel.name, testMaps: panel.testMaps },
{ id: panel.id, name: panel.name, testIds: panel.testIds },
]);
triggerPanelCheckBoxChange(true, panel.testMaps);
};

useEffect(() => {
Expand All @@ -403,12 +403,22 @@ const SampleType = (props) => {
});
}, [rejectionReasonsDisabled]);

useEffect(() => {
props.sampleTypeObject({
selectedTests: selectedTests,
sampleObjectIndex: index,
});
}, [selectedTests]);

useEffect(() => {
props.sampleTypeObject({
selectedPanels: selectedPanels,
sampleObjectIndex: index,
});
}, [selectedPanels]);
for (let i in selectedPanels) {
triggerPanelCheckBoxChange(true, selectedPanels[i].testIds);
}
}, [selectedPanels, sampleTypeTests]);

const repopulateUI = () => {
if (props.sample !== null) {
Expand Down Expand Up @@ -599,12 +609,12 @@ const SampleType = (props) => {
""
) : (
<Checkbox
onChange={(e) => handlePanelCheckbox(e, panel)}
onChange={() => handlePanelCheckbox(panel)}
labelText={panel.name}
id={`panel_` + index + "_" + panel.panelId}
key={index + panel.panelId}
id={`panel_` + index + "_" + panel.id}
key={index + panel.id}
checked={
selectedPanels.filter((item) => item.id === panel.panelId)
selectedPanels.filter((item) => item.id === panel.id)
.length > 0
}
/>
Expand Down Expand Up @@ -707,7 +717,6 @@ const SampleType = (props) => {
selectedTests.filter((item) => item.id === test.id).length >
0
}
// checked={test.userBenchChoice}
/>
);
})}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/admin/menu/GlobalMenuManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function GlobalMenuManagement() {

const [loading, setLoading] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [showChildren, setShowChildren] = useState(false);
const [showChildren, setShowChildren] = useState(true);
const [menuItem, setMenuItem] = useState({
menu: { isActive: true, elementId: "menu_sidenav" },
childMenus: [],
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/admin/menu/MenuUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ export const MenuCheckBox = (props) => {
style={{ marginLeft: 2 * depth + "rem" }}
>
<Checkbox
id={curMenuItem?.menu.elementId}
id={curMenuItem?.menu.elementId + "_checkbox"}
labelText={intl.formatMessage({
id: labelKey
? labelKey
: curMenuItem.menu.displayKey
? curMenuItem.menu.displayKey
: "missing display key",
})}
disabled={curMenuItem.menu.elementId === "menu_sidenav"}
checked={curMenuItem?.menu.isActive}
onChange={(_, { checked }) => {
if (path === "$" || !path) {
Expand Down
14 changes: 6 additions & 8 deletions frontend/src/components/batchOrderEntry/SampleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,16 @@ const SampleType = ({ updateFormValues }) => {
if (isChecked) {
updatedPanels = [
...selectedPanels,
{ id: panel.panelId, name: panel.name, testMaps: panel.testMaps },
{ id: panel.id, name: panel.name, testIds: panel.testIds },
];
} else {
updatedPanels = selectedPanels.filter(
(item) => item.id !== panel.panelId,
);
updatedPanels = selectedPanels.filter((item) => item.id !== panel.id);
}
setSelectedPanels(updatedPanels);

var updatedTests = [...selectedTests];

const testMapIds = panel.testMaps.split(",");
const testMapIds = panel.testIds.split(",");
if (isChecked) {
testMapIds.forEach((testId) => {
const isTestSelected = updatedTests.some((test) => test.id === testId);
Expand Down Expand Up @@ -202,11 +200,11 @@ const SampleType = ({ updateFormValues }) => {
/>
{filteredPanels.map((panel) => (
<Checkbox
key={panel.panelId}
id={`panel_${panel.panelId}`}
key={panel.id}
id={`panel_${panel.id}`}
labelText={panel.name}
checked={selectedPanels.some(
(item) => item.id === panel.panelId,
(item) => item.id === panel.id,
)}
onChange={(e) => handlePanelCheckbox(e, panel)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const sampleTypeTestsStructure = {
panels: [
{
name: "",
testMaps: "",
testIds: "",
panelId: "1",
panelOrder: 0,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
"panels": [
{
"name": "Bilan Biochimique",
"testMaps": "7",
"testIds": "7",
"panelId": "1",
"panelOrder": 0
},
{
"name": "Serologie VIH",
"testMaps": "9,9",
"testIds": "9,9",
"panelId": "4",
"panelOrder": 0
},
{
"name": "Bilan Biochimique",
"testMaps": "7,8,9,10,11,12,13",
"testIds": "7,8,9,10,11,12,13",
"panelId": "1",
"panelOrder": 0
},
{
"name": "Serologie VIH",
"testMaps": "16,16",
"testIds": "16,16",
"panelId": "4",
"panelOrder": 0
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const BatchOrderEntryFormValues = {
panels: [
{
name: "",
testMaps: "",
testIds: "",
panelId: "",
panelOrder: 0,
},
Expand Down
22 changes: 10 additions & 12 deletions frontend/src/components/printBarcode/PrePrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const PrePrint = () => {
setSampleTypeTests({ ...sampleTypeTests, tests: tests });
}

const triggerPanelCheckBoxChange = (isChecked, testMaps) => {
const testIds = testMaps.split(",").map((id) => id.trim());
testIds.map((testId) => {
const triggerPanelCheckBoxChange = (isChecked, testIds) => {
const testIdsList = testIds.split(",").map((id) => id.trim());
testIdsList.map((testId) => {
let testIndex = findTestIndex(testId);
let test = findTestById(testId);
if (testIndex !== -1) {
Expand All @@ -85,18 +85,16 @@ const PrePrint = () => {
const addPanelToSelectedPanels = (panel) => {
setSelectedPanels([
...selectedPanels,
{ id: panel.panelId, name: panel.name, testMaps: panel.testMaps },
{ id: panel.id, name: panel.name, testIds: panel.testIds },
]);
triggerPanelCheckBoxChange(true, panel.testMaps);
triggerPanelCheckBoxChange(true, panel.testIds);
};

const removePanelFromSelectedPanels = (panel) => {
let index = 0;
let panelId = panel.id !== undefined ? panel.id : panel.panelId;

for (let i in selectedPanels) {
if (selectedPanels[i].id === panelId) {
triggerPanelCheckBoxChange(false, selectedPanels[i].testMaps);
if (selectedPanels[i].id === panel.id) {
triggerPanelCheckBoxChange(false, selectedPanels[i].testIds);
const newPanels = selectedPanels;
newPanels.splice(index, 1);
setSelectedPanels([...newPanels]);
Expand Down Expand Up @@ -318,10 +316,10 @@ const PrePrint = () => {
<Checkbox
onChange={(e) => handlePanelCheckbox(e, panel)}
labelText={panel.name}
id={"panel_" + panel.panelId}
key={panel.panelId}
id={"panel_" + panel.id}
key={panel.id}
checked={
selectedPanels.filter((item) => item.id === panel.panelId)
selectedPanels.filter((item) => item.id === panel.id)
.length > 0
}
/>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<properties>
<maven.java.release>11</maven.java.release>
<major.version>3</major.version>
<minor.version>0</minor.version>
<state.version>3</state.version>
<minor.version>1</minor.version>
<state.version>0</state.version>
<!-- 0 = alpha, 1 = beta, 2 = rc, 3 = deployable -->
<fix.version>4</fix.version>
<fix.version>0</fix.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<liquibase.propertyFile>${project.basedir}/liquibase/liquibase.properties</liquibase.propertyFile>
<castor.version>1.4.1</castor.version>
Expand Down
Loading

0 comments on commit 17d8adf

Please sign in to comment.