com.tcitest2.poctest.controller.PatientsController.java Source code

Java tutorial

Introduction

Here is the source code for com.tcitest2.poctest.controller.PatientsController.java

Source

/*Copyright (c) 2016-2017 trustedcare.us.com All Rights Reserved.
 This software is the confidential and proprietary information of trustedcare.us.com You shall not disclose such Confidential Information and shall use it only in accordance
 with the terms of the source code license agreement you entered into with trustedcare.us.com*/
package com.tcitest2.poctest.controller;

/*This is a Studio Managed File. DO NOT EDIT THIS FILE. Your changes may be reverted by Studio.*/
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.TypeMismatchException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import com.wavemaker.runtime.data.exception.EntityNotFoundException;
import com.wavemaker.runtime.data.export.ExportType;
import com.wavemaker.runtime.data.expression.QueryFilter;
import com.wavemaker.runtime.file.model.DownloadResponse;
import com.wavemaker.runtime.file.model.Downloadable;
import com.wavemaker.runtime.util.WMMultipartUtils;
import com.wavemaker.runtime.util.WMRuntimeUtils;
import com.wavemaker.tools.api.core.annotations.WMAccessVisibility;
import com.wavemaker.tools.api.core.models.AccessSpecifier;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import com.tcitest2.poctest.FamilyRepresentativesPatients;
import com.tcitest2.poctest.Medications;
import com.tcitest2.poctest.Messages;
import com.tcitest2.poctest.Patients;
import com.tcitest2.poctest.Vitals;
import com.tcitest2.poctest.service.PatientsService;

/**
 * Controller object for domain model class Patients.
 * @see Patients
 */
@RestController("poctest.PatientsController")
@Api(value = "PatientsController", description = "Exposes APIs to work with Patients resource.")
@RequestMapping("/poctest/Patients")
public class PatientsController {

    private static final Logger LOGGER = LoggerFactory.getLogger(PatientsController.class);

    @Autowired
    @Qualifier("poctest.PatientsService")
    private PatientsService patientsService;

    @ApiOperation(value = "Creates a new Patients instance.")
    @RequestMapping(method = RequestMethod.POST)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Patients createPatients(@RequestBody Patients patients) {
        LOGGER.debug("Create Patients with information: {}", patients);
        patients = patientsService.create(patients);
        LOGGER.debug("Created Patients with information: {}", patients);
        return patients;
    }

    @ApiOperation(value = "Creates a new Patients instance.This API should be used when the Patients instance has fields that requires multipart data.")
    @RequestMapping(method = RequestMethod.POST, consumes = { "multipart/form-data" })
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Patients createPatients(MultipartHttpServletRequest multipartHttpServletRequest) {
        Patients patients = WMMultipartUtils.toObject(multipartHttpServletRequest, Patients.class, "poctest");
        LOGGER.debug("Creating a new Patients with information: {}", patients);
        return patientsService.create(patients);
    }

    @ApiOperation(value = "Returns the Patients instance associated with the given id.")
    @RequestMapping(value = "/{id:.+}", method = RequestMethod.GET)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Patients getPatients(@PathVariable("id") Integer id) throws EntityNotFoundException {
        LOGGER.debug("Getting Patients with id: {}", id);
        Patients foundPatients = patientsService.getById(id);
        LOGGER.debug("Patients details with id: {}", foundPatients);
        return foundPatients;
    }

    @ApiOperation(value = "Retrieves content for the given BLOB field in Patients instance")
    @RequestMapping(value = "/{id}/content/{fieldName}", method = RequestMethod.GET, produces = "application/octet-stream")
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public DownloadResponse getPatientsBLOBContent(@PathVariable("id") Integer id,
            @PathVariable("fieldName") String fieldName, HttpServletRequest httpServletRequest,
            HttpServletResponse httpServletResponse,
            @RequestParam(value = "download", defaultValue = "false") boolean download) {
        LOGGER.debug("Retrieves content for the given BLOB field {} in Patients instance", fieldName);
        if (!WMRuntimeUtils.isLob(Patients.class, fieldName)) {
            throw new TypeMismatchException("Given field " + fieldName + " is not a valid BLOB type");
        }
        Patients patients = patientsService.getById(id);
        return WMMultipartUtils.buildDownloadResponseForBlob(patients, fieldName, httpServletRequest, download);
    }

    @ApiOperation(value = "Updates the Patients instance associated with the given id.")
    @RequestMapping(value = "/{id:.+}", method = RequestMethod.PUT)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Patients editPatients(@PathVariable("id") Integer id, @RequestBody Patients patients)
            throws EntityNotFoundException {
        LOGGER.debug("Editing Patients with id: {}", patients.getId());
        patients.setId(id);
        patients = patientsService.update(patients);
        LOGGER.debug("Patients details with id: {}", patients);
        return patients;
    }

    @ApiOperation(value = "Updates the Patients instance associated with the given id.This API should be used when Patients instance fields that require multipart data.")
    @RequestMapping(value = "/{id:.+}", method = RequestMethod.POST, consumes = { "multipart/form-data" })
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Patients editPatients(@PathVariable("id") Integer id,
            MultipartHttpServletRequest multipartHttpServletRequest) throws EntityNotFoundException {
        Patients newPatients = WMMultipartUtils.toObject(multipartHttpServletRequest, Patients.class, "poctest");
        newPatients.setId(id);
        Patients oldPatients = patientsService.getById(id);
        WMMultipartUtils.updateLobsContent(oldPatients, newPatients);
        LOGGER.debug("Updating Patients with information: {}", newPatients);
        return patientsService.update(newPatients);
    }

    @ApiOperation(value = "Deletes the Patients instance associated with the given id.")
    @RequestMapping(value = "/{id:.+}", method = RequestMethod.DELETE)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public boolean deletePatients(@PathVariable("id") Integer id) throws EntityNotFoundException {
        LOGGER.debug("Deleting Patients with id: {}", id);
        Patients deletedPatients = patientsService.delete(id);
        return deletedPatients != null;
    }

    /**
     * @deprecated Use {@link #findPatients(String, Pageable)} instead.
     */
    @Deprecated
    @ApiOperation(value = "Returns the list of Patients instances matching the search criteria.")
    @RequestMapping(value = "/search", method = RequestMethod.POST)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Page<Patients> searchPatientsByQueryFilters(Pageable pageable, @RequestBody QueryFilter[] queryFilters) {
        LOGGER.debug("Rendering Patients list");
        return patientsService.findAll(queryFilters, pageable);
    }

    @ApiOperation(value = "Returns the list of Patients instances matching the search criteria.")
    @RequestMapping(method = RequestMethod.GET)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Page<Patients> findPatients(
            @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query,
            Pageable pageable) {
        LOGGER.debug("Rendering Patients list");
        return patientsService.findAll(query, pageable);
    }

    @ApiOperation(value = "Returns downloadable file for the data.")
    @RequestMapping(value = "/export/{exportType}", method = RequestMethod.GET, produces = "application/octet-stream")
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Downloadable exportPatients(@PathVariable("exportType") ExportType exportType,
            @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query,
            Pageable pageable) {
        return patientsService.export(exportType, query, pageable);
    }

    @ApiOperation(value = "Returns the total count of Patients instances.")
    @RequestMapping(value = "/count", method = RequestMethod.GET)
    @WMAccessVisibility(value = AccessSpecifier.APP_ONLY)
    public Long countPatients(
            @ApiParam("conditions to filter the results") @RequestParam(value = "q", required = false) String query) {
        LOGGER.debug("counting Patients");
        return patientsService.count(query);
    }

    @RequestMapping(value = "/{id:.+}/familyRepresentativesPatientses", method = RequestMethod.GET)
    @ApiOperation(value = "Gets the familyRepresentativesPatientses instance associated with the given id.")
    public Page<FamilyRepresentativesPatients> findAssociatedFamilyRepresentativesPatientses(
            @PathVariable("id") Integer id, Pageable pageable) {
        LOGGER.debug("Fetching all associated familyRepresentativesPatientses");
        return patientsService.findAssociatedFamilyRepresentativesPatientses(id, pageable);
    }

    @RequestMapping(value = "/{id:.+}/medicationses", method = RequestMethod.GET)
    @ApiOperation(value = "Gets the medicationses instance associated with the given id.")
    public Page<Medications> findAssociatedMedicationses(@PathVariable("id") Integer id, Pageable pageable) {
        LOGGER.debug("Fetching all associated medicationses");
        return patientsService.findAssociatedMedicationses(id, pageable);
    }

    @RequestMapping(value = "/{id:.+}/messageses", method = RequestMethod.GET)
    @ApiOperation(value = "Gets the messageses instance associated with the given id.")
    public Page<Messages> findAssociatedMessageses(@PathVariable("id") Integer id, Pageable pageable) {
        LOGGER.debug("Fetching all associated messageses");
        return patientsService.findAssociatedMessageses(id, pageable);
    }

    @RequestMapping(value = "/{id:.+}/vitalses", method = RequestMethod.GET)
    @ApiOperation(value = "Gets the vitalses instance associated with the given id.")
    public Page<Vitals> findAssociatedVitalses(@PathVariable("id") Integer id, Pageable pageable) {
        LOGGER.debug("Fetching all associated vitalses");
        return patientsService.findAssociatedVitalses(id, pageable);
    }

    /**
    * This setter method should only be used by unit tests
    *
    * @param service PatientsService instance
    */
    protected void setPatientsService(PatientsService service) {
        this.patientsService = service;
    }
}