首页 > 编程语言 >尚医通day13【预约挂号】(内附源码)

尚医通day13【预约挂号】(内附源码)

时间:2023-06-18 13:34:37浏览次数:56  
标签:hoscode return String 尚医通 schedule 预约 内附 源码 depcode

页面预览

预约挂号

  • 根据预约周期,展示可预约日期,根据有号、无号、约满等状态展示不同颜色,以示区分
  • 可预约最后一个日期为即将放号日期
  • 选择一个日期展示当天可预约列表

image-20230227202834422

预约确认

image-20230227203321417

image-20230227203620732

image-20230226175848111

第01章-预约挂号

接口分析

(1)根据预约周期,展示可预约日期数据

(2)选择日期展示当天可预约列表

1、获取可预约日期接口

1.1、Controller

service-hosp微服务创建FrontScheduleController

package com.atguigu.syt.hosp.controller.front;

@Api(tags = "排班")
@RestController
@RequestMapping("/front/hosp/schedule")
public class FrontScheduleController {

    @Resource
    private ScheduleService scheduleService;

    @ApiOperation(value = "获取可预约排班日期数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "hoscode",value = "医院编码", required = true),
            @ApiImplicitParam(name = "depcode",value = "科室编码", required = true)})
    @GetMapping("getBookingScheduleRule/{hoscode}/{depcode}")
    public Result<Map<String, Object>> getBookingSchedule(
            @PathVariable String hoscode,
            @PathVariable String depcode) {

        Map<String, Object> result = scheduleService.getBookingScheduleRule(hoscode, depcode);
        return Result.ok(result);
    }

}

1.2、辅助方法

在ScheduleServiceImpl中添加两个辅助方法

/**
     * 根据日期对象和时间字符串获取一个日期时间对象
     * @param dateTime
     * @param timeString
     * @return
     */
private DateTime getDateTime(DateTime dateTime, String timeString) {
    String dateTimeString = dateTime.toString("yyyy-MM-dd") + " " + timeString;
    return DateTimeFormat.forPattern("yyyy-MM-dd HH:mm").parseDateTime(dateTimeString);
}
/**
     * 根据预约规则获取可预约日期列表
     */
private List<Date> getDateList(BookingRule bookingRule) {
    //预约周期
    int cycle = bookingRule.getCycle();
    //当天放号时间
    DateTime releaseTime = this.getDateTime(new DateTime(), bookingRule.getReleaseTime());
    //如果当天放号时间已过,则预约周期后一天显示即将放号,周期加1
    if (releaseTime.isBeforeNow()) {
        cycle += 1;
    }
    //计算当前可显示的预约日期,并且最后一天显示即将放号倒计时
    List<Date> dateList = new ArrayList<>();
    for (int i = 0; i < cycle; i++) {
        //计算当前可显示的预约日期
        DateTime curDateTime = new DateTime().plusDays(i);
        String dateString = curDateTime.toString("yyyy-MM-dd");
        dateList.add(new DateTime(dateString).toDate());
    }
    return dateList;
}

1.3、Service

接口:ScheduleService

/**
     * 根据医院编码和科室编码查询医院排班日期列表
     * @param hoscode
     * @param depcode
     * @return
     */
Map<String, Object> getBookingScheduleRule(String hoscode, String depcode);

实现:ScheduleServiceImpl

@Resource
private HospitalRepository hospitalRepository;

@Resource
private DepartmentRepository departmentRepository;
@Override
public Map<String, Object> getBookingScheduleRule(String hoscode, String depcode) {
    //获取医院
    Hospital hospital = hospitalRepository.findByHoscode(hoscode);
    //获取预约规则
    BookingRule bookingRule = hospital.getBookingRule();
    //根据预约规则获取可预约日期列表
    List<Date> dateList = this.getDateList(bookingRule);
    //查询条件:根据医院编号、科室编号以及预约日期查询
    Criteria criteria = Criteria.where("hoscode").is(hoscode).and("depcode").is(depcode).and("workDate").in(dateList);
    //根据工作日workDate期进行分组
    Aggregation agg = Aggregation.newAggregation(
        //查询条件
        Aggregation.match(criteria),
        Aggregation
        //按照日期分组 select workDate as workDate from schedule group by workDate
        .group("workDate").first("workDate").as("workDate")
        //剩余预约数
        .sum("availableNumber").as("availableNumber")
    );
    //执行查询
    AggregationResults<BookingScheduleRuleVo> aggResults = mongoTemplate.aggregate(agg, Schedule.class, BookingScheduleRuleVo.class);
    //获取查询结果
    List<BookingScheduleRuleVo> list = aggResults.getMappedResults();
    //将list转换成Map,日期为key,BookingScheduleRuleVo对象为value
    Map<Date, BookingScheduleRuleVo> scheduleVoMap = new HashMap<>();
    if (!CollectionUtils.isEmpty(list)) {
        scheduleVoMap = list.stream().collect(
            Collectors.toMap(bookingScheduleRuleVo -> bookingScheduleRuleVo.getWorkDate(), bookingScheduleRuleVo -> bookingScheduleRuleVo)
        );
    }
    //获取可预约排班规则
    List<BookingScheduleRuleVo> bookingScheduleRuleVoList = new ArrayList<>();
    int size = dateList.size();
    for (int i = 0; i < size; i++) {
        Date date = dateList.get(i);
        BookingScheduleRuleVo bookingScheduleRuleVo = scheduleVoMap.get(date);
        if (bookingScheduleRuleVo == null) { // 说明当天没有排班数据
            bookingScheduleRuleVo = new BookingScheduleRuleVo();
            bookingScheduleRuleVo.setWorkDate(date);
            //科室剩余预约数  -1表示无号
            bookingScheduleRuleVo.setAvailableNumber(-1);
        }
        bookingScheduleRuleVo.setWorkDateMd(date);
        //计算当前预约日期为周几
        String dayOfWeek = DateUtil.getDayOfWeek(new DateTime(date));
        bookingScheduleRuleVo.setDayOfWeek(dayOfWeek);
        if (i == size - 1) { //最后一条记录为即将放号
            bookingScheduleRuleVo.setStatus(1);
        } else {
            bookingScheduleRuleVo.setStatus(0);
        }

        //设置预约状态: 0正常; 1即将放号; -1当天已停止挂号
        if (i == 0) { //当天如果过了停挂时间, 则不能挂号
            DateTime stopTime = this.getDateTime(new DateTime(), bookingRule.getStopTime());
            if (stopTime.isBeforeNow()) {
                bookingScheduleRuleVo.setStatus(-1);//停止挂号
            }
        }
        bookingScheduleRuleVoList.add(bookingScheduleRuleVo);
    }
    //医院基本信息
    Map<String, String> info = new HashMap<>();
    //医院名称
    info.put("hosname", hospitalRepository.findByHoscode(hoscode).getHosname());
    //科室
    Department department = departmentRepository.findByHoscodeAndDepcode(hoscode, depcode);
    //大科室名称
    info.put("bigname", department.getBigname());
    //科室名称
    info.put("depname", department.getDepname());
    //当前月份
    info.put("workDateString", new DateTime().toString("yyyy年MM月"));
    //放号时间
    info.put("releaseTime", bookingRule.getReleaseTime());
    Map<String, Object> result = new HashMap<>();
    //可预约日期数据
    result.put("bookingScheduleList", bookingScheduleRuleVoList);//排班日期列表
    result.put("info", info);//医院基本信息
    return result;
}

2、获取排班数据接口

2.1、Controller

在FrontScheduleController添加方法

@ApiOperation("获取排班数据")
@ApiImplicitParams({
            @ApiImplicitParam(name = "hoscode",value = "医院编码", required = true),
            @ApiImplicitParam(name = "depcode",value = "科室编码", required = true),
            @ApiImplicitParam(name = "workDate",value = "排班日期", required = true)})
@GetMapping("getScheduleList/{hoscode}/{depcode}/{workDate}")
public Result<List<Schedule>> getScheduleList(
    @PathVariable String hoscode,
    @PathVariable String depcode,
    @PathVariable String workDate) {
    List<Schedule> scheduleList = scheduleService.getScheduleList(hoscode, depcode, workDate);
    return Result.ok(scheduleList);
}

2.2、Service

之前已经实现的业务

注意:如果我们在MongoDB集合的实体中使用了ObjectId作为唯一标识,那么需要对数据进行如下转换,以便将字符串形式的id传到前端

@Override
public List<Schedule> getScheduleList(String hoscode, String depcode, String workDate) {

    //注意:最后一个参数需要进行数据类型的转换
    List<Schedule> scheduleList = scheduleRepository.findByHoscodeAndDepcodeAndWorkDate(
            hoscode,
            depcode,
            new DateTime(workDate).toDate());//数据类型的转换

    //id为ObjectId类型时需要进行转换
    scheduleList.forEach(schedule -> {
        schedule.getParam().put("id", schedule.getId().toString());
    });

    return scheduleList;
}

3、前端整合

3.1、预约挂号页面跳转

修改/pages/hospital/_hoscode.vue组件的schedule方法

添加模块引用:

import cookie from 'js-cookie'
import userInfoApi from '~/api/userInfo'

methods中添加如下方法:

schedule(depcode) {
  //window.location.href = '/hospital/schedule?hoscode=' + this.$route.params.hoscode + "&depcode="+ depcode
  // 登录判断
  let token = cookie.get('refreshToken')
  if (!token) {
    this.$alert('请先进行用户登录', { type: 'warning' })
    return
  }
  //判断认证
  userInfoApi.getUserInfo().then((response) => {
    let authStatus = response.data.authStatus
    // 状态为2认证通过
    if (authStatus != 2) {
      this.$alert('请先进行用户认证', {
        type: 'warning',
        callback: () => {
          window.location.href = '/user'
        },
      })
      return
    }
    window.location.href =
      '/hospital/schedule?hoscode=' +
      this.$route.params.hoscode +
      '&depcode=' +
      depcode
  })
}

3.2、api

在api/hosp.js添加方法

//获取可预约排班日期列表
getBookingScheduleRule(hoscode, depcode) {
  return request({
    url: `/front/hosp/schedule/getBookingScheduleRule/${hoscode}/${depcode}`,
    method: 'get'
  })
},

//获取排班数据
getScheduleList(hoscode, depcode, workDate) {
  return request({
    url: `/front/hosp/schedule/getScheduleList/${hoscode}/${depcode}/${workDate}`,
    method: 'get'
  })
},

3.3、页面渲染

/pages/hospital/schedule.vue

第02章-预约确认

1、后端接口

1.1、Controller

在FrontScheduleController中添加方法

@ApiOperation("获取预约详情")
@ApiImplicitParam(name = "id",value = "排班id", required = true)
@GetMapping("getScheduleDetail/{id}")
public Result<Schedule> getScheduleDetail(@PathVariable String id) {
    Schedule schedule = scheduleService.getDetailById(id);
    return Result.ok(schedule);
}

1.2、Service

接口:ScheduleService

/**
     * 排班记录详情
     * @param id
     * @return
     */
Schedule getDetailById(String id);

实现:ScheduleServiceImpl

@Override
public Schedule getDetailById(String id) {
    Schedule schedule = scheduleRepository.findById(new ObjectId(id)).get();
    return this.packSchedule(schedule);
}

辅助方法

/**
     * 封装医院名称,科室名称和周几
     * @param schedule
     * @return
     */
private Schedule packSchedule(Schedule schedule) {
    //医院名称
    String hosname = hospitalRepository.findByHoscode(schedule.getHoscode()).getHosname();
    //科室名称
    String depname = departmentRepository.findByHoscodeAndDepcode(schedule.getHoscode(),schedule.getDepcode()).getDepname();
    //周几
    String dayOfWeek = DateUtil.getDayOfWeek(new DateTime(schedule.getWorkDate()));
    
    Integer workTime = schedule.getWorkTime();
    String workTimeString = workTime.intValue() == 0 ? "上午" : "下午";
    
    schedule.getParam().put("hosname",hosname);
    schedule.getParam().put("depname",depname);
    schedule.getParam().put("dayOfWeek",dayOfWeek);
    schedule.getParam().put("workTimeString", workTimeString);
    
  	//id为ObjectId类型时需要进行转换
    schedule.getParam().put("id",schedule.getId().toString());
    return schedule;
}

2、前端整合

2.1、api

在api/hosp.js添加方法

//获取预约详情
getScheduleDetail(id) {
    return request({
        url: `/front/hosp/schedule/getScheduleDetail/${id}`,
        method: 'get'
    })
}

2.2、页面渲染

pages/hospital/booking.vue

源码:https://gitee.com/dengyaojava/guigu-syt-parent

标签:hoscode,return,String,尚医通,schedule,预约,内附,源码,depcode
From: https://www.cnblogs.com/deyo/p/17489022.html

相关文章

  • nginx-clojure 源码构建一些问题
    因为nginx-clojure就是一个标准的nginx模块,一些是尝试基于源码进行构建发现一些问题的说明简单说明nginx当前1.25版本的构建是有问题的,1.24版本构建是可以的,1.23版本实际上官方已经提供了但是如果查看nginx官方文档会发现1.23版本的下载官方是似乎移除了,没直接提供了......
  • 一次Mybaits查询的源码分析
    很好奇Mybaits是怎么将xml和mapper对应起来的,用一段比较简单的demo去debug追踪一下源码看看先用xml配置的方式,看懂了再去看注解的方式是怎么实现的获取MapperMybaits是如何从xml中加载到mapper的<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEconfigurationPUB......
  • 从源码级深入剖析Tomcat类加载原理
    众所周知,Java中默认的类加载器是以父子关系存在的,实现了双亲委派机制进行类的加载,在前文中,我们提到了,双亲委派机制的设计是为了保证类的唯一性,这意味着在同一个JVM中是不能加载相同类库的不同版本的类。然而与许多服务器应用程序一样,Tomcat允许容器的不同部分以及在容器上运行的......
  • 【sentinel】sentinel客户端与dashboard通讯源码分析
    Sentinel客户端的规则大部分都是在Dashboard上完成配置,那么Sentinel客户端与Dashboard之间是如何进行通讯的呢?客户端定时向dashboard发送心跳要想实现Sentinel客户端与Dashboard进行通讯,我们需要引入下面的依赖:<dependency><groupId>com.alibaba.csp</groupId><artifactI......
  • 【框架源码】Spring源码解析之Bean创建源码流程
    问题:Spring中是如何初始化单例bean的?我们都知道Spring解析xml文件描述成BeanDefinition,解析BeanDefinition最后创建Bean将Bean放入单例池中,那么Spring在创建Bean的这个过程都做了什么。Spring核心方法refresh()中最最重要的一个方法finishBeanFactoryInitialization()方法,该方法......
  • 源码泄露+bak备份泄露+vim泄露+.DS_Store(mas迁移泄露)
    源码泄露+bak备份泄露+vim泄露+.DS_Store(mas迁移泄露)1.源码泄露web网站源码打包在web目录下造成泄露,通常以压缩包方式存在,如.zip、.rar、.tar、.tar.gz等,常见命名方式为网站名,www.网站名,backup+网站名等简单入门题目扫描到压缩包文件进行下载,找到对应文件,查看是否有flag,如果没......
  • 开源数字药店系统源码:打造高效的医药销售平台
    作为医药销售的全新解决方案,数字药店系统源码能够为医药企业提供更高效的销售解决方案,提高企业的竞争力。本文将详细介绍开源数字药店系统源码的特点和优势,以及如何打造高效的医药销售平台。一、开源数字药店系统源码的特点1. 功能丰富具有完善的功能,包括商品管理、订单管理、客户......
  • .Net Core医学检验LIS系统源码
    .NetCoreLIS系统源码,在第三方快检实验室、二级医院检验科应用5年以上,系统运行稳定、功能齐全,界面布局合理、操作简便。系统采用B/S架构SaaS模式,可扩展性强。LIS系统为实验室服务对象提供检验申请、采集标本、结果查询等功能;为实验室工作人员的核收标本、分送标本、传送资料、分析......
  • 互联网医院成品|互联网医院源码|线上医疗所含功能
    作为医疗服务领域的新生力量,互联网医院系统逐渐成为了医疗行业内时常交流和沟通的名词和产品,互联网医院系统就是用信息化、互联网化的手段去降低成本、优化服务,提升医疗服务诊前、诊中、诊后的全流程质量。那么互联网医院成品包含哪些功能呢?接下来啊小编就给大家介绍下。1、在线预......
  • 语音社交源码知识语音房间功能的实现
    当今,快节奏的社会为现在的很多年轻人带来了压力,每到深夜或是压力大的时候,很多人都想找人倾诉一下自己心里的悲伤与痛苦,以此来释放一下自己的压力,然而,这是一个独生子女的社会,大部分家庭都只有一个孩子,并且每天工作繁忙又加班到很晚的人根本没有时间或是精力去交朋友,所以这些人没有人......