Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 35628d1

Browse files
authored
Merge pull request #5 from laniltee/PatientService
Patient service
2 parents f7bd521 + 9e2cf72 commit 35628d1

26 files changed

+388
-142
lines changed

Microservices/PatientService/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,19 @@ app.get("/items", function(req, res){
227227
});
228228
});
229229

230+
//Searches all the patients
231+
app.get("/patients", function(req, res){
232+
console.log("[ROUTE CALLED][GET] /patients");
233+
patients.find({name: new RegExp('^' + reqId)}, function(error, patients){
234+
if(error){
235+
console.log("[ERROR] FETCHING PATIENTS FROM DATABASE FAILED");
236+
res.end();
237+
}
238+
console.log("[DB] PATIENTS FROM DATABASE SUCCESS");
239+
res.json(patients);
240+
});
241+
});
242+
230243

231244

232245

Microservices/PatientService/test/test.js renamed to Microservices/PatientService/test/patient_test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22
var request = require('request');
33
var assert = require('assert');
44

5-
var api = require('../index.js');
5+
var baseUrl = "http://localhost:8082/patients"
66

7-
var baseUrl = "http://localhost:8080/hello"
7+
describe("Patients API Test", function(){
88

9-
describe("Hello World Test", function(){
9+
describe("GET /patients", function(){
1010

11-
describe("GET /hello", function(){
12-
13-
it('returns status code 200', function(done){
11+
it('it returns status code 200', function(done){
1412

1513
request.get(baseUrl, function(error, response, body){
1614

@@ -21,11 +19,11 @@ describe("Hello World Test", function(){
2119

2220
});
2321

24-
it('returns hello world', function(done){
22+
it('it returns a list of patients', function(done){
2523

2624
request(baseUrl, function(error, response, body){
2725

28-
assert.equal("Hello World", body);
26+
assert.equal(200, response.statusCode);
2927
done();
3028

3129
});

Microservices/PatientService/test/should.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

Microservices/PatientService/test/test_department

Whitespace-only changes.

Microservices/PatientService/test/test_department.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

Microservices/PatientService/test/test_student

Whitespace-only changes.

Microservices/PatientService/test/test_student.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

Microservices/RequestService/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ app.use(bodyParser.json());
1111
app.use(cors());
1212

1313
//Database Connection
14-
mongoose.connect('mongodb://localhost/pharmacy_requests');
14+
mongoose.connect('mongodb://127.0.0.1/pharmacy_requests');
1515

1616
//Database schemas for requests and stocks objects
1717
var requests = mongoose.model('requests',{userID: String, requestID: String, drug:String, date:String, amount:Number, department:String, status:String});

Microservices/pharmacy-dispension-service/src/main/java/com/codesharks/Controller.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.springframework.beans.factory.annotation.Autowired;
44
import org.springframework.web.bind.annotation.*;
55

6+
import java.util.Iterator;
67
import java.util.List;
78

89
/**
@@ -22,6 +23,9 @@ public class Controller {
2223
@Autowired
2324
private StockRepository sr;
2425

26+
@Autowired
27+
private PatientsRepository patientsRepositoryr;
28+
2529
@PostMapping(path = "/dispense/{id}")
2630
public @ResponseBody boolean getPrescriptionTotal(@PathVariable String id){
2731

@@ -62,4 +66,48 @@ public class Controller {
6266

6367
return true;
6468
}
69+
70+
@GetMapping(path = "/sales")
71+
public @ResponseBody int getTotalSales(){
72+
73+
int total = 0;
74+
75+
Iterable<prescriptions> allPrescs = pr.findAll();
76+
Iterator<prescriptions> prescIterator = allPrescs.iterator();
77+
78+
while(prescIterator.hasNext()){
79+
total += prescIterator.next().getTotal();
80+
}
81+
82+
return total;
83+
}
84+
85+
@GetMapping(path = "/stock")
86+
public @ResponseBody int getTotalStock(){
87+
int total = 0;
88+
89+
Iterable<items> allItems = sr.findAll();
90+
Iterator<items> itemsIterator = allItems.iterator();
91+
92+
while(itemsIterator.hasNext()){
93+
items temp = itemsIterator.next();
94+
total = total + (temp.getPrice() * temp.getAvailable());
95+
}
96+
97+
return total;
98+
}
99+
100+
@GetMapping(path = "/patients")
101+
public @ResponseBody int getPatientsCount(){
102+
int count = 0;
103+
104+
Iterable<patients> allPats = patientsRepositoryr.findAll();
105+
Iterator<patients> patientsIterator = allPats.iterator();
106+
107+
while (patientsIterator.hasNext()){
108+
count++;
109+
}
110+
111+
return count;
112+
}
65113
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.codesharks;
2+
3+
import org.springframework.data.repository.CrudRepository;
4+
5+
/**
6+
* Created by Lanil Marasinghe on 30-Jun-17.
7+
*/
8+
public interface PatientsRepository extends CrudRepository<patients, String> {
9+
}

0 commit comments

Comments
 (0)