easycare.alc.service.report.HstDiagnosticReportBean.java Source code

Java tutorial

Introduction

Here is the source code for easycare.alc.service.report.HstDiagnosticReportBean.java

Source

package easycare.alc.service.report;

import com.google.common.collect.Lists;
import easycare.alc.model.HstData;
import easycare.alc.model.HstInterpretation;
import easycare.alc.model.HstPatient;
import easycare.alc.model.HstSignature;
import easycare.alc.service.signals.HstSignalImageGeneratorNonCached;
import easycare.common.ApplicationMessageSource;
import easycare.helper.TimeZoneHelper;
import easycare.service.report.ReportBean;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Locale;

@Slf4j
public class HstDiagnosticReportBean extends ReportBean {

    private static final String DEFAULT_DEVICE_TYPE_KEY = "diagnosticReport.default.device.type";
    public static final String REPORT_PDF_SIGNATURE_DETAILS_KEY = "esignature.pdf.signature.details";
    public static final String REPORT_PDF_SIGNATURE_SIGNED_AT_KEY = "esignature.pdf.signature.signedAt";
    public static final String HST_DIAGNOSTIC_REPORT_PATH = "/report/alc/hst-diagnostic-report";

    protected final DecimalFormat onePoint = new DecimalFormat("0.0");

    private boolean showDeviceType;
    private HstReportHeaderFormatter headerFormatter;
    private final HstInterpretation hstInterpretation;
    protected final HstDiagnosticReportDetails reportDetails;

    @Getter
    private final HstPatient patient;

    @Getter
    private final HstData hstData;

    @Getter
    private final HstSignature hstSignature;

    @Getter
    private final InputStream ahiGraph;

    @Getter
    protected InputStream positionGraph;

    @Getter
    protected InputStream eventAndSignalGraph;

    public HstDiagnosticReportBean(ApplicationMessageSource messageSource, TimeZoneHelper timeZoneHelper,
            LocalDate currentDate, InputStream resMedLogo, boolean showDeviceType, HstPatient patient,
            HstData hstData, HstDiagnosticReportDetails reportDetails, InputStream ahiGraph,
            HstInterpretation hstInterpretation, HstSignature hstSignature,
            final HstSignalImageGeneratorNonCached imgGenerator, Locale locale) {
        super(messageSource, currentDate, resMedLogo);
        this.timeZoneHelper = timeZoneHelper;
        this.showDeviceType = showDeviceType;
        this.patient = patient;
        this.hstData = hstData;
        this.reportDetails = reportDetails;
        this.ahiGraph = ahiGraph;
        this.hstInterpretation = hstInterpretation;
        this.hstSignature = hstSignature;

        this.positionGraph = null;
        this.eventAndSignalGraph = null;
        this.locale = locale;

        try {
            if (imgGenerator != null && imgGenerator.getPdfPositionPNG() != null) {
                this.positionGraph = new ByteArrayInputStream(imgGenerator.getPdfPositionPNG());
            }
            if (imgGenerator != null) {
                this.eventAndSignalGraph = new ByteArrayInputStream(imgGenerator.getPdfEventAndSignalPNG());
            }
        } catch (IOException e) {
            log.error("Jasper Report image rendering failed!");
        }
    }

    public String getPatientDetail() {
        return getHeaderFormatter().formatPatientDetail(patient, currentDate);
    }

    public String getLabAddress() {
        return getHeaderFormatter().formatAddress(patient);
    }

    public String getLabContactDetail() {
        return getHeaderFormatter().formatLabContactDetail(patient);
    }

    public LocalDate getRecordingDate() {
        return reportDetails.getRecordingStart().toLocalDate();
    }

    public LocalTime getRecordingStartTime() {
        return reportDetails.getRecordingStart().toLocalTime();
    }

    public LocalTime getRecordingEndTime() {
        return reportDetails.getRecordingStop().toLocalTime();
    }

    public String getRecordingDuration() {
        return reportDetails.getRecordingDuration();
    }

    public LocalTime getEvaluationStartTime() {
        return reportDetails.getEvaluationStart().toLocalTime();
    }

    public LocalTime getEvaluationEndTime() {
        return reportDetails.getEvaluationStop().toLocalTime();
    }

    public String getEvaluationDuration() {
        return reportDetails.getEvaluationDuration();
    }

    public LocalTime getOxygenSaturationEvaluationStartTime() {
        return reportDetails.getOxygenSaturationEvaluationStart().toLocalTime();
    }

    public LocalTime getOxygenSaturationEvaluationEndTime() {
        return reportDetails.getOxygenSaturationEvaluationStop().toLocalTime();
    }

    public String getOxygenSaturationEvaluationDuration() {
        return reportDetails.getOxygenSaturationEvaluationDuration();
    }

    public String getDeviceName() {
        return hstData.getProductName();
    }

    public String getDeviceType() {
        return messageSource.getMessage(DEFAULT_DEVICE_TYPE_KEY);
    }

    public String getApneaHypopneaIndex() {
        return formatDoubleValue(reportDetails.getApneaHypopneaIndex());
    }

    public String getApneaIndex() {
        return formatDoubleValue(reportDetails.getApneaIndex());
    }

    public String getHypopneaIndex() {
        return formatDoubleValue(reportDetails.getHypopneaIndex());
    }

    public Integer getApneaTotal() {
        return reportDetails.getApneaTotal();
    }

    public Integer getHypopneaTotal() {
        return reportDetails.getHypopneaTotal();
    }

    public String getObstructiveApneaIndex() {
        return formatDoubleValue(reportDetails.getObstructiveApneaIndex());
    }

    public String getCentralApneaIndex() {
        return formatDoubleValue(reportDetails.getCentralApneaIndex());
    }

    public String getMixedApneaIndex() {
        return formatDoubleValue(reportDetails.getMixedApneaIndex());
    }

    public String getUnclassifiedApneaIndex() {
        return formatDoubleValue(reportDetails.getUnclassifiedApneaIndex());
    }

    public String getOxygenDesaturationIndex() {
        return formatDoubleValue(reportDetails.getOxygenDesaturationIndex());
    }

    public Integer getOxygenDesaturationTotal() {
        return reportDetails.getOxygenDesaturationTotal();
    }

    public Integer getBaselineOxygenSaturation() {
        return reportDetails.getBaselineOxygenSaturation();
    }

    public Integer getAverageOxygenSaturation() {
        return reportDetails.getAverageOxygenSaturation();
    }

    public Integer getLowestOxygenSaturation() {
        return reportDetails.getLowestOxygenSaturation();
    }

    public Integer getLteq80OxygenSaturationTime() {
        return reportDetails.getLteq80OxygenSaturationTime();
    }

    public Integer getLteq85OxygenSaturationTime() {
        return reportDetails.getLteq85OxygenSaturationTime();
    }

    public Integer getLteq90OxygenSaturationTime() {
        return reportDetails.getLteq90OxygenSaturationTime();
    }

    public Integer getLteq88OxygenSaturationTime() {
        return reportDetails.getLteq88OxygenSaturationTime();
    }

    public String getLteq88OxygenSaturationDuration() {
        return reportDetails.getLteq88OxygenSaturationDurationString();
    }

    public Integer getBreathsTotal() {
        return reportDetails.getBreathsTotal();
    }

    public String getBreathsAverage() {
        return formatDoubleValue(reportDetails.getBreathsAverage());
    }

    public Integer getSnoreEvents() {
        return reportDetails.getSnoreEvents();
    }

    public Integer getCheynesStokesPercentage() {
        return reportDetails.getCheynesStokesPercentage();
    }

    public String getCheynesStokesDuration() {
        return reportDetails.getCheynesStokesDuration();
    }

    public Integer getPulseAvgBpm() {
        return reportDetails.getPulseAvgBpm();
    }

    public Integer getPulseMaxBpm() {
        return reportDetails.getPulseMaxBpm();
    }

    public Integer getPulseMinBpm() {
        return reportDetails.getPulseMinBpm();
    }

    public String getInterpretation() {
        if (hstInterpretation == null) {
            return "";
        }
        String interpretation = hstInterpretation.getInterpretation();
        return interpretation == null ? "" : interpretation;
    }

    private HstReportHeaderFormatter getHeaderFormatter() {
        if (headerFormatter == null) {
            headerFormatter = new HstReportHeaderFormatter(messageSource);
        }
        return headerFormatter;
    }

    public String getSignatureDetails() {
        if (hstSignature == null) {
            return "";
        }

        ArrayList<String> names = Lists.newArrayList(hstSignature.getFirstName(), hstSignature.getLastName());

        if (hstSignature.getTitle() != null) {
            names.add(0, messageSource.getTitleMessage(hstSignature.getTitle()));
        }

        String fullName = StringUtils.join(names, " ");

        ArrayList<String> args = Lists.newArrayList(fullName, hstSignature.getLicenseNumber());
        return messageSource.getMessage(REPORT_PDF_SIGNATURE_DETAILS_KEY, args.toArray());
    }

    public String getSignedAt() {
        if (hstSignature == null) {
            return "";
        }

        String dateTimeFormat = String.format("%s %s", messageSource.getMessage(JAVA_DATE_FORMAT_KEY),
                messageSource.getMessage(JAVA_CLOCK_TIME_FORMAT_KEY));

        DateTime dateTimeAndZone = timeZoneHelper
                .convertHardwareLocalDateTimeToSystemTZDateTime(hstSignature.getSignedAt());

        DateTimeFormatter formatter = DateTimeFormat.forPattern(dateTimeFormat).withLocale(locale);
        String signedAt = formatter.print(dateTimeAndZone.toLocalDateTime()).toLowerCase();
        String timeZone = dateTimeAndZone.getZone().getShortName(0);

        return messageSource.getMessage(REPORT_PDF_SIGNATURE_SIGNED_AT_KEY, new String[] { signedAt, timeZone });
    }

    public Boolean getShowDeviceType() {
        return showDeviceType;
    }

    @Override
    public String getReportPath() {
        return HST_DIAGNOSTIC_REPORT_PATH;
    }

    public Boolean getActigraphyAvailable() {
        return reportDetails.getSupinePercentage() != null;
    }

    public String getSupineDurationAsString() {
        if (getActigraphyAvailable()) {
            return reportDetails.getSupineDuration();
        }
        return "";
    }

    public String getSupinePercentage() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getSupinePercentage());
        }
        return "";
    }

    public String getSupineApneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getSupineApneaIndex());
        }
        return "";
    }

    public String getSupineHypopneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getSupineHypopneaIndex());
        }
        return "";
    }

    public String getSupineApneaHypopneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getSupineApneaHypopneaIndex());
        }
        return "";
    }

    public String getNonSupineDurationAsString() {
        if (getActigraphyAvailable()) {
            return reportDetails.getNonSupineDuration();
        }
        return "";
    }

    public String getNonSupinePercentage() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getNonSupinePercentage());
        }
        return "";
    }

    public String getNonSupineApneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getNonSupineApneaIndex());
        }
        return "";
    }

    public String getNonSupineHypopneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getNonSupineHypopneaIndex());
        }
        return "";
    }

    public String getNonSupineApneaHypopneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getNonSupineApneaHypopneaIndex());
        }
        return "";
    }

    public String getUprightDurationAsString() {
        if (getActigraphyAvailable()) {
            return reportDetails.getUprightDuration();
        }
        return "";
    }

    public String getUprightPercentage() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getUprightPercentage());
        }
        return "";
    }

    public String getUprightApneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getUprightApneaIndex());
        }
        return "";
    }

    public String getUprightHypopneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getUprightHypopneaIndex());
        }
        return "";
    }

    public String getUprightApneaHypopneaIndex() {
        if (getActigraphyAvailable()) {
            return formatDoubleValue(reportDetails.getUprightApneaHypopneaIndex());
        }
        return "";
    }

    protected String formatDoubleValue(Double obj) {
        return obj == null ? "" : onePoint.format(obj);
    }
}