diff --git a/src/main/java/com/divudi/core/data/dataStructure/SearchKeyword.java b/src/main/java/com/divudi/core/data/dataStructure/SearchKeyword.java index 91789bb3af5..0db56c9a3db 100644 --- a/src/main/java/com/divudi/core/data/dataStructure/SearchKeyword.java +++ b/src/main/java/com/divudi/core/data/dataStructure/SearchKeyword.java @@ -7,6 +7,7 @@ import com.divudi.core.data.BillType; import com.divudi.core.data.PaymentMethod; +import com.divudi.core.data.lab.PatientInvestigationStatus; import com.divudi.core.entity.Department; import com.divudi.core.entity.Institution; import com.divudi.core.entity.Item; @@ -59,6 +60,7 @@ public class SearchKeyword { private Department itemDepartment; private Item item; private Investigation investigation; + private PatientInvestigationStatus patientInvestigationStatus; private List billTypes; private Long id; // Removed legacy Institution distributor; use String fromInstitution in JSF filters @@ -450,6 +452,14 @@ public void setInvestigation(Investigation investigation) { this.investigation = investigation; } + public PatientInvestigationStatus getPatientInvestigationStatus() { + return patientInvestigationStatus; + } + + public void setPatientInvestigationStatus(PatientInvestigationStatus patientInvestigationStatus) { + this.patientInvestigationStatus = patientInvestigationStatus; + } + public Long getId() { return id; } diff --git a/src/main/java/com/divudi/service/PatientInvestigationService.java b/src/main/java/com/divudi/service/PatientInvestigationService.java index 8b040c07f68..450e00ce4cd 100644 --- a/src/main/java/com/divudi/service/PatientInvestigationService.java +++ b/src/main/java/com/divudi/service/PatientInvestigationService.java @@ -78,6 +78,11 @@ public List fetchPatientInvestigations( jpql += " and pi.encounter=:en"; params.put("en", searchKeyword.getPatientEncounter()); } + + if (searchKeyword.getPatientInvestigationStatus() != null) { + jpql += " and pi.status=:pis "; + params.put("pis", searchKeyword.getPatientInvestigationStatus()); + } } jpql += " order by pi.id desc"; diff --git a/src/main/java/com/divudi/ws/common/ApplicationConfig.java b/src/main/java/com/divudi/ws/common/ApplicationConfig.java index d5451d3ccca..346b7ab6364 100644 --- a/src/main/java/com/divudi/ws/common/ApplicationConfig.java +++ b/src/main/java/com/divudi/ws/common/ApplicationConfig.java @@ -49,6 +49,7 @@ private void addRestResourceClasses(Set> resources) { resources.add(com.divudi.ws.lims.Lims.class); resources.add(com.divudi.ws.lims.LimsMiddlewareController.class); resources.add(com.divudi.ws.lims.MiddlewareController.class); + resources.add(com.divudi.ws.report.ReportApi.class); } } \ No newline at end of file diff --git a/src/main/java/com/divudi/ws/report/ReportApi.java b/src/main/java/com/divudi/ws/report/ReportApi.java new file mode 100644 index 00000000000..cf93f1d7eab --- /dev/null +++ b/src/main/java/com/divudi/ws/report/ReportApi.java @@ -0,0 +1,181 @@ +package com.divudi.ws.report; + +import com.divudi.bean.common.ApiKeyController; +import com.divudi.bean.lab.PatientInvestigationController; +import com.divudi.core.data.dataStructure.SearchKeyword; +import com.divudi.core.data.lab.PatientInvestigationStatus; +import com.divudi.core.entity.ApiKey; +import com.divudi.core.entity.lab.PatientInvestigation; +import com.divudi.service.PatientInvestigationService; +import org.json.JSONObject; + +import javax.ejb.EJB; +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; +import javax.validation.constraints.NotNull; +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.util.Date; +import java.util.List; +import java.util.logging.Logger; + +/** + * REST Web Service + * + * @author Imesh Ranawella + */ +@Path("report") +@RequestScoped +public class ReportApi { + private static final Logger LOGGER = Logger.getLogger(ReportApi.class.getName()); + + @EJB + private PatientInvestigationService patientInvestigationService; + @Inject + private PatientInvestigationController patientInvestigationController; + @Inject + ApiKeyController apiKeyController; + + private SearchKeyword searchKeyword; + + public ReportApi() { + } + + /** + * Get the reports by mobile number + * Endpoint: /report/by-mobile/{mobile} + */ + @GET + @Path("by-mobile/{mobile}") + @Produces(MediaType.APPLICATION_JSON) + public Response getReportsByMobile( + @Context HttpServletRequest requestContext, + @PathParam("mobile") String mobile, + @QueryParam("fromDate") @NotNull String fromDate, + @QueryParam("toDate") @NotNull String toDate) { + final String key = requestContext.getHeader("Token"); + + if (!isValidKey(key)) { + JSONObject responseError = errorMessageNotValidKey(); + String json = responseError.toString(); + return Response.status(Response.Status.UNAUTHORIZED).entity(json).build(); + } + + try { + validateDates(fromDate, toDate); + validateMobileNumber(mobile); + } catch (WebApplicationException ex) { + LOGGER.warning("Validation error: " + ex.getMessage()); + return Response.status(ex.getResponse().getStatus()) + .entity(ex.getMessage()) + .build(); + } + + getSearchKeyword().setPatientPhone(mobile); + getSearchKeyword().setPatientInvestigationStatus(PatientInvestigationStatus.REPORT_APPROVED); + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime fromLocal = LocalDateTime.parse(fromDate.trim(), formatter); + LocalDateTime toLocal = LocalDateTime.parse(toDate.trim(), formatter); + + List investigations = patientInvestigationService.fetchPatientInvestigations( + Date.from(fromLocal.atZone(ZoneId.systemDefault()).toInstant()), + Date.from(toLocal.atZone(ZoneId.systemDefault()).toInstant()), + getSearchKeyword() + ); + + ViewReportsResponseDTO responseDTO = new ViewReportsResponseDTO( + mobile, + fromDate, + toDate, + investigations + ); + + return Response.status(Response.Status.OK) + .entity(responseDTO) + .build(); + } + + private void validateDates(final String fromDate, final String toDate) { + if (fromDate == null || fromDate.isEmpty() || toDate == null || toDate.isEmpty()) { + throw new WebApplicationException("From date and To date must be provided", Response.Status.BAD_REQUEST); + } + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + try { + LocalDateTime fromLocal = LocalDateTime.parse(fromDate.trim(), formatter); + LocalDateTime toLocal = LocalDateTime.parse(toDate.trim(), formatter); + Date from = Date.from(fromLocal.atZone(ZoneId.systemDefault()).toInstant()); + Date to = Date.from(toLocal.atZone(ZoneId.systemDefault()).toInstant()); + + if (from.after(to)) { + throw new WebApplicationException("From date must be before To date", Response.Status.BAD_REQUEST); + } + + LocalDateTime oneMonthAfterFrom = fromLocal.plusMonths(1); + if (toLocal.isAfter(oneMonthAfterFrom)) { + throw new WebApplicationException("Date range cannot exceed 1 month", Response.Status.BAD_REQUEST); + } + } catch (DateTimeParseException ex) { + LOGGER.warning("Invalid date format: " + ex.getMessage()); + + throw new WebApplicationException("Invalid date format. Please use ISO format (yyyy-MM-dd HH:mm:ss).", Response.Status.BAD_REQUEST); + } + } + + private void validateMobileNumber(final String mobile) { + if (mobile == null || mobile.isEmpty()) { + throw new WebApplicationException("Mobile number must be provided", Response.Status.BAD_REQUEST); + } + } + + private boolean isValidKey(String key) { + if (key == null || key.trim().isEmpty()) { + return false; + } + ApiKey k = apiKeyController.findApiKey(key); + if (k == null) { + return false; + } + if (k.getWebUser() == null) { + return false; + } + if (k.getWebUser().isRetired()) { + return false; + } + if (!k.getWebUser().isActivated()) { + return false; + } + if (k.getDateOfExpiary().before(new Date())) { + return false; + } + return true; + } + + private JSONObject errorMessageNotValidKey() { + JSONObject jSONObjectOut = new JSONObject(); + jSONObjectOut.put("code", 401); + jSONObjectOut.put("type", "error"); + String e = "Not a valid key."; + jSONObjectOut.put("message", e); + return jSONObjectOut; + } + + public SearchKeyword getSearchKeyword() { + if (searchKeyword == null) { + searchKeyword = new SearchKeyword(); + } + return searchKeyword; + } + + public void setSearchKeyword(SearchKeyword searchKeyword) { + this.searchKeyword = searchKeyword; + } +} diff --git a/src/main/java/com/divudi/ws/report/ViewInvestigationResponseDTO.java b/src/main/java/com/divudi/ws/report/ViewInvestigationResponseDTO.java new file mode 100644 index 00000000000..df51874f0df --- /dev/null +++ b/src/main/java/com/divudi/ws/report/ViewInvestigationResponseDTO.java @@ -0,0 +1,87 @@ +package com.divudi.ws.report; + +import com.divudi.core.entity.lab.Investigation; + +public class ViewInvestigationResponseDTO { + private String investigationName; + private String investigationFullName; + private String sampleName; + private String reportType; + private String category; + private String reportFormat; + + public ViewInvestigationResponseDTO(final Investigation investigation) { + if (investigation == null) { + this.investigationName = null; + this.investigationFullName = null; + this.sampleName = null; + this.reportType = null; + this.category = null; + this.reportFormat = null; + return; + } + + this.investigationName = investigation.getName(); + this.investigationFullName = investigation.getFullName(); + this.sampleName = investigation.getSample() == null + ? null + : investigation.getSample().getName(); + this.reportType = investigation.getReportType() == null + ? null + : investigation.getReportType().name(); + this.category = investigation.getCategory() == null + ? null + : investigation.getCategory().getName(); + this.reportFormat = investigation.getReportFormat() == null + ? null + : investigation.getReportFormat().getName(); + } + + public String getInvestigationName() { + return investigationName; + } + + public void setInvestigationName(String investigationName) { + this.investigationName = investigationName; + } + + public String getSampleName() { + return sampleName; + } + + public void setSampleName(String sampleName) { + this.sampleName = sampleName; + } + + public String getReportType() { + return reportType; + } + + public void setReportType(String reportType) { + this.reportType = reportType; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getReportFormat() { + return reportFormat; + } + + public void setReportFormat(String reportFormat) { + this.reportFormat = reportFormat; + } + + public String getInvestigationFullName() { + return investigationFullName; + } + + public void setInvestigationFullName(String investigationFullName) { + this.investigationFullName = investigationFullName; + } +} diff --git a/src/main/java/com/divudi/ws/report/ViewPatientInvestigationResponseDTO.java b/src/main/java/com/divudi/ws/report/ViewPatientInvestigationResponseDTO.java new file mode 100644 index 00000000000..08ba846916f --- /dev/null +++ b/src/main/java/com/divudi/ws/report/ViewPatientInvestigationResponseDTO.java @@ -0,0 +1,336 @@ +package com.divudi.ws.report; + +import com.divudi.core.entity.lab.PatientInvestigation; + +import java.util.Date; +import java.util.List; + +public class ViewPatientInvestigationResponseDTO { + private Long id; + private Date createdAt; + + private Date sampleAcceptedAt; + private Date sampleGeneratedAt; + + private Date sampledAt; + private Boolean sampleOutside; + private String sampleComments; + private String sampleDepartment; + private String sampleInstitution; + + private Date receivedAt; + private String receivedDepartment; + private String receivedInstitution; + private String receivedComments; + + private Date performedAt; + private String performedDepartment; + private String performedInstitution; + private String performedComments; + + private Date approvedAt; + private String approvedDepartment; + private String approvedInstitution; + private String approvedComments; + + private Boolean outsourced; + private String outsourcedInstitution; + private String outsourcedComments; + private String outsourcedDepartment; + + private ViewInvestigationResponseDTO investigation; + + private List reports; + + public static ViewPatientInvestigationResponseDTO fromPatientInvestigation( + final PatientInvestigation patientInvestigation) { + + ViewPatientInvestigationResponseDTO dto = new ViewPatientInvestigationResponseDTO(); + + if (patientInvestigation == null) { + return dto; + } + + dto.id = patientInvestigation.getId(); + dto.createdAt = patientInvestigation.getCreatedAt(); + + dto.sampleAcceptedAt = patientInvestigation.getSampleAcceptedAt(); + dto.sampleGeneratedAt = patientInvestigation.getSampleGeneratedAt(); + dto.sampledAt = patientInvestigation.getSampledAt(); + dto.sampleOutside = patientInvestigation.getSampleOutside(); + dto.sampleComments = patientInvestigation.getSampleComments(); + + dto.sampleDepartment = patientInvestigation.getSampleDepartment() != null + ? patientInvestigation.getSampleDepartment().getName() + : null; + dto.sampleInstitution = patientInvestigation.getSampleInstitution() != null + ? patientInvestigation.getSampleInstitution().getName() + : null; + + dto.receivedAt = patientInvestigation.getReceivedAt(); + dto.receivedDepartment = patientInvestigation.getReceiveDepartment() != null + ? patientInvestigation.getReceiveDepartment().getName() + : null; + dto.receivedInstitution = patientInvestigation.getReceiveInstitution() != null + ? patientInvestigation.getReceiveInstitution().getName() + : null; + dto.receivedComments = patientInvestigation.getReceiveComments(); + + dto.performedAt = patientInvestigation.getPerformedAt(); + dto.performedDepartment = patientInvestigation.getPerformDepartment() != null + ? patientInvestigation.getPerformDepartment().getName() + : null; + dto.performedInstitution = patientInvestigation.getPerformInstitution() != null + ? patientInvestigation.getPerformInstitution().getName() + : null; + dto.performedComments = patientInvestigation.getPerformComments(); + + dto.approvedAt = patientInvestigation.getApproveAt(); + dto.approvedDepartment = patientInvestigation.getApproveDepartment() != null + ? patientInvestigation.getApproveDepartment().getName() + : null; + dto.approvedInstitution = patientInvestigation.getApproveInstitution() != null + ? patientInvestigation.getApproveInstitution().getName() + : null; + dto.approvedComments = patientInvestigation.getApproveComments(); + + dto.outsourced = patientInvestigation.getOutsourced(); + dto.outsourcedInstitution = patientInvestigation.getOutsourcedInstitution() != null + ? patientInvestigation.getOutsourcedInstitution().getName() + : null; + dto.outsourcedComments = patientInvestigation.getOutsourcedComments(); + dto.outsourcedDepartment = patientInvestigation.getOutsourcedDepartment() != null + ? patientInvestigation.getOutsourcedDepartment().getName() + : null; + + dto.investigation = patientInvestigation.getInvestigation() != null + ? new ViewInvestigationResponseDTO(patientInvestigation.getInvestigation()) + : null; + + dto.reports = ViewReportResponseDTO.fromPatientReports(patientInvestigation.getPatientReports()); + + return dto; + } + + public static List fromPatientInvestigations(final List patientInvestigations) { + return patientInvestigations.stream() + .map(ViewPatientInvestigationResponseDTO::fromPatientInvestigation) + .collect(java.util.stream.Collectors.toList()); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getSampleAcceptedAt() { + return sampleAcceptedAt; + } + + public void setSampleAcceptedAt(Date sampleAcceptedAt) { + this.sampleAcceptedAt = sampleAcceptedAt; + } + + public Date getSampleGeneratedAt() { + return sampleGeneratedAt; + } + + public void setSampleGeneratedAt(Date sampleGeneratedAt) { + this.sampleGeneratedAt = sampleGeneratedAt; + } + + public Date getSampledAt() { + return sampledAt; + } + + public void setSampledAt(Date sampledAt) { + this.sampledAt = sampledAt; + } + + public Boolean getSampleOutside() { + return sampleOutside; + } + + public void setSampleOutside(Boolean sampleOutside) { + this.sampleOutside = sampleOutside; + } + + public String getSampleComments() { + return sampleComments; + } + + public void setSampleComments(String sampleComments) { + this.sampleComments = sampleComments; + } + + public String getSampleDepartment() { + return sampleDepartment; + } + + public void setSampleDepartment(String sampleDepartment) { + this.sampleDepartment = sampleDepartment; + } + + public String getSampleInstitution() { + return sampleInstitution; + } + + public void setSampleInstitution(String sampleInstitution) { + this.sampleInstitution = sampleInstitution; + } + + public Date getReceivedAt() { + return receivedAt; + } + + public void setReceivedAt(Date receivedAt) { + this.receivedAt = receivedAt; + } + + public String getReceivedDepartment() { + return receivedDepartment; + } + + public void setReceivedDepartment(String receivedDepartment) { + this.receivedDepartment = receivedDepartment; + } + + public String getReceivedInstitution() { + return receivedInstitution; + } + + public void setReceivedInstitution(String receivedInstitution) { + this.receivedInstitution = receivedInstitution; + } + + public String getReceivedComments() { + return receivedComments; + } + + public void setReceivedComments(String receivedComments) { + this.receivedComments = receivedComments; + } + + public Date getPerformedAt() { + return performedAt; + } + + public void setPerformedAt(Date performedAt) { + this.performedAt = performedAt; + } + + public String getPerformedDepartment() { + return performedDepartment; + } + + public void setPerformedDepartment(String performedDepartment) { + this.performedDepartment = performedDepartment; + } + + public String getPerformedInstitution() { + return performedInstitution; + } + + public void setPerformedInstitution(String performedInstitution) { + this.performedInstitution = performedInstitution; + } + + public String getPerformedComments() { + return performedComments; + } + + public void setPerformedComments(String performedComments) { + this.performedComments = performedComments; + } + + public Date getApprovedAt() { + return approvedAt; + } + + public void setApprovedAt(Date approvedAt) { + this.approvedAt = approvedAt; + } + + public String getApprovedDepartment() { + return approvedDepartment; + } + + public void setApprovedDepartment(String approvedDepartment) { + this.approvedDepartment = approvedDepartment; + } + + public String getApprovedInstitution() { + return approvedInstitution; + } + + public void setApprovedInstitution(String approvedInstitution) { + this.approvedInstitution = approvedInstitution; + } + + public String getApprovedComments() { + return approvedComments; + } + + public void setApprovedComments(String approvedComments) { + this.approvedComments = approvedComments; + } + + public Boolean getOutsourced() { + return outsourced; + } + + public void setOutsourced(Boolean outsourced) { + this.outsourced = outsourced; + } + + public String getOutsourcedInstitution() { + return outsourcedInstitution; + } + + public void setOutsourcedInstitution(String outsourcedInstitution) { + this.outsourcedInstitution = outsourcedInstitution; + } + + public String getOutsourcedComments() { + return outsourcedComments; + } + + public void setOutsourcedComments(String outsourcedComments) { + this.outsourcedComments = outsourcedComments; + } + + public String getOutsourcedDepartment() { + return outsourcedDepartment; + } + + public void setOutsourcedDepartment(String outsourcedDepartment) { + this.outsourcedDepartment = outsourcedDepartment; + } + + public ViewInvestigationResponseDTO getInvestigation() { + return investigation; + } + + public void setInvestigation(ViewInvestigationResponseDTO investigation) { + this.investigation = investigation; + } + + public List getReports() { + return reports; + } + + public void setReports(List reports) { + this.reports = reports; + } +} diff --git a/src/main/java/com/divudi/ws/report/ViewReportItemValueResponseDTO.java b/src/main/java/com/divudi/ws/report/ViewReportItemValueResponseDTO.java new file mode 100644 index 00000000000..24d8b95454d --- /dev/null +++ b/src/main/java/com/divudi/ws/report/ViewReportItemValueResponseDTO.java @@ -0,0 +1,114 @@ +package com.divudi.ws.report; + +import com.divudi.core.entity.lab.InvestigationItemValue; +import com.divudi.core.entity.lab.PatientReportItemValue; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class ViewReportItemValueResponseDTO { + private String investigationItemName; + private String strValue; + private String lobValue; + private String ixItemType; + private String ixItemValueType; + private List itemValueList; + + public static ViewReportItemValueResponseDTO fromPatientReportItemValue( + final PatientReportItemValue patientReportItemValue) { + + ViewReportItemValueResponseDTO dto = new ViewReportItemValueResponseDTO(); + + if (patientReportItemValue == null) { + return dto; + } + + if (patientReportItemValue.getInvestigationItem() != null) { + dto.investigationItemName = patientReportItemValue.getInvestigationItem().getName(); + } else { + dto.investigationItemName = null; + } + + dto.strValue = patientReportItemValue.getStrValue(); + dto.lobValue = patientReportItemValue.getLobValue(); + dto.ixItemType = patientReportItemValue.getInvestigationItem() != null + ? patientReportItemValue.getInvestigationItem().getIxItemType() != null + ? patientReportItemValue.getInvestigationItem().getIxItemType().name() + : null + : null; + dto.ixItemValueType = patientReportItemValue.getInvestigationItem() != null + ? patientReportItemValue.getInvestigationItem().getIxItemValueType() != null + ? patientReportItemValue.getInvestigationItem().getIxItemValueType().name() + : null + : null; + + if (patientReportItemValue.getInvestigationItem() != null && + patientReportItemValue.getInvestigationItem().getInvestigationItemValues() != null) { + + dto.itemValueList = patientReportItemValue.getInvestigationItem() + .getInvestigationItemValues() + .stream() + .map(InvestigationItemValue::getName) + .collect(Collectors.toList()); + } else { + dto.itemValueList = Collections.emptyList(); + } + + return dto; + } + + public static List fromPatientReportItemValues(final List patientReportItemValues) { + return patientReportItemValues.stream() + .map(ViewReportItemValueResponseDTO::fromPatientReportItemValue) + .collect(Collectors.toList()); + } + + public String getInvestigationItemName() { + return investigationItemName; + } + + public void setInvestigationItemName(String investigationItemName) { + this.investigationItemName = investigationItemName; + } + + public String getStrValue() { + return strValue; + } + + public void setStrValue(String strValue) { + this.strValue = strValue; + } + + public List getItemValueList() { + return itemValueList; + } + + public void setItemValueList(List itemValueList) { + this.itemValueList = itemValueList; + } + + public String getLobValue() { + return lobValue; + } + + public void setLobValue(String lobValue) { + this.lobValue = lobValue; + } + + public String getIxItemType() { + return ixItemType; + } + + public void setIxItemType(String ixItemType) { + this.ixItemType = ixItemType; + } + + public String getIxItemValueType() { + return ixItemValueType; + } + + public void setIxItemValueType(String ixItemValueType) { + this.ixItemValueType = ixItemValueType; + } +} diff --git a/src/main/java/com/divudi/ws/report/ViewReportResponseDTO.java b/src/main/java/com/divudi/ws/report/ViewReportResponseDTO.java new file mode 100644 index 00000000000..41785144ff7 --- /dev/null +++ b/src/main/java/com/divudi/ws/report/ViewReportResponseDTO.java @@ -0,0 +1,307 @@ +package com.divudi.ws.report; + +import com.divudi.core.entity.lab.PatientReport; + +import java.util.Collections; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +public class ViewReportResponseDTO { + private Long id; + private Date createdAt; + + private Boolean dataEntered; + private String dataEntryUser; + private Date dataEntryAt; + private String dataEntryComments; + private String dataEntryDepartment; + private String dataEntryInstitution; + + private Boolean approved; + private String approveUser; + private Date approveAt; + private String approveComments; + private String approveDepartment; + private String approveInstitution; + + private Boolean printed; + private String printingUser; + private Date printingAt; + private String printingComments; + private String printingDepartment; + private String printingInstitution; + + private String reportFormat; + private String qrCodeContentsDetailed; + private String qrCodeContentsLink; + + private List reportItemValues; + + public static ViewReportResponseDTO fromPatientReport(final PatientReport patientReport) { + ViewReportResponseDTO dto = new ViewReportResponseDTO(); + + if (patientReport == null) { + return dto; + } + + dto.id = patientReport.getId(); + dto.createdAt = patientReport.getCreatedAt(); + + dto.dataEntered = patientReport.getDataEntered(); + dto.dataEntryUser = patientReport.getDataEntryUser() != null + ? patientReport.getDataEntryUser().getName() + : null; + dto.dataEntryAt = patientReport.getDataEntryAt(); + dto.dataEntryComments = patientReport.getDataEntryComments(); + dto.dataEntryDepartment = patientReport.getDataEntryDepartment() != null + ? patientReport.getDataEntryDepartment().getName() + : null; + dto.dataEntryInstitution = patientReport.getDataEntryInstitution() != null + ? patientReport.getDataEntryInstitution().getName() + : null; + + dto.approved = patientReport.getApproved(); + dto.approveUser = patientReport.getApproveUser() != null + ? patientReport.getApproveUser().getName() + : null; + dto.approveAt = patientReport.getApproveAt(); + dto.approveComments = patientReport.getApproveComments(); + dto.approveDepartment = patientReport.getApproveDepartment() != null + ? patientReport.getApproveDepartment().getName() + : null; + dto.approveInstitution = patientReport.getApproveInstitution() != null + ? patientReport.getApproveInstitution().getName() + : null; + + dto.printed = patientReport.getPrinted(); + dto.printingUser = patientReport.getPrintingUser() != null + ? patientReport.getPrintingUser().getName() + : null; + dto.printingAt = patientReport.getPrintingAt(); + dto.printingComments = patientReport.getPrintingComments(); + dto.printingDepartment = patientReport.getPrintingDepartment() != null + ? patientReport.getPrintingDepartment().getName() + : null; + dto.printingInstitution = patientReport.getPrintingInstitution() != null + ? patientReport.getPrintingInstitution().getName() + : null; + + dto.reportFormat = patientReport.getReportFormat() != null + ? patientReport.getReportFormat().getName() + : null; + + dto.qrCodeContentsDetailed = patientReport.getQrCodeContentsDetailed(); + dto.qrCodeContentsLink = patientReport.getQrCodeContentsLink(); + + dto.reportItemValues = patientReport.getPatientReportItemValues() != null + ? ViewReportItemValueResponseDTO.fromPatientReportItemValues( + patientReport.getPatientReportItemValues() + ) + : Collections.emptyList(); + + return dto; + } + + public static List fromPatientReports(final List patientReports) { + if (patientReports == null) { + return Collections.emptyList(); + } + + return patientReports.stream() + .map(ViewReportResponseDTO::fromPatientReport) + .collect(Collectors.toList()); + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Boolean getDataEntered() { + return dataEntered; + } + + public void setDataEntered(Boolean dataEntered) { + this.dataEntered = dataEntered; + } + + public String getDataEntryUser() { + return dataEntryUser; + } + + public void setDataEntryUser(String dataEntryUser) { + this.dataEntryUser = dataEntryUser; + } + + public Date getDataEntryAt() { + return dataEntryAt; + } + + public void setDataEntryAt(Date dataEntryAt) { + this.dataEntryAt = dataEntryAt; + } + + public String getDataEntryComments() { + return dataEntryComments; + } + + public void setDataEntryComments(String dataEntryComments) { + this.dataEntryComments = dataEntryComments; + } + + public String getDataEntryDepartment() { + return dataEntryDepartment; + } + + public void setDataEntryDepartment(String dataEntryDepartment) { + this.dataEntryDepartment = dataEntryDepartment; + } + + public String getDataEntryInstitution() { + return dataEntryInstitution; + } + + public void setDataEntryInstitution(String dataEntryInstitution) { + this.dataEntryInstitution = dataEntryInstitution; + } + + public Boolean getApproved() { + return approved; + } + + public void setApproved(Boolean approved) { + this.approved = approved; + } + + public String getApproveUser() { + return approveUser; + } + + public void setApproveUser(String approveUser) { + this.approveUser = approveUser; + } + + public Date getApproveAt() { + return approveAt; + } + + public void setApproveAt(Date approveAt) { + this.approveAt = approveAt; + } + + public String getApproveComments() { + return approveComments; + } + + public void setApproveComments(String approveComments) { + this.approveComments = approveComments; + } + + public String getApproveDepartment() { + return approveDepartment; + } + + public void setApproveDepartment(String approveDepartment) { + this.approveDepartment = approveDepartment; + } + + public String getApproveInstitution() { + return approveInstitution; + } + + public void setApproveInstitution(String approveInstitution) { + this.approveInstitution = approveInstitution; + } + + public Boolean getPrinted() { + return printed; + } + + public void setPrinted(Boolean printed) { + this.printed = printed; + } + + public String getPrintingUser() { + return printingUser; + } + + public void setPrintingUser(String printingUser) { + this.printingUser = printingUser; + } + + public Date getPrintingAt() { + return printingAt; + } + + public void setPrintingAt(Date printingAt) { + this.printingAt = printingAt; + } + + public String getPrintingComments() { + return printingComments; + } + + public void setPrintingComments(String printingComments) { + this.printingComments = printingComments; + } + + public String getPrintingDepartment() { + return printingDepartment; + } + + public void setPrintingDepartment(String printingDepartment) { + this.printingDepartment = printingDepartment; + } + + public String getPrintingInstitution() { + return printingInstitution; + } + + public void setPrintingInstitution(String printingInstitution) { + this.printingInstitution = printingInstitution; + } + + public String getReportFormat() { + return reportFormat; + } + + public void setReportFormat(String reportFormat) { + this.reportFormat = reportFormat; + } + + public String getQrCodeContentsDetailed() { + return qrCodeContentsDetailed; + } + + public void setQrCodeContentsDetailed(String qrCodeContentsDetailed) { + this.qrCodeContentsDetailed = qrCodeContentsDetailed; + } + + public String getQrCodeContentsLink() { + return qrCodeContentsLink; + } + + public void setQrCodeContentsLink(String qrCodeContentsLink) { + this.qrCodeContentsLink = qrCodeContentsLink; + } + + public List getReportItemValues() { + return reportItemValues; + } + + public void setReportItemValues(List reportItemValues) { + this.reportItemValues = reportItemValues; + } +} diff --git a/src/main/java/com/divudi/ws/report/ViewReportsResponseDTO.java b/src/main/java/com/divudi/ws/report/ViewReportsResponseDTO.java new file mode 100644 index 00000000000..2f68e2f2475 --- /dev/null +++ b/src/main/java/com/divudi/ws/report/ViewReportsResponseDTO.java @@ -0,0 +1,123 @@ +package com.divudi.ws.report; + +import com.divudi.core.entity.lab.PatientInvestigation; + +import java.util.Date; +import java.util.List; + +public class ViewReportsResponseDTO { + private String nic; + private String mobile; + private String name; + private String phn; + private Date dateOfBirth; + private String title; + private String sex; + private String bloodGroup; + private String fromDate; + private String toDate; + private List patientInvestigations; + + public ViewReportsResponseDTO(String mobile, String fromDate, String toDate, List patientInvestigations) { + this.nic = !patientInvestigations.isEmpty() ? patientInvestigations.get(0).getPatient().getPerson().getNic() : null; + this.mobile = mobile; + this.name = !patientInvestigations.isEmpty() ? patientInvestigations.get(0).getPatient().getPerson().getName() : null; + this.phn = !patientInvestigations.isEmpty() ? patientInvestigations.get(0).getPatient().getPhn() : null; + this.dateOfBirth = !patientInvestigations.isEmpty() ? patientInvestigations.get(0).getPatient().getPerson().getDob() : null; + this.title = !patientInvestigations.isEmpty() ? patientInvestigations.get(0).getPatient().getPerson().getTitle().name() : null; + this.sex = !patientInvestigations.isEmpty() ? patientInvestigations.get(0).getPatient().getPerson().getSex().name() : null; + this.bloodGroup = !patientInvestigations.isEmpty() && patientInvestigations.get(0).getPatient().getPerson().getBloodGroup() != null + ? patientInvestigations.get(0).getPatient().getPerson().getBloodGroup().getName() : null; + this.fromDate = fromDate; + this.toDate = toDate; + this.patientInvestigations = ViewPatientInvestigationResponseDTO.fromPatientInvestigations(patientInvestigations); + } + + public String getNic() { + return nic; + } + + public void setNic(String nic) { + this.nic = nic; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getFromDate() { + return fromDate; + } + + public void setFromDate(String fromDate) { + this.fromDate = fromDate; + } + + public String getToDate() { + return toDate; + } + + public void setToDate(String toDate) { + this.toDate = toDate; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPhn() { + return phn; + } + + public void setPhn(String phn) { + this.phn = phn; + } + + public Date getDateOfBirth() { + return dateOfBirth; + } + + public void setDateOfBirth(Date dateOfBirth) { + this.dateOfBirth = dateOfBirth; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getSex() { + return sex; + } + + public void setSex(String sex) { + this.sex = sex; + } + + public String getBloodGroup() { + return bloodGroup; + } + + public void setBloodGroup(String bloodGroup) { + this.bloodGroup = bloodGroup; + } + + public List getPatientInvestigations() { + return patientInvestigations; + } + + public void setPatientInvestigations(List patientInvestigations) { + this.patientInvestigations = patientInvestigations; + } +}