Red Hat Application Migration Toolkit
package com.mpdmal.cloudental.beans;
import com.mpdmal.cloudental.beans.base.AbstractEaoService;
import com.mpdmal.cloudental.entities.Activity;
import com.mpdmal.cloudental.entities.Dentist;
import com.mpdmal.cloudental.entities.Discount;
import com.mpdmal.cloudental.entities.Medicalhistory;
import com.mpdmal.cloudental.entities.Patient;
import com.mpdmal.cloudental.entities.Patienthistory;
import com.mpdmal.cloudental.entities.Prescription;
import com.mpdmal.cloudental.entities.PricelistItem;
import com.mpdmal.cloudental.entities.UserPreferences;
import com.mpdmal.cloudental.util.CloudentUtils;
import com.mpdmal.cloudental.util.exception.DentistNotFoundException;
import com.mpdmal.cloudental.util.exception.DiscountNotFoundException;
import com.mpdmal.cloudental.util.exception.InvalidPostitAlertException;
import com.mpdmal.cloudental.util.exception.PatientExistsException;
import com.mpdmal.cloudental.util.exception.PatientNotFoundException;
import com.mpdmal.cloudental.util.exception.PricelistItemNotFoundException;
import com.mpdmal.cloudental.util.exception.ValidationException;
import com.mpdmal.cloudental.util.exception.base.CloudentException;
import java.io.FileNotFoundException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.Vector;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.inject.Named;
import javax.jws.WebService;
import javax.mail.MessagingException;
import javax.persistence.Query;
import net.sf.jasperreports.engine.JRException;
@Named
@Stateless
@LocalBean
@WebService
public class DentistServices extends AbstractEaoService {
private static final long serialVersionUID = 1L;
public Prescription createPrescription(int dentistid, int patientid, ArrayList rows) throws DentistNotFoundException, PatientNotFoundException, ValidationException {
Dentist dentist = this.findDentist(dentistid);
Patient patient = this.findPatient(patientid);
Prescription p = new Prescription();
p.setDentist(dentist);
p.setPatienthistory(patient.getDentalHistory());
p.setCreated(new Timestamp(System.currentTimeMillis()));
p.setPrescriptionrows(rows);
this.emgr.persist(p);
return p;
}
public Collection getMedicineList() {
Query q = this.emgr.getEM().createQuery("select m from Medicine m");
return (Collection)this.emgr.executeMultipleObjectQuery(q);
}
public UserPreferences getUserPrefs(int userid) throws CloudentException {
UserPreferences item = (UserPreferences)this.emgr.findOrFail(UserPreferences.class, Integer.valueOf(userid));
if(item == null) {
throw new CloudentException("Cannot get Prefs, userid: " + userid);
} else {
return item;
}
}
public void savePrefs(UserPreferences prefs) {
this.emgr.update(prefs);
}
public void sendOnDemandReport(int userid, String email, int type) throws FileNotFoundException, JRException, MessagingException {
String reportname = CloudentUtils.printPatientReport(userid);
CloudentUtils.mailReport(reportname, email);
}
public Discount createDiscount(int dentistid, String title, String description, double value) throws DentistNotFoundException, ValidationException {
Dentist dentist = this.findDentist(dentistid);
Discount d = new Discount();
if(description == null) {
d.setDescription("");
} else {
d.setDescription(description);
}
d.setTitle(title);
d.setDiscount(BigDecimal.valueOf(value));
d.setDentist(dentist);
dentist.addDiscount(d);
this.emgr.persist(d);
return d;
}
public long countDiscounts() {
Query q = this.emgr.getEM().createQuery("select count(d) from Discount d");
return this.emgr.executeSingleLongQuery(q);
}
public long countDentistDiscounts(int dentistid) {
Query q = this.emgr.getEM().createQuery("select count(d) from Discount d where d.dentist.id =:dentistid").setParameter("dentistid", Integer.valueOf(dentistid));
return this.emgr.executeSingleLongQuery(q);
}
public void updateDiscount(int id, String description, String title) throws DiscountNotFoundException {
Discount d = this.findDiscount(id);
d.setDescription(description);
d.setTitle(title);
this.emgr.update(d);
}
public void deleteDiscount(int id) throws DiscountNotFoundException {
Discount d = this.findDiscount(id);
d.getDentist().removeDiscount(d);
this.emgr.delete(d);
}
public Collection getDiscounts(int dentistid) {
Query q = this.emgr.getEM().createQuery("select d from Discount d where d.dentist.id =:dentistid").setParameter("dentistid", Integer.valueOf(dentistid));
return (Collection)this.emgr.executeMultipleObjectQuery(q);
}
public void deleteDiscounts(int dentistid) throws DentistNotFoundException {
Dentist d = this.findDentist(dentistid);
Iterator var3 = d.getDiscounts().iterator();
while(var3.hasNext()) {
Discount discount = (Discount)var3.next();
this.emgr.delete(discount);
}
}
public PricelistItem createPricelistItem(int dentistid, String title, String description, double value) throws InvalidPostitAlertException, DentistNotFoundException, ValidationException {
Dentist dentist = this.findDentist(dentistid);
PricelistItem item = new PricelistItem();
if(description == null) {
item.setDescription("");
} else {
item.setDescription(description);
}
item.setTitle(title);
item.setPrice(BigDecimal.valueOf(value));
item.setDentist(dentist);
dentist.addPricelistItem(item);
this.emgr.persist(item);
return item;
}
public long countPricelistItems() {
Query q = this.emgr.getEM().createQuery("select count(pi) from PricelistItem pi");
return this.emgr.executeSingleLongQuery(q);
}
public long countDentistPricelistItems(int dentistid) {
Query q = this.emgr.getEM().createQuery("select count(pi) from PricelistItem pi where pi.dentist.id =:dentistid").setParameter("dentistid", Integer.valueOf(dentistid));
return this.emgr.executeSingleLongQuery(q);
}
public void updatePricelistItem(int id, String description, String title) throws PricelistItemNotFoundException {
PricelistItem item = this.findPricable(id);
item.setDescription(description);
item.setTitle(title);
this.emgr.update(item);
}
public Collection getPricelist(int dentistid) {
Query q = this.emgr.getEM().createQuery("select pi from PricelistItem pi where pi.dentist.id =:dentistid").setParameter("dentistid", Integer.valueOf(dentistid));
return (Collection)this.emgr.executeMultipleObjectQuery(q);
}
public void deletePricelistItem(int id) throws PricelistItemNotFoundException {
PricelistItem item = this.findPricable(id);
item.getDentist().removePricelistItem(item);
this.emgr.delete(item);
}
public void deletePricelist(int dentistid) throws DentistNotFoundException {
Dentist d = this.findDentist(dentistid);
Iterator var3 = d.getPriceList().iterator();
while(var3.hasNext()) {
PricelistItem item = (PricelistItem)var3.next();
this.emgr.delete(item);
}
}
public Patient createPatient(int dentistid, String name, String surname) throws DentistNotFoundException, PatientExistsException, ValidationException, DiscountNotFoundException, PricelistItemNotFoundException {
Dentist dentist = this.findDentist(dentistid);
long created = (new Date()).getTime();
Patient p = new Patient();
p.setCreated(new Date(created));
p.setName(name);
p.setSurname(surname);
Medicalhistory medhistory = new Medicalhistory();
medhistory.setComments("Auto Generated");
medhistory.setPatient(p);
Activity ac = new Activity();
ac.setDescription("def act| cdent");
ac.setDiscount(this.findDiscount(-1));
ac.setEnddate((Date)null);
ac.setOpen(true);
ac.setPrice(BigDecimal.ZERO);
ac.setPriceable(this.findPricable(-1));
ac.setStartdate(new Date());
Patienthistory dentalhistory = new Patienthistory();
dentalhistory.setComments("auto generated");
dentalhistory.setStartdate(new Date());
dentalhistory.setPatient(p);
dentalhistory.addActivity(ac);
p.setDentist(dentist);
p.setMedicalhistory(medhistory);
p.setDentalhistory(dentalhistory);
dentist.addPatient(p);
this.emgr.persist(p);
return p;
}
public long countPatients() {
Query q = this.emgr.getEM().createQuery("select count(p) from Patient p");
return this.emgr.executeSingleLongQuery(q);
}
public long countDentistPatients(int dentistid) {
Query q = this.emgr.getEM().createQuery("select count(p) from Patient p where p.dentist.id =:dentistid").setParameter("dentistid", Integer.valueOf(dentistid));
return this.emgr.executeSingleLongQuery(q);
}
public void updatePatient(int id, String name, String surname, String comments) throws PatientNotFoundException {
Patient p = this.findPatient(id);
p.setSurname(surname);
p.setName(name);
p.setComments(comments);
this.emgr.update(p);
}
public Collection getPatientlist(int dentistid) {
Query q = this.emgr.getEM().createQuery("select p from Patient p where p.dentist.id =:dentistid").setParameter("dentistid", Integer.valueOf(dentistid));
return (Collection)this.emgr.executeMultipleObjectQuery(q);
}
public void deletePatient(int patientid) throws PatientNotFoundException {
System.out.println("@@");
Patient p = this.findPatient(patientid);
p.getDentist().removePatient(p);
this.emgr.delete(p);
}
public void deletePatientList(int dentistid) throws DentistNotFoundException, PatientNotFoundException {
Dentist dentist = this.findDentist(dentistid);
Vector ptns = (Vector)dentist.getPatientList();
while(ptns.size() > 0) {
this.deletePatient(((Patient)ptns.elementAt(0)).getId().intValue());
}
}
public Vector getDentistVisits(int dentistid) {
Query q = this.emgr.getEM().createQuery("select v from Visit v where v.activity.patienthistory.patient.dentist.id =:dentistid").setParameter("dentistid", Integer.valueOf(dentistid));
return (Vector)this.emgr.executeMultipleObjectQuery(q);
}
}