-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from wso2/master
Update fork
- Loading branch information
Showing
197 changed files
with
7,140 additions
and
729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
4 changes: 4 additions & 0 deletions
4
docs/content/src/get-started/healthcare-service/Ballerina.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
org_name = "wso2" | ||
version = "0.1.0" | ||
lockfile_version = "1.0.0" | ||
ballerina_version = "1.0.1" |
File renamed without changes.
16 changes: 16 additions & 0 deletions
16
docs/content/src/get-started/healthcare-service/src/doctors/Module.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Grand Oak and Pine Valley Hospital Services | ||
|
||
Gives out available doctors for a given doctor type for Grand Oak hospital and Pine Valley hospital | ||
|
||
Available doctor types: | ||
Pediatrician | ||
Physician | ||
Ophthalmologist | ||
|
||
## Example requests | ||
|
||
``curl -v http://localhost:9090/grandOak/doctors/Physician`` | ||
|
||
``curl -v http://localhost:9091/pineValley/doctors/Physician`` | ||
|
||
|
95 changes: 95 additions & 0 deletions
95
docs/content/src/get-started/healthcare-service/src/doctors/grandOak.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2019 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// WSO2 Inc. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/http; | ||
import ballerina/log; | ||
|
||
@http:ServiceConfig { | ||
basePath: "/grandOak" | ||
} | ||
service grandOakService on new http:Listener(9091) { | ||
|
||
@http:ResourceConfig { | ||
path: "/doctors/{doctorType}", | ||
methods: ["GET"] | ||
} | ||
resource function doctors(http:Caller caller, http:Request request, string doctorType) returns error? { | ||
|
||
json responsePayload = {}; | ||
if (doctorType.toLowerAscii() == "ophthalmologist") { | ||
responsePayload = { | ||
"doctors": { | ||
"doctor": [ | ||
{ | ||
"name": "John Mathew", | ||
"time": "03:30 PM", | ||
"hospital": "Grand Oak" | ||
}, | ||
{ | ||
"name": "Allan Silvester", | ||
"time": "04:30 PM", | ||
"hospital": "Grand Oak" | ||
} | ||
] | ||
} | ||
}; | ||
} else if (doctorType.toLowerAscii() == "physician") { | ||
responsePayload = { | ||
"doctors": { | ||
"doctor": [ | ||
{ | ||
"name": "Shane Martin", | ||
"time": "07:30 AM", | ||
"hospital": "Grand Oak" | ||
}, | ||
{ | ||
"name": "Geln Ivan", | ||
"time": "08:30 AM", | ||
"hospital": "Grand Oak" | ||
} | ||
] | ||
} | ||
}; | ||
} else if (doctorType.toLowerAscii() == "pediatrician") { | ||
responsePayload = { | ||
"doctors": { | ||
"doctor": [ | ||
{ | ||
"name": "Bob Watson", | ||
"time": "05:30 PM", | ||
"hospital": "Grand Oak" | ||
}, | ||
{ | ||
"name": "Paul Johnson", | ||
"time": "07:30 AM", | ||
"hospital": "Grand Oak" | ||
} | ||
] | ||
} | ||
}; | ||
} else { | ||
handleError(caller, "Invalid doctor category"); | ||
return; | ||
} | ||
http:Response response = new; | ||
response.setJsonPayload(responsePayload, "application/json"); | ||
var result = caller->respond(response); | ||
// Logs the `error` in case of a failure. | ||
if (result is error) { | ||
log:printError("Error sending response", err = result); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
docs/content/src/get-started/healthcare-service/src/doctors/healthcare_service.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright (c) 2019 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// WSO2 Inc. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/http; | ||
import ballerina/log; | ||
|
||
http:Client grandOakHospital = new("http://localhost:9091/grandOak"); | ||
http:Client pineValleyHospital = new("http://localhost:9092/pineValley"); | ||
|
||
@http:ServiceConfig { | ||
basePath: "/healthcare" | ||
} | ||
service healthcare on new http:Listener(9090) { | ||
|
||
@http:ResourceConfig { | ||
path: "/doctor/{doctorType}" | ||
} | ||
resource function getDoctors(http:Caller caller, http:Request request, string doctorType) returns error? { | ||
json grandOakDoctors = {}; | ||
json pineValleyDoctors = {}; | ||
var grandOakResponse = grandOakHospital->get("/doctors/" + doctorType); | ||
var pineValleyResponse = pineValleyHospital->post("/doctors", {doctorType: doctorType}); | ||
// Extract doctors array from grand oak hospital response | ||
if (grandOakResponse is http:Response) { | ||
json result = check grandOakResponse.getJsonPayload(); | ||
grandOakDoctors = check result.doctors.doctor; | ||
} else { | ||
handleError(caller, <@untained> grandOakResponse.reason()); | ||
} | ||
// Extract doctors array from pine valley hospital response | ||
if (pineValleyResponse is http:Response) { | ||
json result = check pineValleyResponse.getJsonPayload(); | ||
pineValleyDoctors = check result.doctors.doctor; | ||
} else { | ||
handleError(caller, <@untained> pineValleyResponse.reason()); | ||
} | ||
// Aggregate grand oak hospital's doctors with pine valley hospital's doctors | ||
if (grandOakDoctors is json[] && pineValleyDoctors is json[]) { | ||
foreach var item in pineValleyDoctors { | ||
grandOakDoctors.push(item); | ||
} | ||
} | ||
// Respond back to the caller with aggregated json response | ||
http:Response response = new(); | ||
response.setJsonPayload(<@untained> grandOakDoctors); | ||
var result = caller->respond(response); | ||
|
||
if (result is error) { | ||
log:printError("Error sending response", err = result); | ||
} | ||
} | ||
} | ||
|
||
function handleError(http:Caller caller, string errorMsg) { | ||
http:Response response = new; | ||
|
||
json responsePayload = { | ||
"error": { | ||
"message": errorMsg | ||
} | ||
}; | ||
response.setJsonPayload(responsePayload, "application/json"); | ||
var result = caller->respond(response); | ||
if (result is error) { | ||
log:printError("Error sending response", err = result); | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
docs/content/src/get-started/healthcare-service/src/doctors/pineValley.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright (c) 2019 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
// | ||
// WSO2 Inc. licenses this file to you under the Apache License, | ||
// Version 2.0 (the "License"); you may not use this file except | ||
// in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
import ballerina/http; | ||
import ballerina/log; | ||
|
||
@http:ServiceConfig { | ||
basePath: "/pineValley" | ||
} | ||
service pineValleyService on new http:Listener(9092) { | ||
|
||
@http:ResourceConfig { | ||
path: "/doctors", | ||
methods: ["POST"] | ||
} | ||
resource function doctors(http:Caller caller, http:Request request) returns error? { | ||
|
||
json doctors = check request.getJsonPayload(); | ||
string doctorType = <string>doctors.doctorType; | ||
json responsePayload = {}; | ||
if (doctorType.toLowerAscii() == "ophthalmologist") { | ||
responsePayload = { | ||
"doctors": { | ||
"doctor": [ | ||
{ | ||
"name": "John Mathew", | ||
"time": "07:30 AM", | ||
"hospital": "pineValley" | ||
}, | ||
{ | ||
"name": "Roma Katherine", | ||
"time": "04:30 PM", | ||
"hospital": "pineValley" | ||
} | ||
] | ||
} | ||
}; | ||
} else if (doctorType.toLowerAscii() == "physician") { | ||
responsePayload = { | ||
"doctors": { | ||
"doctor": [ | ||
{ | ||
"name": "Geln Ivan", | ||
"time": "05:30 PM", | ||
"hospital": "pineValley" | ||
}, | ||
{ | ||
"name": "Daniel Lewis", | ||
"time": "05:30 PM", | ||
"hospital": "pineValley" | ||
} | ||
] | ||
} | ||
}; | ||
} else if (doctorType.toLowerAscii() == "pediatrician") { | ||
responsePayload = { | ||
"doctors": { | ||
"doctor": [ | ||
{ | ||
"name": "Bob Watson", | ||
"time": "07:30 AM", | ||
"hospital": "pineValley" | ||
}, | ||
{ | ||
"name": "Wilson Mcdonald", | ||
"time": "07:30 AM", | ||
"hospital": "pineValley" | ||
} | ||
] | ||
} | ||
}; | ||
} else { | ||
handleError(caller, "Invalid doctor category"); | ||
return; | ||
} | ||
http:Response response = new; | ||
response.setJsonPayload(responsePayload, "application/json"); | ||
var result = caller->respond(response); | ||
// Logs the `error` in case of a failure. | ||
if (result is error) { | ||
log:printError("Error sending response", err = result); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.