diff --git a/frontend/src/components/data/PatientResultsTableHeaders.js b/frontend/src/components/data/PatientResultsTableHeaders.js
index c1df7721e5..2088aad9d8 100644
--- a/frontend/src/components/data/PatientResultsTableHeaders.js
+++ b/frontend/src/components/data/PatientResultsTableHeaders.js
@@ -25,4 +25,8 @@ export const patientSearchHeaderData = [
key: "nationalId",
header: ,
},
+ {
+ key: "dataSourceName",
+ header: ,
+ },
];
diff --git a/frontend/src/components/patient/SearchPatientForm.js b/frontend/src/components/patient/SearchPatientForm.js
index bf0a176197..ead34f0207 100644
--- a/frontend/src/components/patient/SearchPatientForm.js
+++ b/frontend/src/components/patient/SearchPatientForm.js
@@ -1,7 +1,7 @@
import React, { useContext, useState, useEffect } from "react";
import { FormattedMessage, injectIntl, useIntl } from "react-intl";
import "../Style.css";
-import { getFromOpenElisServer } from "../utils/Utils";
+import { getFromOpenElisServer, postToOpenElisServer } from "../utils/Utils";
import {
Form,
TextInput,
@@ -20,7 +20,10 @@ import {
TableCell,
Pagination,
Loading,
+ Toggle,
+ Tag,
} from "@carbon/react";
+import { Person } from "@carbon/react/icons";
import CustomLabNumberInput from "../common/CustomLabNumberInput";
import { patientSearchHeaderData } from "../data/PatientResultsTableHeaders";
import { Formik, Field } from "formik";
@@ -29,6 +32,7 @@ import { NotificationContext } from "../layout/Layout";
import { AlertDialog, NotificationKinds } from "../common/CustomNotification";
import CustomDatePicker from "../common/CustomDatePicker";
import { ConfigurationContext } from "../layout/Layout";
+import CreatePatientFormValues from "../formModel/innitialValues/CreatePatientFormValues";
function SearchPatientForm(props) {
const { notificationVisible, setNotificationVisible, addNotification } =
@@ -39,20 +43,101 @@ function SearchPatientForm(props) {
const [dob, setDob] = useState("");
const [patientSearchResults, setPatientSearchResults] = useState([]);
+ const [importStatus, setImportStatus] = useState({});
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(5);
const [loading, setLoading] = useState(false);
const [nextPage, setNextPage] = useState(null);
+ const [isToggled, setIsToggled] = useState(false);
const [previousPage, setPreviousPage] = useState(null);
const [pagination, setPagination] = useState(false);
const [url, setUrl] = useState("");
const [searchFormValues, setSearchFormValues] = useState(
SearchPatientFormValues,
);
+
+ const handlePatientImport = (patientId) => {
+ console.log("Import button clicked, patientId:", patientId);
+
+ const patientSelected = patientSearchResults.find(
+ (patient) => patient.patientID === patientId,
+ );
+ console.log("Patient selected:", patientSelected);
+
+ if (!patientSelected) {
+ addNotification({
+ title: intl.formatMessage({ id: "notification.title" }),
+ message: intl.formatMessage({ id: "error.no.patient.data" }),
+ kind: NotificationKinds.error,
+ });
+ return;
+ }
+
+ const dataToSend = {
+ ...CreatePatientFormValues,
+ patientPK: "",
+ nationalId: patientSelected.nationalId || "",
+ subjectNumber: "",
+ lastName: patientSelected.lastName || "",
+ firstName: patientSelected.firstName || "",
+ streetAddress: patientSelected.address?.street || "",
+ city: patientSelected.address?.city || "",
+ primaryPhone: patientSelected.contactPhone || "",
+ gender: patientSelected.gender || "",
+ birthDateForDisplay: patientSelected.birthdate || "",
+ commune: patientSelected.commune || "",
+ education: patientSelected.education || "",
+ maritialStatus: patientSelected.maritalStatus || "",
+ nationality: patientSelected.nationality || "",
+ healthDistrict: patientSelected.healthDistrict || "",
+ healthRegion: patientSelected.healthRegion || "",
+ otherNationality: patientSelected.otherNationality || "",
+ patientContact: {
+ person: {
+ firstName: patientSelected.contact?.firstName || "",
+ lastName: patientSelected.contact?.lastName || "",
+ primaryPhone: patientSelected.contact?.primaryPhone || "",
+ email: patientSelected.contact?.email || "",
+ },
+ },
+ };
+
+ console.log("Data to send:", dataToSend);
+
+ postToOpenElisServer(
+ "/rest/patient-management",
+ JSON.stringify(dataToSend),
+ (status) => {
+ handlePost(status, patientId);
+ },
+ );
+ };
+
+ const handlePost = (status, patientId) => {
+ setNotificationVisible(true);
+ if (status === 200) {
+ addNotification({
+ title: intl.formatMessage({ id: "notification.title" }),
+ message: intl.formatMessage({ id: "success.import.patient" }),
+ kind: NotificationKinds.success,
+ });
+ setImportStatus((prevStatus) => ({
+ ...prevStatus,
+ [patientId]: true,
+ }));
+ } else {
+ addNotification({
+ title: intl.formatMessage({ id: "notification.title" }),
+ message: intl.formatMessage({ id: "error.import.patient" }),
+ kind: NotificationKinds.error,
+ });
+ }
+ };
+
const handleSubmit = (values) => {
setLoading(true);
values.dateOfBirth = dob;
- const searchEndPoint =
+ let searchEndPoint =
"/rest/patient-search-results?" +
"lastName=" +
values.lastName +
@@ -74,9 +159,15 @@ function SearchPatientForm(props) {
values.gender +
"&suppressExternalSearch=" +
values.suppressExternalSearch;
+
+ if (values.crSearch === true) {
+ searchEndPoint += "&crSearch=true";
+ }
+
getFromOpenElisServer(searchEndPoint, fetchPatientResults);
setUrl(searchEndPoint);
};
+
const loadNextResultsPage = () => {
setLoading(true);
getFromOpenElisServer(url + "&page=" + nextPage, fetchPatientResults);
@@ -87,6 +178,10 @@ function SearchPatientForm(props) {
getFromOpenElisServer(url + "&page=" + previousPage, fetchPatientResults);
};
+ const toggle = () => {
+ setIsToggled((prev) => !prev);
+ };
+
const fetchPatientResults = (res) => {
let patientsResults = res.patientSearchResults;
if (patientsResults.length > 0) {
@@ -351,6 +446,21 @@ function SearchPatientForm(props) {
/>
+ {configurationProperties.ENABLE_CLIENT_REGISTRY === "true" && (
+
+ {
+ toggle();
+ setFieldValue("crSearch", !isToggled);
+ }}
+ />
+
+ )}
)}
@@ -396,7 +506,7 @@ function SearchPatientForm(props) {
-
+
{headers.map((header) => (
- <>
- {rows
- .slice((page - 1) * pageSize)
- .slice(0, pageSize)
- .map((row) => (
+ {rows
+ .slice((page - 1) * pageSize, page * pageSize)
+ .map((row) => {
+ const dataSourceName = row.cells.find(
+ (cell) => cell.info.header === "dataSourceName",
+ )?.value;
+
+ return (
- {" "}
-
+ {dataSourceName === "OpenElis" ? (
+
+ ) : (
+
+ )}
+
{row.cells.map((cell) => (
- {cell.value}
+
+ {cell.info.header === "dataSourceName" ? (
+ <>
+
+ {cell.value}
+
+
+ {dataSourceName === "Open Client Registry" ? (
+
+ ) : (
+
+ )}
+ >
+ ) : (
+ cell.value
+ )}
+
))}
- ))}
- >
+ );
+ })}
diff --git a/frontend/src/languages/en.json b/frontend/src/languages/en.json
index b018fe2acf..2adf53a837 100644
--- a/frontend/src/languages/en.json
+++ b/frontend/src/languages/en.json
@@ -541,6 +541,7 @@
"search.label.sample": "Select Sample Status",
"pathology.label.report": "Pathology Report",
"patient.natioanalid": "National ID",
+ "patient.dataSourceName": "Data Source Name",
"patient.label.additionalInfo": "Additional Information",
"sample.entry.available.tests": "Available Tests",
"sample.entry.panels": "Panels",
@@ -828,6 +829,9 @@
"rulebuilder.label.add.externaltrigger": "Add External `triggered by` message",
"error.duplicate.calculationname": "Duplicate Calculation Name or Error while saving",
"success.save.patient": "Patient Saved Successfully",
+ "success.import.patient": "Patient Succesfully Imported",
+ "error.no.patient.data": "No Patient Data to Import",
+ "error.import.patient": "Error While Importing Patient into OpenELIS",
"error.save.patient": "Error While Saving Patient",
"patient.search.nopatient": "No patients found matching search terms",
"result.search.noresult": "No results found",
diff --git a/pom.xml b/pom.xml
index d7db495d4a..cc626cf0d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -664,6 +664,7 @@
tools/Liquibase-Outdated/**
dataexport/**
plugins/**
+ frontend/**