Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
842974287 committed Jun 4, 2018
0 parents commit c0e11e0
Show file tree
Hide file tree
Showing 23 changed files with 458 additions and 0 deletions.
31 changes: 31 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const views = require('koa-views');
const logger = require('koa-logger');
const koaBody = require('koa-body');
const server = require('koa-static');
const path = require('path');

const Koa = require('koa');
const app = module.exports = new Koa();

const router = require('./routes/router')

// middleware

app.use(logger());

app.use(
views(
path.join(__dirname, '/views'), {
extension: 'html',
map: { html: 'swig' }
}
)
);

app.use(koaBody());

app.use(server(path.join(__dirname, '/static')));

app.use(router.routes());

app.listen(3001);
5 changes: 5 additions & 0 deletions db/db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const mongoose = require('mongoose');

const db = mongoose.createConnection('mongodb://localhost:27017/Outpatient');

module.exports = db;
18 changes: 18 additions & 0 deletions db/patient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const db = require('./db');

const patientSchema = new Schema({
name: String,
gender: String,
birthDate: String,
diagnosis: [String],
treatment: [String]
}, {
versionKey: false
});

const Patient = db.model('Patient', patientSchema);

module.exports = Patient;
Empty file added lib/configs/diagnosis.json
Empty file.
Empty file added lib/configs/treatment.json
Empty file.
4 changes: 4 additions & 0 deletions lib/jsonFileIO.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const fs = require('fs');

let diagnosis = JSON.parse(fs.readFileSync('./config/diagnosis.json'));
let treatment = JSON.parse(fs.readFileSync('./config/treatment.json'));
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "outpatient-service",
"version": "1.0.0",
"description": "Managing the patients.",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"author": "Shiyan Deng",
"license": "ISC",
"dependencies": {
"koa": "^2.2.0",
"koa-basic-auth": "^2.0.0",
"koa-body": "^2.0.1",
"koa-compose": "^4.0.0",
"koa-csrf": "^3.0.6",
"koa-logger": "^3.0.0",
"koa-router": "^7.2.0",
"koa-session": "^5.0.0",
"koa-static": "^3.0.0",
"koa-views": "^6.0.2",
"mongoose": "^5.1.3",
"swig": "^1.4.2"
}
}
31 changes: 31 additions & 0 deletions routes/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const router = require('koa-router')();
const Patient = require('../db/patient');

router.get('/', showMainPage)
.get('/searchByName', searchByName)
.get('/addNewPatient', addNewPatient)
.get('/patientDetail', showPatientDetail);

async function showMainPage(ctx) {
await ctx.render('main');
}

async function searchByName(ctx) {
let patients = await Patient.find({ name: ctx.query.name });

if (patients.length) {
await ctx.render('patientList', {patients: patients});
}
else {
let newPatient = new Patient({name : ctx.query.name});
newPatient.save();

await ctx.render('newPatient', { name: ctx.query.name });
}
}

async function showPatientDetail(ctx) {

}

module.exports = router;
7 changes: 7 additions & 0 deletions static/css/bootstrap.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/css/bootstrap.min.css.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/css/jquery.dataTables.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions static/js/bootstrap.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions static/js/bootstrap.min.js.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions static/js/dataTable_setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$(document).ready( function () {
$('#dataTable').DataTable({
"language": {
"paginate": {
"sNext": "下一页",
"sPrevious": "上一页",
},
"loadingRecords": "正在加载中.....",
"zeroRecords": "对不起,查询不到相关数据!",
"infoFiltered": "【从 _MAX_ 条数据中搜索的结果】",
"sSearch": "搜索",
"sLengthMenu": "每页显示 _MENU_ 条记录",
"sInfo": "当前显示 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
}
});
});
Loading

0 comments on commit c0e11e0

Please sign in to comment.