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

Patient Status CSV Report #1265

Closed
wants to merge 13 commits into from
Closed
8 changes: 4 additions & 4 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^3.3.2",
mozzy11 marked this conversation as resolved.
Show resolved Hide resolved
"prettier": "^3.3.3",
"sass": "^1.57.1"
}
}
53 changes: 53 additions & 0 deletions frontend/src/components/reports/common/PatientStatusReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ConfigurationContext } from "../../layout/Layout";
import { Formik, Field } from "formik";
import PatientStatusReportFormValues from "../../formModel/innitialValues/PatientStatusReportFormValues";
import SearchPatientForm from "../../patient/SearchPatientForm";
// import config from "../../../config.json";

import { encodeDate } from "../../utils/Utils";

Expand Down Expand Up @@ -61,6 +62,46 @@ function PatientStatusReport(props) {
});
};

// function to handle csv report start
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may not be needed . we only need to change the report type param

Copy link
Collaborator

@mozzy11 mozzy11 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you just need add a link in the report menu in this component
ie

{
     title: <FormattedMessage id="sidenav.title.statusreport.csv" />,
     icon: IbmWatsonDiscovery,
     SideNavMenuItem: [
       {
         link: "/RoutineReport?type=patient&report=CSVPatientStatusReport",
         label: <FormattedMessage id="sidenav.label.statusreport.csv" />,
       },
     ],
   },

then add report component here

ie

 {type === "patient" && report === "CSVPatientStatusReport" && (
        <PatientStatusReport
          report={"CSVPatientStatusReport"}
          id={"openreports.patientTestStatus.csv"}
        />
      )}


const handleCSVReport = () => {
const url = `${config.serverBaseUrl}/patientStatus`;

// URL parameters
const params = new URLSearchParams({
lowerDateRange: reportFormValues.startDate,
upperDateRange: reportFormValues.endDate,
patientId: reportFormValues.selectedPatientId,
referringSiteId: reportFormValues.referringSiteId,
referringSiteDepartmentId: reportFormValues.referringSiteDepartmentId,
onlyResults: result,
dateType: items,
}).toString();

fetch(`${url}?${params}`, { method: "GET" })
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok");
}
return response.blob();
})
.then((blob) => {
const csvUrl = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.style.display = "none";
a.href = csvUrl;
a.download = "PatientStatusReport.csv";
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(csvUrl);
})
.catch((error) => {
console.error("Error:", error);
});
};

// function to handle csv ends

const handleReportPrint = () => {
let barcodesPdf =
config.serverBaseUrl +
Expand Down Expand Up @@ -440,6 +481,18 @@ function PatientStatusReport(props) {
</Button>
</Column>
</Grid>
{/* CSV button */}
<Grid>
<Column lg={16} md={8} sm={4}>
<br />
<br />
</Column>
<Column lg={16} md={8} sm={4}>
Copy link
Collaborator

@mozzy11 mozzy11 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also get rid of this button. the existing button should be enough

<Button type="button" onClick={handleCSVReport}>
<FormattedMessage id="label.button.generateCSVVersion" />
</Button>
</Column>
</Grid>
</Form>
)}
</Formik>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"label.button.confirmAction": "Confirm Action",
"label.button.confirmTitle": "Are You Sure ?",
"label.button.generatePrintableVersion": "Generate Printable Version",
"label.button.generateCSVVersion": "Generate CSV Version",
"label.button.viewReport": "View Report",
"label.routine.Reports": "Routine Reports",
"label.audittrail.Reports": "Audit Trail Reports",
Expand Down Expand Up @@ -491,6 +492,7 @@
"dashboard.rejected.orders.subtitle": "Rejected By Lab Today",
"dashboard.unprints.results.label": "UnPrinted Results",
"dashboard.unprints.results.subtitle.label": "UnPrinted Results Today",
"landingpage.welcome": "Welcome",
"label.electronic.orders": "Electronic Orders",
"patient.dob": "Date of Birth",
"patient.male": "Male",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@
"dashboard.rejected.orders.subtitle": "Rejeté par le laboratoire aujourd'hui",
"dashboard.unprints.results.label": "Résultats non imprimés",
"dashboard.unprints.results.subtitle.label": "Résultats non imprimés aujourd'hui",
"landingpage.welcome": "Bienvenue!",
"label.electronic.orders": "Commandes électroniques",
"patient.dob": "Date de naissance",
"patient.male": "Mâle",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ public ModelAndView showRejectionForm(HttpServletRequest request, @Validated Rej
return findForward(FWD_SUCCESS, form);
}

@RequestMapping(value = "/patientStatus", method = RequestMethod.GET)
Copy link
Collaborator

@mozzy11 mozzy11 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you dont need a new endpoint for handling the report.
we already have this endpoint used by every report

public ModelAndView showPatientStatusForm(HttpServletRequest request, @Validated RejectionForm form,
BindingResult result) throws LIMSInvalidConfigurationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {
if (result.hasErrors()) {
saveErrors(result);
form = new RejectionForm();
return findForward(FWD_FAIL, form);
}
form = new RejectionForm();
setupForm(form);
addFlashMsgsToRequest(request);
request.getSession().setAttribute(SAVE_DISABLED, TRUE);

return findForward(FWD_SUCCESS, form);
}

private void setupForm(RejectionForm form) throws LIMSInvalidConfigurationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.openelisglobal.reports.action.implementation;

import java.sql.SQLException;
import org.jfree.util.Log;
import org.openelisglobal.internationalization.MessageUtil;
import org.openelisglobal.reports.action.implementation.reportBeans.CSVSampleRejectionColumnBuilder;
import org.openelisglobal.reports.form.ReportForm;

public class CSVPatientStatusReport extends CSVSampleExportReport implements IReportParameterSetter, IReportCreator {

@Override
public void setRequestParameters(ReportForm form) {
try {
form.setReportName(getReportNameForParameterPage());
form.setUseLowerDateRange(Boolean.TRUE);
form.setUseUpperDateRange(Boolean.TRUE);
} catch (RuntimeException e) {
Log.error("Error in ExportProjectByDate.setRequestParemeters: ", e);
}
}

protected String getReportNameForParameterPage() {
return MessageUtil.getMessage("openreports.mgt.rejection");
}

@Override
protected String reportFileName() {
return "SampleRejection";
}

@Override
protected void createReportParameters() {
super.createReportParameters();
}

@Override
public void initializeReport(ReportForm form) {
super.initializeReport();
errorFound = false;

lowDateStr = form.getLowerDateRange();
highDateStr = form.getUpperDateRange();
dateRange = new DateRange(lowDateStr, highDateStr);

createReportParameters();
errorFound = !validateSubmitParameters();
if (errorFound) {
return;
}

createReportItems();
}

/** creating the list for generation to the report */
private void createReportItems() {
try {
csvColumnBuilder = new CSVSampleRejectionColumnBuilder(dateRange);
csvColumnBuilder.buildDataSource();
} catch (SQLException e) {
Log.error("Error in " + this.getClass().getSimpleName() + ".createReportItems: ", e);
add1LineErrorMessage("report.error.message.general.error");
}
}

private boolean validateSubmitParameters() {
return dateRange.validateHighLowDate("report.error.message.date.received.missing");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public static IReportParameterSetter getParameterSetter(String report) {
return new CovidResultsReport();
} else if (report.equals("statisticsReport")) {
return new StatisticsReport();
} else if (report.equals("patientReport")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should use a consistent report param here ie CSVPatientStatusReport

return new CSVPatientStatusReport();
} else if (report.equals("sampleRejectionReport")) {
return new CSVSampleRejectionReport();
}
Expand Down Expand Up @@ -283,6 +285,8 @@ public static IReportCreator getReportCreator(String report) {
return new StatisticsReport();
} else if (report.equals("sampleRejectionReport")) {
return new CSVSampleRejectionReport();
} else if (report.equals("CSVPatientStatusReport")) {
return new CSVPatientStatusReport();
} else if (report.equals("PatientPathologyReport")) {
return new PatientPathologyReport();
} else if (report.equals("PatientCytologyReport")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
* @since Mar 18, 2011
*/
public abstract class CSVColumnBuilder {
//
// public abstract String[] getHeaders();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can remove unused comented code

//
// public abstract List<String[]> getRows();

// these are used so we are not passing around strings in the methods that are
// appended to sql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.openelisglobal.reports.action.implementation.reportBeans;

import static org.openelisglobal.reports.action.implementation.reportBeans.CSVColumnBuilder.Strategy.DATE_TIME;
import static org.openelisglobal.reports.action.implementation.reportBeans.CSVColumnBuilder.Strategy.NONE;

import java.sql.Date;
import org.openelisglobal.common.services.StatusService;
import org.openelisglobal.reports.action.implementation.Report.DateRange;

public class CSVPatientStatusColumnBuilder extends CSVColumnBuilder {
protected DateRange dateRange;

public CSVPatientStatusColumnBuilder(DateRange dateRange) {
super(StatusService.AnalysisStatus.SampleRejected);
this.dateRange = dateRange;
defineAllReportColumns();
}

@Override
public void makeSQL() {
query = new StringBuilder();
Date lowDate = dateRange.getLowDate();
Date highDate = dateRange.getHighDate();
query.append("SELECT s.accession_number AS lab_no ,s.received_date AS request_date , o.name as"
+ " site_name, ts.description AS sample_type , t.name AS test_name , d.dict_entry AS"
+ " rejection_reason ,si.lastupdated AS rejection_date FROM sample s INNER JOIN"
+ " sample_item si ON s.id = si.samp_id INNER JOIN type_of_sample ts ON si.typeosamp_id"
+ " = ts.id INNER JOIN analysis a ON si.id = a.sampitem_id INNER JOIN test t ON"
+ " a.test_id = t.id LEFT JOIN dictionary d ON si.reject_reason_id = d.id INNER JOIN"
+ " sample_requester sr ON s.id = sr.sample_id INNER JOIN organization o ON"
+ " sr.requester_id = o.id WHERE si.rejected = true AND sr.requester_type_id = (SELECT"
+ " rt.id FROM requester_type rt WHERE rt.requester_type = 'organization') AND"
+ " s.entered_date BETWEEN '" + lowDate + "' AND '" + highDate + "' ORDER BY s.accession_number");
}

protected void defineAllReportColumns() {
add("lab_no", "Lab No ", NONE);
add("request_date", "Request Date", DATE_TIME);
add("site_name", "Site Name", NONE);
add("sample_type", "Sample", NONE);
add("test_name", "Test", NONE);
add("rejection_reason", "Rejection Reason", NONE);
add("rejection_date", "Rejection Date", DATE_TIME);
}
}
Loading