Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.05 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. return lista.isEmpty();
  258. }
  259.  
  260. public void salvar() throws Exception {
  261. // salva o construtor que implementa a interface do Schedule com os atributos.
  262. ScheduleEvent newEvent = new CustomScheduleEvent(this.evento.getTitulo(), this.evento.getDataInicio(),
  263. this.evento.getDataFim(), this.evento.getTipoEvento().getCss(), this.evento.isDiaInteiro(),
  264. this.evento.getDescricao(), this.evento.getMedico(), this.evento.getPaciente(), this.evento);
  265.  
  266. if (evento.getDataInicio().before(evento.getDataFim()) && validarMedico()) {
  267.  
  268. if (evento.getId() == null) {
  269. model.addEvent(newEvent);
  270. } else {
  271. newEvent.setId(event.getId());
  272. model.updateEvent(newEvent);
  273. }
  274. eventoController.merge(evento);
  275. FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Agendamento Salvo",
  276. "Agendamento para: " + evento.getTitulo());
  277. addMessage(message);
  278. }else {
  279. FacesMessage message = new FacesMessage(
  280. FacesMessage.SEVERITY_INFO, "Já existe um médico cadastrado CAIU NO ELSE",
  281. "" );
  282. addMessage(message);
  283. }
  284. }
  285.  
  286. public void remover() throws Exception {
  287. eventoController.delete(evento);
  288. model.deleteEvent(event);
  289. FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Agendamento Removido",
  290. "Agendamento Removido :" + evento.getTitulo());
  291. addMessage(message);
  292. }
  293.  
  294. // AO SALVAR SELEÇÃO DE UMA AGENDAMENTO
  295. public void onDateSelect(SelectEvent selectEvent) {
  296. this.evento = new Evento();
  297. Date dataSelecionada = (Date) selectEvent.getObject();
  298. @SuppressWarnings("unused")
  299. DateTime dataSelecionadaJoda = new DateTime(dataSelecionada.getTime());
  300. this.evento.setDataInicio(dataSelecionada);
  301. // Adiciona 30min por consulta
  302. //this.evento.setDataFim(dataSelecionadaJoda.plusMinutes(30).toDate());
  303. }
  304.  
  305. // EVENTO DE SELEÇÃO DOS HORARIOS AGENDADOS
  306. public void onEventSelect(SelectEvent selectEvent) {
  307. event = (CustomScheduleEvent) selectEvent.getObject();
  308. this.evento = (Evento) event.getData();
  309. this.dataInicioSelecionada = this.evento.getDataInicio();
  310. this.dataFimSelecionada = this.evento.getDataFim();
  311. }
  312.  
  313. // EVENTO QUE PERMITE REDIMENSIONAR HORARIOS
  314. public void onEventResize(ScheduleEntryResizeEvent event) {
  315. FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Evento Redimensionado",
  316. "Dia:" + event.getDayDelta() + ", Horário:" + event.getMinuteDelta());
  317. addMessage(message);
  318. }
  319.  
  320. // EVENTO QUE PERMITE MOVER HORARIOS SELECIONADOS
  321. public void onEventMove(ScheduleEntryMoveEvent event) {
  322. /*
  323. * if(evento.getDataInicio().getTime() <= evento.getDataFim().getTime()){
  324. *
  325. * try{ eventoController.merge(evento); }catch(Exception ex){
  326. * FacesContext.getCurrentInstance().addMessage(null, new
  327. * FacesMessage("Erro ao salvar trabalho", "Erro:" + ex.getMessage())); } evento
  328. * = new Evento(); }else{ FacesContext.getCurrentInstance().addMessage(null, new
  329. * FacesMessage("Data do começo do evento não pode ser maior que a do final",
  330. * "")); }
  331. */
  332.  
  333. // FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Event
  334. // moved", "Day delta:" + event.getDayDelta() + ", Minute delta:" +
  335. // event.getMinuteDelta());
  336.  
  337. // addMessage(message);
  338. }
  339.  
  340. private void addMessage(FacesMessage message) {
  341. FacesContext.getCurrentInstance().addMessage(null, message);
  342. }
  343.  
  344. public TipoEvento[] getTiposEventos() {
  345. return TipoEvento.values();
  346. }
  347.  
  348. // GETTERS E SETTERS
  349.  
  350. public List<ScheduleEvent> getScheduleEvents() {
  351. return scheduleEvents;
  352. }
  353.  
  354. public void setScheduleEvents(List<ScheduleEvent> scheduleEvents) {
  355. this.scheduleEvents = scheduleEvents;
  356. }
  357.  
  358. public Date getDataAtual() {
  359. return dataAtual;
  360. }
  361.  
  362. public void setDataAtual(Date dataAtual) {
  363. // Pega somente a data para passar para data minima do calendario
  364. LocalDate localDate = new LocalDate();
  365. dataAtual = localDate.toDate();
  366.  
  367. this.dataAtual = dataAtual;
  368. }
  369.  
  370. @Override
  371. protected Class<Evento> getClassImp() {
  372. return Evento.class;
  373. }
  374.  
  375. @Override
  376. protected InterfaceCrud<Evento> getController() {
  377. return eventoController;
  378. }
  379.  
  380. @Override
  381. public void consultarEntidade() throws Exception {
  382. evento = new Evento();
  383. list.clean();
  384. list.setTotalRegistroConsulta(super.totalRegistroConsulta(), super.getSqlLazyQuery());
  385.  
  386. }
  387.  
  388. @Override
  389. public String condicaoAndParaPesquisa() throws Exception {
  390. return null;
  391. }
  392.  
  393. public ScheduleModel getModel() {
  394. return model;
  395. }
  396.  
  397. public void setModel(ScheduleModel model) {
  398. this.model = model;
  399. }
  400.  
  401. public Evento getEvento() {
  402. return evento;
  403. }
  404.  
  405. public void setEvento(Evento evento) {
  406. this.evento = evento;
  407. }
  408.  
  409. public CarregamentoLazyListForObjeto<Evento> getList() {
  410. return list;
  411. }
  412.  
  413. public void setList(CarregamentoLazyListForObjeto<Evento> list) {
  414. this.list = list;
  415. }
  416.  
  417. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement