Package com.krminc.phr.dao

Examples of com.krminc.phr.dao.PersistenceService


            @QueryParam("max") @DefaultValue("10") int max,
            @QueryParam("source") @DefaultValue("self") String source,
            @QueryParam("orderBy") @DefaultValue("dateadded") String orderBy,
            @QueryParam("desc") @DefaultValue("1") int desc)
    {
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            persistenceSvc.beginTx();
            return new HeartRatesConverter(
                    getEntities(start, max, source, orderBy, desc),
                    uriInfo.getAbsolutePath(),
                    Api.DEFAULT_EXPAND_LEVEL
            );
        } finally {
            persistenceSvc.commitTx();
            persistenceSvc.close();
        }
    }
View Full Code Here


        }
        catch(NullPointerException ex) {
            throw new WebApplicationException(Response.Status.FORBIDDEN);
        }
       
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            if (data.hasError) {
                throw new WebApplicationException(Response.Status.PRECONDITION_FAILED);
            }

            persistenceSvc.beginTx();
            EntityManager em = persistenceSvc.getEntityManager();
            HeartRate entity = data.resolveEntity(em);
            createEntity(data.resolveEntity(em));
            persistenceSvc.commitTx();
            return Response.created(uriInfo.getAbsolutePath().resolve(entity.getHeartRateId() + "/")).build();
        } finally {
            persistenceSvc.close();
        }
    }
View Full Code Here

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

    @Path("image/")
    @GET
    @Produces("image/jpeg")
    public Response getImage() {
        PersistenceService persistenceSvc = PersistenceService.getInstance();
        byte[] image = null;
        final String staticDirectory = "./static/images/avatars/";
        final String maleAvatar = "default_avatar_male_126x126.jpg";
        final String femaleAvatar = "default_avatar_female_126x126.jpg";
        User user = null;
        HealthRecord hr = null;

       //logger.error("Attempting to serve user image!");

        try {
            persistenceSvc.beginTx();
            hr = getEntity();
            user = hr.getUser();
            image = user.getUserImage();
        } finally {
            persistenceSvc.close();
        }

        if (image != null && image.length > 0) {
            return Response.ok(image, "image/jpeg").build();
        } else {
View Full Code Here

    public JSONObject getPatientInfo() {

        HealthRecord hr = null;
        JSONObject jSONObject = new JSONObject();

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            persistenceSvc.beginTx();
            hr = getEntity();
            jSONObject.put("name", hr.getUser().getFullName());
            jSONObject.put("gender", hr.getFullGender());
            jSONObject.put("age", hr.getAge());
        } catch (JSONException ex) {
View Full Code Here

        HealthRecord hr = null;
        User usr = null;
        Address adrs = null;
        JSONObject jSONObject = new JSONObject();

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            persistenceSvc.beginTx();
            hr = getEntity();
            usr =  hr.getUser();
            adrs = usr.getAddresses().get(0);
            jSONObject.put("firstName",usr.getFirstName());
            jSONObject.put("middleName", usr.getMiddleName());
View Full Code Here

        HealthRecord hr = null;
        User usr = null;
        JSONObject jSONObject = new JSONObject();

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            persistenceSvc.beginTx();
            hr = getEntity();
            usr =  hr.getUser();
            //username, last login, number of logins, preferred name, date account created, and email address
            jSONObject.put("username",usr.getUsername());
            jSONObject.put("lastLogin", usr.getLastLogin());
View Full Code Here

    public JSONObject getPreferences() {

        HealthRecord hr = null;
        JSONObject jSONObject = new JSONObject();

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            persistenceSvc.beginTx();
            hr = getEntity();
            UserPreferences pref = hr.getPreferences();
            String careNotebookString = "";
            if (pref != null) {
                careNotebookString = pref.getShowCarenotebookString();
View Full Code Here

    public JSONObject getUsersWithAccess() {

        HealthRecord hr = null;
        JSONObject jSONObject = new JSONObject();

        PersistenceService persistenceSvc = PersistenceService.getInstance();
        try {
            persistenceSvc.beginTx();
            hr = getEntity();
            List<String> names = new ArrayList<String>();
            List<String> emails = new ArrayList<String>();
            List<String> phones = new ArrayList<String>();
            List<String> faxes = new ArrayList<String>();
View Full Code Here

        Boolean returnType = false;

        if (healthRecordIdToRemove != null)
        {

            PersistenceService persistenceSvc = PersistenceService.getInstance();

            try {
                if (! securityContext.isUserInRole(UserConfig.ROLE_PATIENT)) throw new Exception("Not in patient role for removing access");
               
                EntityManager em = PersistenceService.getInstance().getEntityManager();
                User userToDisallow = null;
                User removingUser = null;

                try {
                    persistenceSvc.beginTx();

                    //get user
                     userToDisallow = getUserById(userId);
                     removingUser = getAuthenticatedUser();

                     //TODO check we are owner of HR
                     //if HR owner == removingUser

                     //find the correct hr
                     List<HealthRecord> healthRecords = userToDisallow.getHealthRecords();
                     boolean shouldRemove = false;
                     HealthRecord toRemove = null;

                    //make sure we aren't removing ourself
                    if (removingUser.getUserId().compareTo(userId) == 0) {
                        shouldRemove = false;
                        logger.debug("Preventing self-removal attempt id1 {} id2 {}", userToDisallow.getUserId(), userId);
                    } else {
                        for (HealthRecord hr : healthRecords) {
                            //prepare to remove link
                            if (healthRecordIdToRemove.compareTo(hr.getHealthRecordId()) == 0) {
                                toRemove = hr;
                                logger.debug("Ready to remove healthRecord {} from user {}", hr, userToDisallow);
                                shouldRemove = true;
                            }
                        }

                        if ( toRemove == null) {
                            logger.error("Unable to find matching hr to remove");
                        }
                    }

                     if (shouldRemove) {
                        healthRecords.remove(toRemove);
                        userToDisallow.setHealthRecords(healthRecords);
                        em.flush();
                        persistenceSvc.commitTx();
                        returnType = true;
                     } else {
                         returnType = false;
                         persistenceSvc.rollbackTx();
                     }
                }
                catch (NoResultException ex) {
                    logger.error("Unable to find remove access for HRID: {}", healthRecordIdToRemove);
                    returnType = false;
                }

            }
            catch (Exception ex) {
                logger.error("removeAccess encountered exception: {}", ex);
                returnType = false;
            } finally {
                persistenceSvc.close();
            }
        } else {
            returnType = false;
        }
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.