private Boolean createAndSavePatientDocument(OutPatientListVo outPatientListVo, PatientDocumentErrorVoCollection errors) //WDEV-12640 { if(outPatientListVo == null || outPatientListVo.getPasEvent() == null || outPatientListVo.getPasEvent().getPatient() == null) return false; PatientShort patient = outPatientListVo.getPasEvent().getPatient(); CareContextMinVo careContext = domain.getCareContextByPasEvent(outPatientListVo.getPasEvent()); ClinicRefVo clinic = outPatientListVo.getClinic(); PatientDocumentVo patDoc = savePatientDocuments(patient, careContext, clinic, "DummyFileName", errors); if (patDoc == null) return false; String fileName = createReport(patient, careContext,patDoc, errors); if (fileName == null) { domain.deletePatientDocument(patDoc); return false; } patDoc.getServerDocument().setFileName(fileName); patDoc.validate(); try { domain.savePatientDocument(patDoc); } catch (StaleObjectException e) { domain.deletePatientDocument(patDoc); deleteFile(getWorkAreaPath() + fileName);//WDEV-13366 e.printStackTrace(); errors.add(createError(patient, careContext, "Could not be created")); return false; } return true; }
private PatientDocumentVo savePatientDocuments(PatientShort patient, CareContextMinVo careContext, ClinicRefVo clinic, String fileName, PatientDocumentErrorVoCollection errors) { if(fileName == null || fileName.length() == 0) return null; PatientDocumentVo vo = populatePatientDocumentVo(patient, careContext, clinic, populateServerDocumentVo(fileName)); if(vo == null) return null; String[] str = vo.validate(); if (str != null && str.length > 0) { errors.add(createError(patient, careContext, "Could not be created")); return null; } try { return domain.savePatientDocument(vo); } catch (StaleObjectException e) { e.printStackTrace(); errors.add(createError(patient, careContext, "Could not be created")); return null; } }
private String createReport(PatientShort patient, CareContextMinVo carecontext,PatientDocumentVo doc, PatientDocumentErrorVoCollection errors) { String urlQueryServer = ConfigFlag.GEN.QUERY_SERVER_URL.getValue(); String urlReportServer = ConfigFlag.GEN.REPORT_SERVER_URL.getValue(); ReportTemplateVo template = domain.getTemplate((TemplateForPatientDocumentVo) form.lyrLetterCreate().tabTemplate().dyngrdReports().getValue()); QueryBuilderClient client = new QueryBuilderClient(urlQueryServer, engine.getSessionId()); ReportSeedParsedVoCollection seeds = getSeedsFromReport(template.getReport().getReportXml()); addSeedsForTemplate(client, seeds, patient, carecontext,doc); if(!addValueForNonMandatorySeeds(client, seeds))// WDEV-14299 { errors.add(createError(patient, carecontext, "Could not be created")); return null; } String [] errorsSeed = checkForSeeds(seeds, client); if(errorsSeed != null && errorsSeed.length > 0) { errors.add(createError(patient, carecontext, "Could not be created")); return null; } String fileName; try { fileName = client.buildReportAndUpload(getWorkAreaPath(), template.getReport().getReportXml(), template.getTemplateXml(), urlReportServer, QueryBuilderClient.RTF, "", 1, false);//WDEV-13366 } catch (QueryBuilderClientException e1) { errors.add(createError(patient, carecontext, "Could not be created")); e1.printStackTrace(); return null; } return fileName; }
private PatientDocumentErrorVo createError(PatientShort patient, CareContextMinVo careContext, String errorValue) { PatientDocumentErrorVo error = new PatientDocumentErrorVo(); error.setPatient(patient.getName()); error.setIdentifiers(patient.getIdentifiers()); error.setDocumentName(((TemplateForPatientDocumentVo) form.lyrLetterCreate().tabTemplate().dyngrdReports().getValue()).getName()); error.setDocumentDate((careContext != null && careContext.getStartDateTime() != null ) ? careContext.getStartDateTime().getDate() : new Date()); error.setError(errorValue); return error; }
public CareContextMinVo getCareContextByPasEvent(PASEventRefVo pasEvent) { if(pasEvent == null || !pasEvent.getID_PASEventIsNotNull()) throw new CodingRuntimeException("Cannot get Care Context on null Pas Event."); DomainFactory factory = getDomainFactory(); List<?> careContext = factory.find("from CareContext as cc where cc.pasEvent.id = :PasEventId order by cc.systemInformation.creationDateTime desc ", new String[] {"PasEventId"}, new Object[] {pasEvent.getID_PASEvent()}); if(careContext == null || careContext.size() == 0) return null; return CareContextMinVoAssembler.create((CareContext) careContext.get(0)); }
private PatientDocumentVo populatePatientDocumentVo(PatientShort patient, CareContextMinVo careContext, ClinicRefVo clinic, ServerDocumentVo serverDocumentVo) { if(serverDocumentVo == null) return null; PatientDocumentVo vo = new PatientDocumentVo(); vo.setPatient(patient); vo.setEpisodeofCare(careContext != null ? careContext.getEpisodeOfCare() : null); vo.setCareContext(careContext); if(form.lyrLetterCreate().tabTemplate().dyngrdReports().getValue() instanceof TemplateForPatientDocumentVo) { vo.setName(((TemplateForPatientDocumentVo) form.lyrLetterCreate().tabTemplate().dyngrdReports().getValue()).getName()); DocumentCategoryConfigShortVo dc = domain.getDocCatConfig((TemplateForPatientDocumentVo) form.lyrLetterCreate().tabTemplate().dyngrdReports().getValue()); vo.setCategory(dc != null ? dc.getCategory() : null); } vo.setServerDocument(serverDocumentVo); vo.setCreationType(DocumentCreationType.GENERATED); vo.setStatus(PreActiveActiveInactiveStatus.ACTIVE); MemberOfStaffLiteVo mosUser = form.lyrLetterCreate().tabTemplate().ccTypist().getValue() instanceof MemberOfStaffLiteVo ? (MemberOfStaffLiteVo) form.lyrLetterCreate().tabTemplate().ccTypist().getValue() : null; vo.setRecordingUser(mosUser); vo.setRecordingDateTime(new DateTime()); HcpRefVo hcpUser = form.lyrLetterCreate().tabTemplate().ccAuth().getValue() instanceof HcpRefVo ? (HcpRefVo) form.lyrLetterCreate().tabTemplate().ccAuth().getValue() : null; vo.setAuthoringHCP(hcpUser); vo.setAuthoringDateTime(new DateTime()); vo.setSpecialty(form.lyrLetterCreate().tabTemplate().cmbSpecialty().getValue()!=null?form.lyrLetterCreate().tabTemplate().cmbSpecialty().getValue():((careContext != null && careContext.getEpisodeOfCare() != null) ? careContext.getEpisodeOfCare().getSpecialty() : null)); PatientDocumentStatusVo documentStatus = new PatientDocumentStatusVo(); documentStatus.setCorrespondenceStatus(DocumentStatus.DRAFT); documentStatus.setRecordingUser((MemberOfStaffLiteVo)domain.getMosUser()); documentStatus.setRecordingDateTime(new DateTime()); vo.setCurrentDocumentStatus(documentStatus); PatientDocumentStatusVoCollection historyStatus = new PatientDocumentStatusVoCollection(); historyStatus.add(documentStatus); vo.setDocumentStatusHistory(historyStatus); vo.setDocumentDate(form.lyrLetterCreate().tabTemplate().dteDocDate().getValue()!=null?form.lyrLetterCreate().tabTemplate().dteDocDate().getValue():((careContext != null && careContext.getStartDateTime() != null ) ? careContext.getStartDateTime().getDate() : new Date())); //WDEV-12721 if(form.getLocalContext().getMinDate() == null || vo.getDocumentDate().isLessThan(form.getLocalContext().getMinDate())) form.getLocalContext().setMinDate(vo.getDocumentDate()); //WDEV-12721 if(form.getLocalContext().getMaxDate() == null || vo.getDocumentDate().isGreaterThan(form.getLocalContext().getMaxDate())) form.getLocalContext().setMaxDate(vo.getDocumentDate()); vo.setClinic(clinic); HcpRefVo responsibleHcp = form.lyrLetterCreate().tabTemplate().ccResponsible().getValue() instanceof HcpRefVo ? (HcpRefVo)form.lyrLetterCreate().tabTemplate().ccResponsible().getValue():(careContext != null && careContext.getResponsibleHCP() != null) ? careContext.getResponsibleHCP() : (careContext != null && careContext.getEpisodeOfCare() != null) ? careContext.getEpisodeOfCare().getResponsibleHCP() : null; vo.setResponsibleHCP(responsibleHcp); return vo; }