Package com.krminc.phr.dao

Examples of com.krminc.phr.dao.PersistenceService


        List<HealthrecordRequest> requests = new ArrayList<HealthrecordRequest>();
        boolean foundRequests = false;
        List<String> requestingUsers = new ArrayList<String>();
        List<Integer> requestIds = new ArrayList<Integer>();

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            EntityManager em = PersistenceService.getInstance().getEntityManager();

            persistenceSvc.beginTx();
            Long healthRecordId = getEntity().getHealthRecordId();
            try {
                requests = em.createNamedQuery("HealthrecordRequest.findByRecIdRequested")
                    .setParameter("recIdRequested", healthRecordId)
                    .getResultList();

                if (!requests.isEmpty()) foundRequests = true;
            }
            catch (NoResultException ex) {
                foundRequests = false;
                logger.error("No requests found for HealthrecordRequest.findByRecIdRequested: {}", ex);
            }

            if (foundRequests) {
                for (HealthrecordRequest request : requests) {
                    try {
                        User u = (User) em.createNamedQuery("User.findByUserId")
                            .setParameter("userId", request.getUserIdRequestor())
                            .setMaxResults(1)
                            .getSingleResult();

                        if (u != null) {
                            requestingUsers.add(u.getFullName());
                            requestIds.add(request.getRequestId());
                        }
                    }
                    catch (NoResultException ex) {
                        logger.error("Unable to find a user who requested hrid access");
                    }
                }
            }

        }
        catch (Exception ex) {
            foundRequests = false;
        } finally {
            persistenceSvc.close();
        }

        try {
            jSONObject.put("requests", foundRequests);
View Full Code Here


            ) {
        JSONObject jSONObject = new JSONObject();

        //Add the link to hr->user linkage table

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        EntityManager em = persistenceSvc.getEntityManager();
        String approvalRequest = new String();

        try {
            if (! securityContext.isUserInRole(UserConfig.ROLE_PATIENT)) throw new Exception("Not in patient role for approval request");
           
            persistenceSvc.beginTx();
            HealthrecordRequest approvedRequest = em.find(HealthrecordRequest.class, requestId);

            //ensure we are linking a request that is of our own record
            if (approvedRequest.getRecIdRequested() == getEntity().getHealthRecordId()) {

                //find the user we are giving access to hr for
                User approvedUser = em.find(
                        User.class,
                        new Long(approvedRequest.getUserIdRequestor())
                    );
               
                //find the hrid we want to give access to
                HealthRecord approvedRecord = em.find(
                        HealthRecord.class,
                        new Long(approvedRequest.getRecIdRequested())
                    );

                //add the healthrecord to user object
                List<HealthRecord> currentRecords = approvedUser.getHealthRecords();
                currentRecords.add(approvedRecord);
                approvedUser.setHealthRecords(currentRecords);

                //delete the request now that it is satisfied
                em.remove(approvedRequest);
            }

            persistenceSvc.commitTx();
            approvalRequest = "success";
        } catch (Exception ex) {
            logger.error("Exception encountered processing approval request: {}", ex);
            approvalRequest = "error";
        } finally {
            persistenceSvc.close();
        }

        try {
            jSONObject.put("status", approvalRequest);
        } catch (JSONException ex) {
View Full Code Here

     * @return an instance of BloodPressureConverter
     */
    @GET
    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
    public BloodPressureConverter get() {
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            persistenceSvc.beginTx();
            return new BloodPressureConverter(getEntity(), uriInfo.getAbsolutePath(), Api.DEFAULT_EXPAND_LEVEL);
        } finally {
            PersistenceService.getInstance().close();
        }
    }
View Full Code Here

        }
        catch(NullPointerException ex) {
            throw new WebApplicationException(Response.Status.FORBIDDEN);
        }
       
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            //check updateable
            if (getEntity().getDataSourceId() != 1) {
                throw new WebApplicationException(Response.Status.FORBIDDEN);
            }

            if (data.hasError) {
                throw new WebApplicationException(Response.Status.PRECONDITION_FAILED);
            }

            persistenceSvc.beginTx();
            EntityManager em = persistenceSvc.getEntityManager();

            updateEntity(getEntity(), data.resolveEntity(em));
            persistenceSvc.commitTx();
        } finally {
            persistenceSvc.close();
        }
    }
View Full Code Here

    public JSONObject denyRequest(
            @PathParam("requestId") Integer requestId
            ) {
       
        JSONObject jSONObject = new JSONObject();
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        EntityManager em = persistenceSvc.getEntityManager();
        String denyRequest = new String();

        try {
            if (! securityContext.isUserInRole(UserConfig.ROLE_PATIENT)) throw new Exception("Not in patient role for denial request");
           
            persistenceSvc.beginTx();
            HealthrecordRequest toDelete = em.find(HealthrecordRequest.class, requestId);

            //ensure we are deleting a request that is of our own record
            if (toDelete.getRecIdRequested() == getEntity().getHealthRecordId()) {
                em.remove(toDelete);
            }

            persistenceSvc.commitTx();
            denyRequest = "success";
        } catch (Exception ex) {
            logger.error("Exception encountered processing approval request: {}", ex);
            denyRequest = "error";
        } finally {
            persistenceSvc.close();
        }

        try {
            jSONObject.put("status", denyRequest);
        } catch (JSONException ex) {
View Full Code Here

  }
  catch(NullPointerException ex) {
    throw new WebApplicationException(Response.Status.FORBIDDEN);
  }

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            //check updateable
            if (getEntity().getDataSourceId() != 1) {
                throw new WebApplicationException(Response.Status.FORBIDDEN);
            }
           
            persistenceSvc.beginTx();
            deleteEntity(getEntity());
            persistenceSvc.commitTx();
        } finally {
            persistenceSvc.close();
        }
    }
View Full Code Here

    @GET
    @Produces({ MediaType.APPLICATION_JSON })
    public JSONObject getPatientStats() {
        JSONObject jSONObject = new JSONObject();

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        Weight latestWeight = null;
        Height latestHeight = null;
        Boolean calculateBMI = true;
        try {
            EntityManager em = PersistenceService.getInstance().getEntityManager();

            persistenceSvc.beginTx();
            Long healthRecordId = getEntity().getHealthRecordId();
            try {
                latestHeight = (Height)em.createNamedQuery("Height.getLatestByHealthRecordId")
                    .setParameter("healthRecordId", healthRecordId)
                    .setMaxResults(1)
View Full Code Here

    /**
     * @return a User.
     */
    private User getUserById(Long userId) {
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        EntityManager em = persistenceSvc.getEntityManager();
        try {
            // persistenceSvc.beginTx(); -- Transaction already exists in *some* callers.
            return (User) em.createNamedQuery("User.findByUserId")
                .setParameter("userId", userId)
                .getSingleResult();
View Full Code Here

    /**
     * @return a User.
     */
    private User getAuthenticatedUser() {
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        EntityManager em = persistenceSvc.getEntityManager();
        try {
            // persistenceSvc.beginTx(); -- Transaction already exists in *some* callers.
            return (User) em.createNamedQuery("User.findByUsername")
                .setParameter("username", securityContext.getUserPrincipal().getName())
                .getSingleResult();
View Full Code Here

     * @return an instance of PainConverter
     */
    @GET
    @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
    public PainConverter get() {
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            persistenceSvc.beginTx();
            return new PainConverter(getEntity(), uriInfo.getAbsolutePath(), Api.DEFAULT_EXPAND_LEVEL);
        } finally {
            PersistenceService.getInstance().close();
        }
    }
View Full Code Here

TOP

Related Classes of com.krminc.phr.dao.PersistenceService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.