Skip to content

Commit

Permalink
restucture code
Browse files Browse the repository at this point in the history
  • Loading branch information
isuruh15 committed Sep 24, 2024
1 parent fad3848 commit 804a2e4
Show file tree
Hide file tree
Showing 33 changed files with 28 additions and 6,617 deletions.
9 changes: 9 additions & 0 deletions regulation/cms-0057-f/bulk-export-client-service/records.bal
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ public type BulkExportServerConfig record {|
decimal defaultIntervalInSec;
|};

public type TargetServerConfig record {|
string 'type;
string host;
int port;
string username;
string password;
string directory;
|};

// have a generic config for source server and target server for FHIR cases
// check Ballerina FTP client for the FTP server config

Expand Down
26 changes: 13 additions & 13 deletions regulation/cms-0057-f/bulk-export-client-service/service.bal
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ import ballerina/task;
import ballerina/uuid;
import ballerinax/health.fhir.r4.international401;

configurable BulkExportServerConfig exportSeverConfig = ?;
configurable BulkExportServerConfig sourceServerConfig = ?;
configurable BulkExportClientConfig clientServiceConfig = ?;
configurable FtpServerConfig ftpServerConfig = ?;
configurable TargetServerConfig targetServerConfig = ?;

http:OAuth2ClientCredentialsGrantConfig config = {
tokenUrl: exportSeverConfig.tokenUrl,
clientId: exportSeverConfig.clientId,
clientSecret: exportSeverConfig.clientSecret,
scopes: exportSeverConfig.scopes
tokenUrl: sourceServerConfig.tokenUrl,
clientId: sourceServerConfig.clientId,
clientSecret: sourceServerConfig.clientSecret,
scopes: sourceServerConfig.scopes
};

isolated http:Client statusClient = check new (exportSeverConfig.baseUrl);
isolated http:Client statusClient = check new (sourceServerConfig.baseUrl);

service /trigger on new http:Listener(clientServiceConfig.port) {

function init() returns error? {

if clientServiceConfig.authEnabled {
lock {
statusClient = check new (exportSeverConfig.baseUrl, auth = config.clone());
statusClient = check new (sourceServerConfig.baseUrl, auth = config.clone());
}
} else {
lock {
statusClient = check new (exportSeverConfig.baseUrl);
statusClient = check new (sourceServerConfig.baseUrl);
}
}

Expand All @@ -53,7 +53,7 @@ service /trigger on new http:Listener(clientServiceConfig.port) {
string queryString = populateQueryString(_outputFormat, _since, _type);
// kick-off request to the bulk export server
lock {
status = statusClient->get(string `${exportSeverConfig.contextPath}/Patient/$export${queryString}`, {
status = statusClient->get(string `${sourceServerConfig.contextPath}/Patient/$export${queryString}`, {
Accept: "application/fhir+json",
Prefer: "respond-async"
});
Expand Down Expand Up @@ -106,7 +106,7 @@ service /trigger on new http:Listener(clientServiceConfig.port) {
// kick-off request to the bulk export server

lock {
status = statusClient->post(string `${exportSeverConfig.contextPath}/Patient/$export`, parametersResource.clone().toJson(),
status = statusClient->post(string `${sourceServerConfig.contextPath}/Patient/$export`, parametersResource.clone().toJson(),
{
Accept: "application/fhir+json",
Prefer: "respond-async",
Expand Down Expand Up @@ -151,7 +151,7 @@ service /trigger on new http:Listener(clientServiceConfig.port) {
string queryString = populateQueryString(_outputFormat, _since, _type);
// kick-off request to the bulk export server
lock {
status = statusClient->get(string `${exportSeverConfig.contextPath}/Group/${group_id}/$export${queryString}`, {
status = statusClient->get(string `${sourceServerConfig.contextPath}/Group/${group_id}/$export${queryString}`, {
Accept: "application/fhir+json",
Prefer: "respond-async"
});
Expand Down Expand Up @@ -199,7 +199,7 @@ isolated function submitBackgroundJob(string taskId, http:Response|http:ClientEr
// get the location of the status check
do {
string location = check status.getHeader("Content-location");
task:JobId|() _ = check executeJob(new PollingTask(taskId, location), exportSeverConfig.defaultIntervalInSec);
task:JobId|() _ = check executeJob(new PollingTask(taskId, location), sourceServerConfig.defaultIntervalInSec);
log:printDebug("Polling location recieved: " + location);
} on fail var e {
log:printError("Error occurred while getting the location or scheduling the Job", e);
Expand Down
6 changes: 3 additions & 3 deletions regulation/cms-0057-f/bulk-export-client-service/utils.bal
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public isolated function saveFileInFS(string downloadLink, string fileName) retu
log:printDebug(string `Successfully downloaded the file. File name: ${fileName}`);
}

public isolated function sendFileFromFSToFTP(FtpServerConfig config, string sourcePath, string fileName) returns error? {
public isolated function sendFileFromFSToFTP(TargetServerConfig config, string sourcePath, string fileName) returns error? {
// Implement the FTP server logic here.
ftp:Client fileClient = check new ({
host: config.host,
Expand All @@ -78,10 +78,10 @@ public isolated function downloadFiles(json exportSummary, string exportId) retu
if downloadFileResult is error {
log:printError("Error occurred while downloading the file.", downloadFileResult);
}
if ftpServerConfig.enabled {
if targetServerConfig.'type == "ftp" {
// download the file to the FTP server
// implement the FTP server logic
error? uploadFileResult = sendFileFromFSToFTP(ftpServerConfig, string `${clientServiceConfig.targetDirectory}/${item.'type}-exported.ndjson`, string `${item.'type}-exported.ndjson`);
error? uploadFileResult = sendFileFromFSToFTP(targetServerConfig, string `${clientServiceConfig.targetDirectory}/${item.'type}-exported.ndjson`, string `${item.'type}-exported.ndjson`);
if uploadFileResult is error {
log:printError("Error occurred while sending the file to ftp.", downloadFileResult);

Expand Down
8 changes: 0 additions & 8 deletions regulation/cms-0057-f/demo/backend-service/Ballerina.toml

This file was deleted.

16 changes: 0 additions & 16 deletions regulation/cms-0057-f/demo/backend-service/records.bal

This file was deleted.

107 changes: 0 additions & 107 deletions regulation/cms-0057-f/demo/backend-service/service.bal

This file was deleted.

12 changes: 0 additions & 12 deletions regulation/cms-0057-f/demo/backend-service/utils.bal

This file was deleted.

24 changes: 0 additions & 24 deletions regulation/cms-0057-f/demo/webapp/pdex-member-portal/.gitignore

This file was deleted.

50 changes: 0 additions & 50 deletions regulation/cms-0057-f/demo/webapp/pdex-member-portal/README.md

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions regulation/cms-0057-f/demo/webapp/pdex-member-portal/index.html

This file was deleted.

Loading

0 comments on commit 804a2e4

Please sign in to comment.