1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 'use strict';
- const _ = require('lodash');
- const Controller = require('egg').Controller;
- // 病人管理
- class PatientController extends Controller {
- constructor(ctx) {
- super(ctx);
- this.service = this.ctx.service.patient;
- }
- // 查询列表
- async index() {
- let { skip, limit, ...info } = this.ctx.query;
- if (skip && !_.isNumber(skip)) skip = Number(skip);
- if (limit && !_.isNumber(limit)) limit = Number(limit);
- const res = await this.service.query(info, { skip, limit });
- this.ctx.ok(res);
- }
- // POST
- // 注册患者
- async create() {
- // 如果参数校验未通过,将会抛出一个 status = 422 的异常
- const res = await this.service.create(this.ctx.request.body);
- this.ctx.ok({ msg: 'created', data: res });
- }
- // GET /{id}
- // 获得患者详情
- async show() {
- const res = await this.service.fetch(this.ctx.params);
- this.ctx.ok({ data: res });
- }
- // GET /{id}
- // 获得患者所有关注的医生列表
- async doctors() {
- const res = await this.service.doctors(this.ctx.params);
- this.ctx.ok({ data: res });
- }
- // 查询患者所有群信息
- async groups() {
- const res = await this.service.groups(this.ctx.params);
- this.ctx.ok({ data: res });
- }
- // GET /{id}/info
- // POST /{id}/info
- // 获得基本信息,修改基本信息
- async info() {
- if (this.ctx.request.method === 'POST') {
- await this.service.updateInfo(this.ctx.params, this.ctx.request.body);
- this.ctx.ok({ msg: 'accepted' });
- } else {
- const res = await this.service.fetch(this.ctx.params);
- this.ctx.ok({ data: res && res.emrs });
- }
- }
- // DELETE /{id}
- // 删除患者信息
- async destroy() {
- const { id } = this.ctx.params;
- await this.service.delete({ id });
- this.ctx.ok({ msg: 'deleted' });
- }
- // 根据openid 取得医生信息
- async findopenid() {
- return await this.service.findByOpenid(this.ctx.query);
- }
- async cutDoctorPatient() {
- await this.service.fromDoctorDelete(this.ctx.request.body);
- this.ctx.ok();
- }
- }
- module.exports = PatientController;
|