Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.73 KB | None | 0 0
  1. /**
  2. * @author Humberto
  3. *
  4. */
  5.  
  6. @Audited
  7. @Entity
  8. @Table(name = "evento")
  9. @SequenceGenerator(name = "evento_seq", sequenceName = "evento_seq", initialValue = 1, allocationSize = 1)
  10. public class Evento implements Serializable {
  11.  
  12. private static final long serialVersionUID = 1089332436469136104L;
  13. @Id
  14. @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "evento_seq")
  15. private Long id;
  16. private String titulo;
  17.  
  18. private Date dataInicio;
  19. private Date dataFim;
  20. private boolean diaInteiro;
  21. private TipoEvento tipoEvento;
  22. private String descricao;
  23.  
  24. @ManyToOne(cascade = CascadeType.ALL)
  25. @JoinColumn()
  26. private Paciente paciente;
  27.  
  28. @ManyToOne(cascade = CascadeType.ALL)
  29. @JoinColumn()
  30. private Medico medico;
  31.  
  32.  
  33. public Evento() {
  34. this.tipoEvento = TipoEvento.CONSULTA;
  35. this.titulo = "";
  36. this.diaInteiro = false;
  37. }
  38.  
  39. public Evento(Long id,
  40. String titulo,
  41. Date dataInicio,
  42. Date dataFim,
  43. boolean diaInteiro,
  44. TipoEvento tipoEvento,
  45. String descricao,
  46. Paciente paciente,
  47. Medico medico)
  48. {
  49.  
  50. this.id = id;
  51. this.titulo = titulo;
  52. this.dataInicio = dataInicio;
  53. this.dataFim = dataFim;
  54. this.diaInteiro = diaInteiro;
  55. this.tipoEvento = tipoEvento;
  56. this.setDescricao(descricao);
  57. this.paciente = paciente;
  58. this.medico = medico;
  59. }
  60.  
  61. public Long getId() {
  62. return id;
  63. }
  64.  
  65. public void setId(Long id) {
  66. this.id = id;
  67. }
  68.  
  69. public String getTitulo() {
  70. return titulo;
  71. }
  72.  
  73. public void setTitulo(String titulo) {
  74. this.titulo = titulo;
  75. }
  76.  
  77. public Date getDataInicio() {
  78. return dataInicio;
  79. }
  80.  
  81. public void setDataInicio(Date dataInicio) {
  82. //Calendar calendar = java.util.Calendar.getInstance() ;
  83. // calendar.set(Calendar.HOUR_OF_DAY, 8) ;
  84. //calendar.set(Calendar);
  85.  
  86. this.dataInicio = dataInicio;
  87. }
  88.  
  89. public Date getDataFim() {
  90. return dataFim;
  91. }
  92.  
  93. public void setDataFim(Date dataFim) {
  94. this.dataFim = dataFim;
  95. }
  96.  
  97. public boolean isDiaInteiro() {
  98. return diaInteiro;
  99. }
  100.  
  101. public void setDiaInteiro(boolean diaInteiro) {
  102. this.diaInteiro = diaInteiro;
  103. }
  104.  
  105. public TipoEvento getTipoEvento() {
  106. return tipoEvento;
  107. }
  108.  
  109. public void setTipoEvento(TipoEvento tipoEvento) {
  110. this.tipoEvento = tipoEvento;
  111. }
  112.  
  113. public Medico getMedico() {
  114. return medico;
  115. }
  116.  
  117. public void setMedico(Medico medico) {
  118. this.medico = medico;
  119. }
  120. @Override
  121. public int hashCode() {
  122. int hash = 3;
  123. hash = 29 * hash + Objects.hashCode(this.id);
  124. return hash;
  125. }
  126.  
  127. @Override
  128. public boolean equals(Object obj) {
  129. if (this == obj) {
  130. return true;
  131. }
  132. if (obj == null) {
  133. return false;
  134. }
  135. if (getClass() != obj.getClass()) {
  136. return false;
  137. }
  138. final Evento other = (Evento) obj;
  139. if (!Objects.equals(this.id, other.id)) {
  140. return false;
  141. }
  142. return true;
  143. }
  144.  
  145. public Paciente getPaciente() {
  146. return paciente;
  147. }
  148.  
  149. public void setPaciente(Paciente paciente) {
  150. this.paciente = paciente;
  151. }
  152.  
  153. public String getDescricao() {
  154. return descricao;
  155. }
  156.  
  157. public void setDescricao(String descricao) {
  158. this.descricao = descricao;
  159. }
  160.  
  161.  
  162. }
  163.  
  164. @ManagedBean(name = "scheduleBean")
  165. @Controller
  166. @Scope(value = "session")
  167. public class ScheduleBean extends BeanManagedViewAbstract {
  168.  
  169. private static final long serialVersionUID = 1L;
  170.  
  171. private ScheduleModel model;
  172. private Evento evento = new Evento();
  173. private ScheduleEvent event;
  174. private List<ScheduleEvent> scheduleEvents;
  175. private Date dataInicioSelecionada;
  176. private Date dataFimSelecionada;
  177.  
  178. Date dataAtual = new Date();
  179.  
  180. private CarregamentoLazyListForObjeto<Evento> list = new CarregamentoLazyListForObjeto<Evento>();
  181.  
  182. @Autowired
  183. private EventoController eventoController;
  184.  
  185. @Autowired
  186. private PacienteController pacienteController;
  187.  
  188. @Autowired
  189. private MedicoController medicoController;
  190.  
  191. public ScheduleBean() {
  192. event = new CustomScheduleEvent();
  193. model = new DefaultScheduleModel();
  194.  
  195. evento = new Evento();
  196. }
  197.  
  198. @Override
  199. public StreamedContent getArquivoReport() throws Exception {
  200. super.setNomeRelatorioJasper("report_evento");
  201. super.setNomeRelatorioSaida("report_evento");
  202. super.setListDataBeanCollectionReport(eventoController.findList(getClassImp()));
  203. return super.getArquivoReport();
  204. }
  205.  
  206. // LISTA DE PACIENTES
  207. public List<SelectItem> getPacientes() throws Exception {
  208. return pacienteController.getListPacientes();
  209. }
  210.  
  211. // LISTA DE MEDICOS
  212. public List<SelectItem> getMedicos() throws Exception {
  213. return medicoController.getListMedicos();
  214. }
  215.  
  216. @PostConstruct
  217. public void init() throws Exception {
  218.  
  219. if (this.model != null) {
  220. List<Evento> eventos = this.eventoController.listarEventos();
  221. // List<Evento> eventos = this.eventoDAO.listarTodos();
  222. if (this.scheduleEvents == null) {
  223. this.scheduleEvents = new ArrayList<ScheduleEvent>();
  224. }
  225. for (Evento eventoAtual : eventos) { // lista que popula os eventos e inseri
  226. ScheduleEvent newEvent = new CustomScheduleEvent(eventoAtual.getTitulo(), eventoAtual.getDataInicio(),
  227. eventoAtual.getDataFim(), eventoAtual.getTipoEvento().getCss(), eventoAtual.isDiaInteiro(),
  228. eventoAtual.getDescricao(), eventoAtual.getMedico(), eventoAtual.getPaciente(), eventoAtual);
  229. if (!this.scheduleEvents.contains(newEvent)) {
  230. newEvent.setId(eventoAtual.getId().toString());
  231. this.scheduleEvents.add(newEvent);
  232. this.model.addEvent(newEvent);
  233. }
  234. }
  235. }
  236. }
  237.  
  238. public boolean validarMedico() throws Exception {
  239.  
  240. String[] param = new String[] {"idMedico", "dataInicio", "dataFim"};
  241. String hql ="FROM Evento e WHERE e.medico.idMedico = "
  242. + ":idMedico AND (e.dataInicio BETWEEN :dataInicio AND :dataFim "
  243. + "OR e.dataFim BETWEEN :dataInicio AND :dataFim)";
  244.  
  245. List<Evento> lista = eventoController.findListByQueryDinamica(
  246. hql, Arrays.asList(param) , evento.getMedico().getIdMedico(), evento.getDataInicio(), evento.getDataFim());
  247.  
  248. if (evento.getId() == null && !lista.isEmpty()) {
  249. return false;
  250. }else if((this.dataInicioSelecionada.compareTo(evento.getDataInicio()) != 0 ||
  251. this.dataFimSelecionada.compareTo(evento.getDataFim()) !=0)
  252. && !lista.isEmpty()){
  253. return false;
  254. }else {
  255. return true;
  256. }
  257. }
  258.  
  259. public void salvar() throws Exception {
  260. // salva o construtor que implementa a interface do Schedule com os atributos.
  261. ScheduleEvent newEvent = new CustomScheduleEvent(this.evento.getTitulo(), this.evento.getDataInicio(),
  262. this.evento.getDataFim(), this.evento.getTipoEvento().getCss(), this.evento.isDiaInteiro(),
  263. this.evento.getDescricao(), this.evento.getMedico(), this.evento.getPaciente(), this.evento);
  264.  
  265. if (evento.getDataInicio().before(evento.getDataFim()) && validarMedico()) {
  266.  
  267. if (evento.getId() == null) {
  268. model.addEvent(newEvent);
  269. } else {
  270. newEvent.setId(event.getId());
  271. model.updateEvent(newEvent);
  272. }
  273. eventoController.merge(evento);
  274. FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Agendamento Salvo",
  275. "Agendamento para: " + evento.getTitulo());
  276. addMessage(message);
  277. }else {
  278. FacesMessage message = new FacesMessage(
  279. FacesMessage.SEVERITY_INFO, "Já existe um médico cadastrado CAIU NO ELSE",
  280. "" );
  281. addMessage(message);
  282. }
  283. }
  284.  
  285. public void remover() throws Exception {
  286. eventoController.delete(evento);
  287. model.deleteEvent(event);
  288. FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Agendamento Removido",
  289. "Agendamento Removido :" + evento.getTitulo());
  290. addMessage(message);
  291. }
  292.  
  293. // AO SALVAR SELEÇÃO DE UMA AGENDAMENTO
  294. public void onDateSelect(SelectEvent selectEvent) {
  295. this.evento = new Evento();
  296. Date dataSelecionada = (Date) selectEvent.getObject();
  297. @SuppressWarnings("unused")
  298. DateTime dataSelecionadaJoda = new DateTime(dataSelecionada.getTime());
  299. this.evento.setDataInicio(dataSelecionada);
  300. // Adiciona 30min por consulta
  301. //this.evento.setDataFim(dataSelecionadaJoda.plusMinutes(30).toDate());
  302. }
  303.  
  304. // EVENTO DE SELEÇÃO DOS HORARIOS AGENDADOS
  305. public void onEventSelect(SelectEvent selectEvent) {
  306. event = (CustomScheduleEvent) selectEvent.getObject();
  307. this.evento = (Evento) event.getData();
  308. this.dataInicioSelecionada = this.evento.getDataInicio();
  309. this.dataFimSelecionada = this.evento.getDataFim();
  310. }
  311.  
  312. // EVENTO QUE PERMITE REDIMENSIONAR HORARIOS
  313. public void onEventResize(ScheduleEntryResizeEvent event) {
  314. FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Evento Redimensionado",
  315. "Dia:" + event.getDayDelta() + ", Horário:" + event.getMinuteDelta());
  316. addMessage(message);
  317. }
  318.  
  319. // EVENTO QUE PERMITE MOVER HORARIOS SELECIONADOS
  320. public void onEventMove(ScheduleEntryMoveEvent event) {
  321. /*
  322. * if(evento.getDataInicio().getTime() <= evento.getDataFim().getTime()){
  323. *
  324. * try{ eventoController.merge(evento); }catch(Exception ex){
  325. * FacesContext.getCurrentInstance().addMessage(null, new
  326. * FacesMessage("Erro ao salvar trabalho", "Erro:" + ex.getMessage())); } evento
  327. * = new Evento(); }else{ FacesContext.getCurrentInstance().addMessage(null, new
  328. * FacesMessage("Data do começo do evento não pode ser maior que a do final",
  329. * "")); }
  330. */
  331.  
  332. // FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Event
  333. // moved", "Day delta:" + event.getDayDelta() + ", Minute delta:" +
  334. // event.getMinuteDelta());
  335.  
  336. // addMessage(message);
  337. }
  338.  
  339. private void addMessage(FacesMessage message) {
  340. FacesContext.getCurrentInstance().addMessage(null, message);
  341. }
  342.  
  343. public TipoEvento[] getTiposEventos() {
  344. return TipoEvento.values();
  345. }
  346.  
  347. // GETTERS E SETTERS
  348.  
  349. public List<ScheduleEvent> getScheduleEvents() {
  350. return scheduleEvents;
  351. }
  352.  
  353. public void setScheduleEvents(List<ScheduleEvent> scheduleEvents) {
  354. this.scheduleEvents = scheduleEvents;
  355. }
  356.  
  357. public Date getDataAtual() {
  358. return dataAtual;
  359. }
  360.  
  361. public void setDataAtual(Date dataAtual) {
  362. // Pega somente a data para passar para data minima do calendario
  363. LocalDate localDate = new LocalDate();
  364. dataAtual = localDate.toDate();
  365.  
  366. this.dataAtual = dataAtual;
  367. }
  368.  
  369. @Override
  370. protected Class<Evento> getClassImp() {
  371. return Evento.class;
  372. }
  373.  
  374. @Override
  375. protected InterfaceCrud<Evento> getController() {
  376. return eventoController;
  377. }
  378.  
  379. @Override
  380. public void consultarEntidade() throws Exception {
  381. evento = new Evento();
  382. list.clean();
  383. list.setTotalRegistroConsulta(super.totalRegistroConsulta(), super.getSqlLazyQuery());
  384.  
  385. }
  386.  
  387. @Override
  388. public String condicaoAndParaPesquisa() throws Exception {
  389. return null;
  390. }
  391.  
  392. public ScheduleModel getModel() {
  393. return model;
  394. }
  395.  
  396. public void setModel(ScheduleModel model) {
  397. this.model = model;
  398. }
  399.  
  400. public Evento getEvento() {
  401. return evento;
  402. }
  403.  
  404. public void setEvento(Evento evento) {
  405. this.evento = evento;
  406. }
  407.  
  408. public CarregamentoLazyListForObjeto<Evento> getList() {
  409. return list;
  410. }
  411.  
  412. public void setList(CarregamentoLazyListForObjeto<Evento> list) {
  413. this.list = list;
  414. }
  415.  
  416. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement