Information

0
Story Points

Technologies

CDI CDI Decompiled Java File
package com.mpdmal.cloudental.beans;

import com.mpdmal.cloudental.beans.base.AbstractEaoService;
import com.mpdmal.cloudental.entities.Activity;
import com.mpdmal.cloudental.entities.Address;
import com.mpdmal.cloudental.entities.Contactinfo;
import com.mpdmal.cloudental.entities.Discount;
import com.mpdmal.cloudental.entities.Medicalhistory;
import com.mpdmal.cloudental.entities.Medicalhistoryentry;
import com.mpdmal.cloudental.entities.MedicalhistoryentryPK;
import com.mpdmal.cloudental.entities.Patient;
import com.mpdmal.cloudental.entities.Patienthistory;
import com.mpdmal.cloudental.entities.PricelistItem;
import com.mpdmal.cloudental.entities.Visit;
import com.mpdmal.cloudental.util.CloudentUtils;
import com.mpdmal.cloudental.util.exception.ActivityNotFoundException;
import com.mpdmal.cloudental.util.exception.DiscountNotFoundException;
import com.mpdmal.cloudental.util.exception.InvalidMedEntryAlertException;
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.VisitNotFoundException;
import com.mpdmal.cloudental.util.exception.base.CloudentException;
import java.math.BigDecimal;
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.persistence.Query;

@Named
@Stateless
@LocalBean
@WebService
public class PatientServices extends AbstractEaoService {
   private static final long serialVersionUID = 1L;

   public Activity createActivity(int patientid, String description, Date start, Date end, int plitemid, int discountid, BigDecimal price) throws CloudentException {
      Patient p = this.findPatient(patientid);
      Discount d = this.findDiscount(discountid);
      PricelistItem plitem = this.findPricable(plitemid);
      Patienthistory ph = p.getDentalHistory();
      Activity ac = new Activity();
      ac.setDescription(description);
      ac.setStartdate(start);
      ac.setOpen(end == null);
      ac.setEnddate(end);
      ac.setPriceable(plitem);
      ac.setDiscount(d);
      ac.setPatienthistory(ph);
      ac.setPrice(price);
      ph.addActivity(ac);
      this.emgr.persist(ac);
      return ac;
   }

   public long countActivities() {
      Query q = this.emgr.getEM().createQuery("select count(ac) from Activity ac");
      return this.emgr.executeSingleLongQuery(q);
   }

   public long countPatientActivities(int patientid) {
      Query q = this.emgr.getEM().createQuery("select count(ac) from Activity ac where ac.patienthistory.patient.id =:patientid").setParameter("patientid", Integer.valueOf(patientid));
      return this.emgr.executeSingleLongQuery(q);
   }

   public void deleteActivity(int activityid) throws ActivityNotFoundException {
      Activity act = this.findActivity(activityid);
      act.getPatienthistory().removeActivity(act);
      this.emgr.delete(act);
   }

   public void deletePatientActivities(int patientid) throws PatientNotFoundException, ActivityNotFoundException {
      Patient p = this.findPatient(patientid);
      Vector acts = (Vector)p.getDentalHistory().getActivities();

      while(acts.size() > 0) {
         this.deleteActivity(((Activity)acts.elementAt(0)).getId().intValue());
      }

   }

   public void updateActivity(Activity act) throws ActivityNotFoundException, DiscountNotFoundException, PricelistItemNotFoundException {
      this.findDiscount(act.getDiscount().getId().intValue());
      this.findPricable(act.getPriceable().getId().intValue());
      if(act.getEnddate() != null && act.getEnddate().getTime() <= act.getStartdate().getTime()) {
         CloudentUtils.logWarning("Activity enddate cannot precede start date, wont update:" + act.getId());
      } else {
         Activity ac = this.findActivity(act.getId().intValue());
         ac.setDiscount(act.getDiscount());
         ac.setDescription(act.getDescription());
         ac.setOpen(act.isOpen());
         ac.setPrice(act.getPrice());
         ac.setPriceable(act.getPriceable());
         this.emgr.update(ac);
      }
   }

   public Vector getPatientActivities(int patientid) throws PatientNotFoundException {
      Patient p = this.findPatient(patientid);
      Query q = this.emgr.getEM().createQuery("select ac from Activity ac where ac.patienthistory.patient.id =:patientid").setParameter("patientid", p.getId());
      return (Vector)this.emgr.executeMultipleObjectQuery(q);
   }

   public Medicalhistoryentry createMedicalEntry(int patientID, String comment, int alert) throws PatientNotFoundException, InvalidMedEntryAlertException {
      Patient p = this.findPatient(patientID);
      Medicalhistory hstr = p.getMedicalhistory();
      MedicalhistoryentryPK id = new MedicalhistoryentryPK();
      id.setAdded(new Date());
      id.setId(hstr.getId());
      Medicalhistoryentry entry = new Medicalhistoryentry();
      entry.setAlert(Integer.valueOf(alert));
      entry.setComments(comment);
      entry.setId(id);
      hstr.addMedicalEntry(entry);
      this.emgr.update(hstr);
      return entry;
   }

   public void deleteMedicalEntry(Medicalhistoryentry entry) throws PatientNotFoundException {
      Patient p = this.findPatient(entry.getId().getId().intValue());
      p.getMedicalhistory().deleteMedicalEntry(entry);
      this.emgr.delete(entry);
   }

   public Contactinfo createContactinfo(Contactinfo info) throws CloudentException {
      Patient p = this.findPatient(info.getId().getId().intValue());
      p.addContactInfo(info);
      this.emgr.update(p);
      return info;
   }

   public Address createAddress(Address adr) throws CloudentException {
      Patient p = this.findPatient(adr.getId().getId().intValue());
      p.addAddress(adr);
      this.emgr.update(p);
      return adr;
   }

   public Visit createVisit(int activityID, String comments, String title, Date start, Date end, double deposit, int color) throws CloudentException {
      Activity act = this.findActivity(activityID);

      try {
         this.validateVisit(act, start, end);
      } catch (ValidationException var11) {
         throw var11;
      }

      Visit v = new Visit();
      v.setComments(comments);
      v.setVisitdate(start);
      v.setEnddate(end);
      v.setColor(Integer.valueOf(color));
      v.setTitle(title);
      v.setDeposit(BigDecimal.valueOf(deposit));
      v.setActivity(act);
      act.addVisit(v);
      this.emgr.persist(v);
      return v;
   }

   public Vector getActivityVisits(int activityid) throws ActivityNotFoundException {
      Query q = this.emgr.getEM().createQuery("select v from Visit v where v.activity.id =:activityid").setParameter("activityid", Integer.valueOf(activityid));
      return (Vector)this.emgr.executeMultipleObjectQuery(q);
   }

   public Vector getPatientVisits(int patientid) throws ActivityNotFoundException {
      Query q = this.emgr.getEM().createQuery("select v from Visit v where v.activity.patienthistory.patient.id =:patientid").setParameter("patientid", Integer.valueOf(patientid));
      return (Vector)this.emgr.executeMultipleObjectQuery(q);
   }

   public long countVisits() {
      Query q = this.emgr.getEM().createQuery("select count(v) from Visit v");
      return this.emgr.executeSingleLongQuery(q);
   }

   public long countActivityVisits(int activityid) throws ActivityNotFoundException {
      Query q = this.emgr.getEM().createQuery("select count(v) from Visit v where v.activity.id =:activityid").setParameter("activityid", Integer.valueOf(activityid));
      return this.emgr.executeSingleLongQuery(q);
   }

   public long countPatientVisits(int patientid) {
      Query q = this.emgr.getEM().createQuery("select count(v) from Visit v where v.activity.patienthistory.patient.id =:patientid").setParameter("patientid", Integer.valueOf(patientid));
      return this.emgr.executeSingleLongQuery(q);
   }

   public void deleteVisit(int visitid) throws VisitNotFoundException {
      Visit v = this.findVisit(visitid);
      v.getActivity().removeVisit(v);
      this.emgr.delete(v);
   }

   public void deleteActivityVisits(int activityid) throws PatientNotFoundException, VisitNotFoundException, ActivityNotFoundException {
      Activity act = this.findActivity(activityid);
      Vector visits = (Vector)act.getVisits();

      while(visits.size() > 0) {
         this.deleteVisit(((Visit)visits.elementAt(0)).getId().intValue());
      }

   }

   public void deletePatientVisits(int patientid) throws PatientNotFoundException, VisitNotFoundException, ActivityNotFoundException {
      Patient p = this.findPatient(patientid);
      Collection acts = p.getDentalHistory().getActivities();
      Iterator var4 = acts.iterator();

      while(var4.hasNext()) {
         Activity activity = (Activity)var4.next();
         Vector visits = (Vector)activity.getVisits();

         while(visits.size() > 0) {
            this.deleteVisit(((Visit)visits.elementAt(0)).getId().intValue());
         }
      }

   }

   public void updateVisit(Visit v) throws VisitNotFoundException {
      Visit vt = this.findVisit(v.getId().intValue());
      if(v.getEnddate() != null && v.getEnddate().getTime() <= v.getVisitdate().getTime()) {
         CloudentUtils.logWarning("Visit enddate cannot precede start date, wont update:" + v.getId());
      } else {
         vt.setComments(v.getComments());
         vt.setColor(v.getColor());
         vt.setDeposit(v.getDeposit());
         vt.setTitle(v.getTitle());
         this.emgr.update(vt);
      }
   }

   private void validateVisit(Activity act, Date start, Date end) throws ValidationException, ActivityNotFoundException {
      if(start == null) {
         throw new ValidationException("Visit START date cannot be NULL");
      } else {
         long vtstart = start.getTime();
         long vtend = end.getTime();
         if(vtend <= vtstart) {
            throw new ValidationException("Visit END date must come after the START date");
         } else {
            if(act.isOpen()) {
               if(vtstart <= act.getStartdate().getTime()) {
                  throw new ValidationException("Patient doesnt exist at that date");
               }
            } else {
               long invalid = act.getStartdate().getTime();
               long vt = act.getEnddate().getTime();
               if(invalid > vtstart || vt < vtend) {
                  throw new ValidationException("Visit START and END date must be within the respective Activity dates");
               }
            }

            if(act.getVisits().size() > 0) {
               boolean invalid1 = false;
               Iterator var9 = this.getPatientVisits(act.getPatienthistory().getPatient().getId().intValue()).iterator();

               while(var9.hasNext()) {
                  Visit vt1 = (Visit)var9.next();
                  if(vtend >= vt1.getVisitdate().getTime() && vtstart <= vt1.getEnddate().getTime()) {
                     invalid1 = true;
                  }
               }

               if(invalid1) {
                  throw new ValidationException("Visit dates cannot OVERLAP one another");
               }
            }
         }
      }
   }
}
Page generated: Oct 19, 2017 2:35:13 PM