首页 > 程序开发 > web前端 > HTML/CSS >

医生信息控制器开发

2017-03-18

医生信息控制器开发。

医生信息控制器开发

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.ddoc.backend.admin.controllers.doctors;

import com.csig.entities.standards.CountryStateCities;
import com.csig.entities.standards.CountryStatesProvinces;
import com.csig.types.exceptions.InvalidInputException;
import com.csig.types.exceptions.InvalidRequestException;
import com.csig.types.exceptions.LoginInvalidException;
import com.ddoc.entities.Appointments;
import com.ddoc.entities.Contact;
import com.ddoc.entities.Doctor;
import com.ddoc.interfaces.services.IAppointmentsService;
import com.ddoc.interfaces.services.accounts.IAccountService;
import com.ddoc.interfaces.services.addresses.IAddressService;
import com.ddoc.interfaces.services.doctors.IDoctorService;
import com.ddoc.types.doctors.AppointmentSearchFilters;
import com.ddoc.types.doctors.DoctorSearchFilters;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import javax.security.auth.login.AccountNotFoundException;
import org.apache.commons.lang3.StringUtils;

/**
*
* @author songlinlin
*/
@Named
@ViewScoped
public class DoctorInfoController implements Serializable {

private static final long serialVersionUID = -5076562333997840033L;

private Integer doctorId;

private Doctor doctorInfo;

@EJB(name = "DoctorEJB")
private IDoctorService doctorService;

@EJB(name = "AppointmentsEJB")
private IAppointmentsService appointmentsService;

@EJB(name = "AccountEJB")
private IAccountService accountService;

private List appointmentList;

@EJB(name = "AddressServiceEJB")
private IAddressService addressService;

private List homeProvinceList;

private List homeCityList;

private List workProvinceList;

private List workCityList;

private Contact modifiedContact;

private String newPassword;

private String[] years = {"2017", "2016", "2015", "2014", "2013", "2012", "2011", "2010", "2009", "2008", "2007", "2006",
    "2005", "2004", "2003", "2002", "2001", "2000", "1999", "1998", "1997", "1996", "1995", "1994", "1993", "1992", "1991", "1990"};

private static final Logger LOG = Logger.getLogger(DoctorInfoController.class.getName());

public void onPreRenderView() {

    loadData();

    loadDoctorInfo();

}

public void loadDoctorInfo() {

    if (doctorId == null) {

        LOG.severe("No DoctorID provided.");

        return;

    }

    if (doctorInfo == null) {

        DoctorSearchFilters filters = new DoctorSearchFilters();

        List doctorIdList = new ArrayList<>();

        doctorIdList.add(doctorId);

        filters.setDoctorIdList(doctorIdList);

        try {

            List doctorList = doctorService.getDoctorInfo(filters, 0, 1);

            if (doctorList != null && !doctorList.isEmpty()) {

                this.doctorInfo = doctorList.get(0);

            }catch (Exception e) {

            final String message = "System error retrieving doctor info.";

            FacesMessage fmsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message);

            FacesContext.getCurrentInstance().addMessage(null, fmsg);

      }
   }
}

public void updateContact() {
    try {

        accountService.updateContact(&#39;D&#39;, doctorId, doctorInfo.getContactId());

        loadDoctorInfo();

        final String message = "Doctor contact data saved.";

        FacesMessage fmsg = new FacesMessage(FacesMessage.SEVERITY_INFO, message, message);

        FacesContext.getCurrentInstance().addMessage(null, fmsg);

    } catch (InvalidInputException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

        final String message = "Invalid input while saving Doctor contact data.";

        FacesMessage fmsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message);

        FacesContext.getCurrentInstance().addMessage(null, fmsg);

    } catch (InvalidRequestException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

        final String message = "Invalid request while saving Doctor contact data.";

        FacesMessage fmsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message);

        FacesContext.getCurrentInstance().addMessage(null, fmsg);

    }

}

public void doctorUpdatePassword() {
    try {

        accountService.doctorUpdatePassword(doctorInfo.getAccountName(), newPassword, doctorInfo.getPassword(), false);

        loadDoctorInfo();

        final String message = "Doctor Password data saved.";

        FacesMessage fmsg = new FacesMessage(FacesMessage.SEVERITY_INFO, message, message);

        FacesContext.getCurrentInstance().addMessage(null, fmsg);

    } catch (InvalidInputException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

        final String message = "Invalid input while saving Doctor Password data.";

        FacesMessage fmsg = new FacesMessage(FacesMessage.SEVERITY_ERROR, message, message);

        FacesContext.getCurrentInstance().addMessage(null, fmsg);

    } catch (AccountNotFoundException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

    } catch (LoginInvalidException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

    } catch (Exception ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

    }

}

public void updateAccount() {

    try {

        accountService.updateDoctor(doctorInfo);

        loadDoctorInfo();

        final String message = "Doctor Account data saved.";

        FacesMessage fmsg = new FacesMessage(FacesMessage.SEVERITY_INFO, message, message);

        FacesContext.getCurrentInstance().addMessage(null, fmsg);

    } catch (InvalidInputException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

    } catch (InvalidRequestException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

    } catch (AccountNotFoundException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

    }

}

public void loadData() {

    AppointmentSearchFilters filter = new AppointmentSearchFilters();

    filter.setDoctorId(doctorId);

    Calendar calStart = Calendar.getInstance();

    calStart.set(Calendar.HOUR, 0);

    calStart.set(Calendar.MINUTE, 0);

    calStart.set(Calendar.SECOND, 0);

    calStart.set(Calendar.MILLISECOND, 0);

    calStart.set(Calendar.MINUTE, 0);

    filter.setStartTimeFrom(calStart.getTime());

    Calendar calTo = Calendar.getInstance();

    calTo.set(Calendar.DAY_OF_YEAR, calStart.get(Calendar.DAY_OF_YEAR));

    calTo.add(Calendar.DAY_OF_MONTH, 30);

    calTo.set(Calendar.HOUR, 0);

    calTo.set(Calendar.MINUTE, 0);

    calTo.set(Calendar.SECOND, 0);

    calTo.set(Calendar.MILLISECOND, 0);

    filter.setStartTimeTo(calTo.getTime());

    System.out.println("doctorId=" + doctorId);

    try {

        appointmentList = appointmentsService.getAppointments(filter, true, true, 0, 100);

        System.out.println("appointmentList=" + appointmentList.size());

    } catch (InvalidRequestException ex) {

        Logger.getLogger(DoctorInfoController.class.getName()).log(Level.SEVERE, null, ex);

    }

}

public Integer getDoctorId() {
    return doctorId;
}

public void setDoctorId(Integer doctorId) {
    this.doctorId = doctorId;
}

public Doctor getDoctorInfo() {
    return doctorInfo;
}

public void setDoctorInfo(Doctor doctorInfo) {
    this.doctorInfo = doctorInfo;
}

public List getAppointmentList() {
    return appointmentList;
}

public void setAppointmentList(List appointmentList) {
    this.appointmentList = appointmentList;
}

public Contact getModifiedContact() {
    return modifiedContact;
}

public void setModifiedContact(Contact modifiedContact) {
    this.modifiedContact = modifiedContact;
}

public String getNewPassword() {
    return newPassword;
}

public void setNewPassword(String newPassword) {
    this.newPassword = newPassword;
}

public String[] getYears() {
    return years;
}

public void setYears(String[] years) {
    this.years = years;
}

}

相关文章
最新文章
热点推荐