Java tutorial
package easycare.alc.service.report; import com.google.common.collect.Lists; import easycare.alc.model.HstPatient; import easycare.alc.model.HstPrescription; import easycare.alc.web.patient.PrescriptionSettings.HstMaskTypeEnum; import easycare.alc.web.patient.PrescriptionSettings.HstTherapySettingEnum; import easycare.common.ApplicationMessageSource; import easycare.helper.TimeZoneHelper; import easycare.service.report.ReportBean; import lombok.Getter; import org.apache.commons.lang.StringUtils; import org.joda.time.DateTime; import org.joda.time.LocalDate; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; import java.io.InputStream; import java.util.ArrayList; import java.util.Locale; public class HstPrescriptionReportBean extends ReportBean { public static final String REPORT_PDF_SIGNATURE_DETAILS_KEY = "prescriptionReport.pdf.signature.details"; public static final String REPORT_PDF_SIGNATURE_SIGNED_AT_KEY = "prescriptionReport.pdf.signature.signedAt"; public static final String HST_PRESCRIPTION_REPORT_PATH = "/report/alc/hst-prescription-report"; @Getter protected String leftColumnTitle = ""; @Getter protected String rightColumnTitle = ""; @Getter protected String patientAHIValue = ""; @Getter protected String maskReplacementLabel = ""; @Getter protected String maskReplacement = ""; @Getter protected String interfaceReplacementLabel = ""; @Getter protected String interfaceReplacement = ""; @Getter protected String humidifierReplacementLabel = ""; @Getter protected String humidifierReplacement = ""; @Getter protected String airTubingReplacementLabel = ""; @Getter protected String airTubingReplacement = ""; @Getter protected String filterReplacementLabel = ""; @Getter protected String filterReplacement = ""; @Getter private Boolean isResmedPrescription; @Getter private String reportTitle = ""; @Getter private String maskType; @Getter private String humidifier; @Getter private String airTubingType; @Getter private String filterType; @Getter private String additionalNotes; @Getter private String patientDetail; @Getter private String labAddress; @Getter private String labContactDetail; @Getter private final HstPatient patient; @Getter private final HstPrescription hstPrescription; public HstPrescriptionReportBean(ApplicationMessageSource messageSource, TimeZoneHelper timeZoneHelper, LocalDate currentDate, InputStream resMedLogo, HstPatient patient, HstPrescription hstPrescription, boolean isResmedPrescription, Locale locale) { super(messageSource, currentDate, resMedLogo); this.timeZoneHelper = timeZoneHelper; this.patient = patient; this.hstPrescription = hstPrescription; this.locale = locale; this.isResmedPrescription = isResmedPrescription; reportTitle = messageSource.getMessage(getKeyWithSuffix("prescriptionReport.pdf.title")); maskType = messageSource.getMessage(getMaskTypeKey()); humidifier = messageSource .getMessage("prescriptionReport.pdf.humidifier." + hstPrescription.getHumidifierRequiredField()); airTubingType = messageSource .getMessage("prescriptionReport.pdf.airTubing." + hstPrescription.getTubingSelectField()); filterType = messageSource .getMessage("prescriptionReport.pdf.filters." + hstPrescription.getFilterSelectField()); additionalNotes = hstPrescription.getAdditionalNotesField(); HstReportHeaderFormatter formatter = new HstReportHeaderFormatter(messageSource); patientDetail = formatter.formatPatientDetail(patient, currentDate); labAddress = formatter.formatAddress(patient); labContactDetail = formatter.formatLabContactDetail(patient); } public String getDeviceName() { if (HstTherapySettingEnum.Other == HstTherapySettingEnum.valueOf(hstPrescription.getTherapyDeviceField())) { return messageSource.getMessage(getDeviceNameKey(true), new String[] { hstPrescription.getTherapyDeviceOther() }); } return messageSource.getMessage(getDeviceNameKey(false)); } public String getDevicePressure() { HstTherapySettingEnum therapySettingEnum = HstTherapySettingEnum .valueOf(hstPrescription.getTherapyDeviceField()); String devicePressureLabel = ""; if (HstTherapySettingEnum.Other != therapySettingEnum) { String unit = therapySettingEnum.getTherapySettings().get(0).getUnit(); devicePressureLabel = messageSource.getMessage("prescriptionReport.pdf.therapy.device." + hstPrescription.getTherapyDeviceField() + ".pressure.label", new String[] { unit }); } return devicePressureLabel; } public String getDeviceValue() { HstTherapySettingEnum therapySettingEnum = HstTherapySettingEnum .valueOf(hstPrescription.getTherapyDeviceField()); String devicePressure = ""; switch (therapySettingEnum) { case APAP: devicePressure = String.format("%.1f/%.1f", hstPrescription.getMinimumPressure(), hstPrescription.getMaximumPressure()); break; case CPAP: devicePressure = String.format("%.1f", hstPrescription.getSetPressure()); break; case Other: devicePressure = ""; break; default: } return devicePressure; } public String getSignedAt() { String dateTimeFormat = String.format("%s %s", messageSource.getMessage(JAVA_DATE_FORMAT_KEY), messageSource.getMessage(JAVA_CLOCK_TIME_FORMAT_KEY)); DateTime dateTimeAndZone = timeZoneHelper .convertHardwareLocalDateTimeToSystemTZDateTime(hstPrescription.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 String getSignatureDetails() { ArrayList<String> names = Lists.newArrayList(hstPrescription.getPhysicianFirstName(), hstPrescription.getPhysicianLastName()); if (hstPrescription.getPhysicianTitle() != null) { names.add(0, messageSource.getTitleMessage(hstPrescription.getPhysicianTitle())); } String fullName = StringUtils.join(names, " "); ArrayList<String> args = Lists.newArrayList(fullName, hstPrescription.getPhysicianLicenseNumber()); return messageSource.getMessage(REPORT_PDF_SIGNATURE_DETAILS_KEY, args.toArray()); } @Override public String getReportPath() { return HST_PRESCRIPTION_REPORT_PATH; } private String getMaskTypeKey() { return getKeyWithSuffix(HstMaskTypeEnum.valueOf(hstPrescription.getMaskSelectField().toUpperCase()) .getMaskType().getLabel()); } private String getDeviceNameKey(boolean isForOther) { return getKeyWithSuffix("prescriptionReport.pdf.therapy.device." + (isForOther ? "Other" : hstPrescription.getTherapyDeviceField())); } private String getKeyWithSuffix(String genericKey) { if (isResmedPrescription) { return genericKey + HstMaskTypeEnum.RESMED_SUFFIX; } return genericKey; } }