From 3dfd0b11245cb8f947e986fe8da2a6e399bc8689 Mon Sep 17 00:00:00 2001 From: Gevin Karunarathne Date: Fri, 8 Mar 2024 15:17:03 +0530 Subject: [PATCH 1/5] Add validator service --- .../validator-service/.devcontainer.json | 4 + miscellaneous/validator-service/.gitignore | 3 + .../validator-service/Ballerina.toml | 18 + .../validator-service/Dependencies.toml | 383 ++++++++++++++++++ miscellaneous/validator-service/service.bal | 114 ++++++ 5 files changed, 522 insertions(+) create mode 100644 miscellaneous/validator-service/.devcontainer.json create mode 100644 miscellaneous/validator-service/.gitignore create mode 100644 miscellaneous/validator-service/Ballerina.toml create mode 100644 miscellaneous/validator-service/Dependencies.toml create mode 100644 miscellaneous/validator-service/service.bal diff --git a/miscellaneous/validator-service/.devcontainer.json b/miscellaneous/validator-service/.devcontainer.json new file mode 100644 index 0000000..b9c505b --- /dev/null +++ b/miscellaneous/validator-service/.devcontainer.json @@ -0,0 +1,4 @@ +{ + "image": "ballerina/ballerina-devcontainer:2201.8.1", + "extensions": ["WSO2.ballerina"], +} diff --git a/miscellaneous/validator-service/.gitignore b/miscellaneous/validator-service/.gitignore new file mode 100644 index 0000000..7512ebe --- /dev/null +++ b/miscellaneous/validator-service/.gitignore @@ -0,0 +1,3 @@ +target +generated +Config.toml diff --git a/miscellaneous/validator-service/Ballerina.toml b/miscellaneous/validator-service/Ballerina.toml new file mode 100644 index 0000000..f78646e --- /dev/null +++ b/miscellaneous/validator-service/Ballerina.toml @@ -0,0 +1,18 @@ +[package] +org = "wso2" +name = "validator_service" +version = "0.1.0" +distribution = "2201.8.1" + +[build-options] +observabilityIncluded = true + +[[dependency]] +org = "ballerinax" +name = "health.fhir.r4.validator" +version = "4.2.0" + +[[dependency]] +org = "ballerinax" +name = "health.fhir.r4" +version = "4.3.3" diff --git a/miscellaneous/validator-service/Dependencies.toml b/miscellaneous/validator-service/Dependencies.toml new file mode 100644 index 0000000..854e2e2 --- /dev/null +++ b/miscellaneous/validator-service/Dependencies.toml @@ -0,0 +1,383 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.8.1" + +[[package]] +org = "ballerina" +name = "auth" +version = "2.10.0" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "log"} +] + +[[package]] +org = "ballerina" +name = "cache" +version = "3.7.1" +dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "task"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "constraint" +version = "1.5.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "crypto" +version = "2.6.2" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "file" +version = "1.9.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "os"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "http" +version = "2.10.8" +dependencies = [ + {org = "ballerina", name = "auth"}, + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "file"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "jwt"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.decimal"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "lang.regexp"}, + {org = "ballerina", name = "lang.runtime"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "mime"}, + {org = "ballerina", name = "oauth2"}, + {org = "ballerina", name = "observe"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"} +] +modules = [ + {org = "ballerina", packageName = "http", moduleName = "http"}, + {org = "ballerina", packageName = "http", moduleName = "http.httpscerr"} +] + +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "jwt" +version = "2.10.0" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "lang.string"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.decimal" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.int" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" + +[[package]] +org = "ballerina" +name = "lang.regexp" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.runtime" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.string" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.regexp"} +] + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "log" +version = "2.9.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerina", packageName = "log", moduleName = "log"} +] + +[[package]] +org = "ballerina" +name = "mime" +version = "2.9.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"} +] + +[[package]] +org = "ballerina" +name = "oauth2" +version = "2.10.0" +dependencies = [ + {org = "ballerina", name = "cache"}, + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"} +] + +[[package]] +org = "ballerina" +name = "observe" +version = "1.2.2" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "os" +version = "1.8.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "task" +version = "2.5.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerina" +name = "time" +version = "2.4.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "url" +version = "2.4.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "uuid" +version = "1.7.0" +dependencies = [ + {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.int"}, + {org = "ballerina", name = "time"} +] + +[[package]] +org = "ballerinai" +name = "observe" +version = "0.0.0" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "observe"} +] +modules = [ + {org = "ballerinai", packageName = "observe", moduleName = "observe"} +] + +[[package]] +org = "ballerinax" +name = "health.base" +version = "1.0.3" +dependencies = [ + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jwt"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "mime"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "uuid"} +] + +[[package]] +org = "ballerinax" +name = "health.fhir.r4" +version = "4.3.3" +dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jwt"}, + {org = "ballerina", name = "lang.regexp"}, + {org = "ballerina", name = "lang.value"}, + {org = "ballerina", name = "log"}, + {org = "ballerina", name = "time"}, + {org = "ballerina", name = "url"}, + {org = "ballerina", name = "uuid"}, + {org = "ballerinax", name = "health.base"} +] +modules = [ + {org = "ballerinax", packageName = "health.fhir.r4", moduleName = "health.fhir.r4"} +] + +[[package]] +org = "ballerinax" +name = "health.fhir.r4.international401" +version = "1.2.0" +dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "log"}, + {org = "ballerinax", name = "health.fhir.r4"} +] + +[[package]] +org = "ballerinax" +name = "health.fhir.r4.parser" +version = "4.1.1" +dependencies = [ + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "log"}, + {org = "ballerinax", name = "health.fhir.r4"}, + {org = "ballerinax", name = "health.fhir.r4.international401"} +] + +[[package]] +org = "ballerinax" +name = "health.fhir.r4.validator" +version = "4.2.0" +dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "lang.regexp"}, + {org = "ballerina", name = "log"}, + {org = "ballerinax", name = "health.fhir.r4"}, + {org = "ballerinax", name = "health.fhir.r4.parser"} +] +modules = [ + {org = "ballerinax", packageName = "health.fhir.r4.validator", moduleName = "health.fhir.r4.validator"} +] + +[[package]] +org = "wso2" +name = "validator_service" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "http"}, + {org = "ballerina", name = "log"}, + {org = "ballerinai", name = "observe"}, + {org = "ballerinax", name = "health.fhir.r4"}, + {org = "ballerinax", name = "health.fhir.r4.validator"} +] +modules = [ + {org = "wso2", packageName = "validator_service", moduleName = "validator_service"} +] + diff --git a/miscellaneous/validator-service/service.bal b/miscellaneous/validator-service/service.bal new file mode 100644 index 0000000..96d071c --- /dev/null +++ b/miscellaneous/validator-service/service.bal @@ -0,0 +1,114 @@ +import ballerina/http; +import ballerina/log; +import ballerinax/health.fhir.r4; +import ballerinax/health.fhir.r4.validator; + +configurable string[] CORS_ALLOWED_ORIGINS = ?; + +# FHIR validation error details record. +# +# + issues - FHIR issues +public type FHIRValidationErrorDetail record { + *r4:FHIRErrorDetail; + [validator:FHIRValidationIssueDetail, validator:FHIRValidationIssueDetail...] issues; +}; + +isolated function issueDetailToOperationOutcomeIssue(r4:FHIRIssueDetail detail) returns r4:OperationOutcomeIssue { + + r4:OperationOutcomeIssue issueBBE = { + severity: detail.severity, + code: detail.code + }; + + (r4:CodeableConcept)? details = detail.details; + if details != () { + issueBBE.details = details; + } + + string? diagnostic = detail.diagnostic; + if diagnostic != () { + issueBBE.diagnostics = string `${diagnostic}`; + } else { + issueBBE.diagnostics = ""; + } + + string[]? expression = detail.expression; + if expression != () { + issueBBE.expression = expression; + } + + return issueBBE; +} + +service http:Service / on new http:Listener(9090) { + + @http:ResourceConfig { + cors: { + allowOrigins: CORS_ALLOWED_ORIGINS, + allowCredentials: true + } + } + + resource function post validate(@http:Payload json message) returns http:Response { + + var validationResult = validator:validate(message); + + if validationResult is error { + + //Gets the fhir error from the validate function, extracts the detailedErrors array, and creates + //a FHIRIssueDetail for each detailed error in the detailedErrors array. + FHIRValidationErrorDetail & readonly detail = validationResult.detail(); + validator:FHIRValidationIssueDetail issues = detail.issues[0]; + r4:FHIRIssueDetail[] issueArray = []; + string[]? errorInIssue = issues.detailedErrors; + if (errorInIssue != ()) { + foreach var i in 0 ..< errorInIssue.length() { + r4:FHIRIssueDetail issue = { + severity: issues.severity, + code: issues.code, + diagnostic: errorInIssue[i], + expression: issues.expression, + details: () + }; + issueArray.push(issue); + } + } + + //Then, creates an OperationOutcomeIssue for each FHIRIssueDetail and adds them to an OperationOutcome. + r4:OperationOutcomeIssue[] opIssueArray = []; + foreach var i in 0 ..< issueArray.length() { + r4:OperationOutcomeIssue opIssue = issueDetailToOperationOutcomeIssue(issueArray[i]); + opIssueArray.push(opIssue); + } + r4:OperationOutcome opOutcome = { + issue: opIssueArray + }; + + log:printDebug(opOutcome.toJsonString()); + + http:Response response = new; + response.statusCode = 400; + response.setPayload(opOutcome.toJson()); + return response; + + } + + log:printDebug("Validation successful"); + r4:FHIRIssueDetail issue = { + severity: "information", + code: "informational", + diagnostic: "Validation Successful", + expression: (), + details: () + }; + + r4:OperationOutcomeIssue opIssue = issueDetailToOperationOutcomeIssue(issue); + r4:OperationOutcome opOutcome = { + issue: [opIssue] + }; + http:Response response = new; + response.statusCode = 200; + response.setPayload(opOutcome.toJson()); + return response; + } +} From 4de570e8ea43671109fbd77f0979e12c55d0f356 Mon Sep 17 00:00:00 2001 From: Gevin Karunarathne Date: Tue, 12 Mar 2024 10:30:54 +0530 Subject: [PATCH 2/5] Add readme file --- miscellaneous/validator-service/README.md | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 miscellaneous/validator-service/README.md diff --git a/miscellaneous/validator-service/README.md b/miscellaneous/validator-service/README.md new file mode 100644 index 0000000..e19102b --- /dev/null +++ b/miscellaneous/validator-service/README.md @@ -0,0 +1,57 @@ +# FHIR Validation API Service + +This service is a Ballerina-based API designed to validate FHIR (Fast Healthcare Interoperability Resources) messages. It uses the ballerinax/health.fhir.r4 and ballerinax/health.fhir.r4.validator libraries for FHIR R4 validation. + +## Prerequisites +To get started with this service, you'll need to have Ballerina (Refer compatibility to install the relevant version) installed on your machine. + +### Setup and run + +1. Clone this repository to your local machine and navigate to the validator-service directory. + +2. Set the following values from environment variables. + +- `CORS_ALLOWED_ORIGINS` - An array of strings, where each string is a URL that is allowed to access the API (To allow your URL to access the pre-built service, include it in this array). + +3. Run the project. + +```ballerina +bal run +``` + +4. Invoke the APIs. + +Sample request for FHIR patient read: + +``` +curl -X POST -H "Content-Type: application/json" -d '{ + "resourceType": "Patient", + "id": "example", + "text": { + "status": "generated", + "div": "" + }, +}' http://localhost:9090/validate +``` + + + +## API Reference + +#### POST /validate + +This endpoint accepts a JSON payload containing a FHIR message and validates it. + +#### Request + +The request body should contain a JSON representation of a FHIR message. + +#### Response + +The HTTP status code of the response will be 200 if the validation is successful, and 400 if it fails. + +The response will be a JSON representation of an `OperationOutcome` FHIR resource. This resource contains a list of issues that were found during the validation process. + +If the validation is successful, the `OperationOutcome` will contain a single issue with severity "information" and code "informational", and a diagnostic message "Validation Successful". + +If the validation fails, the `OperationOutcome` will contain one or more issues detailing the validation errors. From 4a9a3fb985f81c96ac8a2d3c5e37441fe1b466ec Mon Sep 17 00:00:00 2001 From: Gevin Karunarathne Date: Wed, 13 Mar 2024 13:51:25 +0530 Subject: [PATCH 3/5] Add comments and code improvement --- miscellaneous/validator-service/service.bal | 51 ++++++------------- .../validator-service/service_utils.bal | 47 +++++++++++++++++ 2 files changed, 62 insertions(+), 36 deletions(-) create mode 100644 miscellaneous/validator-service/service_utils.bal diff --git a/miscellaneous/validator-service/service.bal b/miscellaneous/validator-service/service.bal index 96d071c..bf6b8f7 100644 --- a/miscellaneous/validator-service/service.bal +++ b/miscellaneous/validator-service/service.bal @@ -1,3 +1,15 @@ +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). +// WSO2 LLC. 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 + import ballerina/http; import ballerina/log; import ballerinax/health.fhir.r4; @@ -5,41 +17,6 @@ import ballerinax/health.fhir.r4.validator; configurable string[] CORS_ALLOWED_ORIGINS = ?; -# FHIR validation error details record. -# -# + issues - FHIR issues -public type FHIRValidationErrorDetail record { - *r4:FHIRErrorDetail; - [validator:FHIRValidationIssueDetail, validator:FHIRValidationIssueDetail...] issues; -}; - -isolated function issueDetailToOperationOutcomeIssue(r4:FHIRIssueDetail detail) returns r4:OperationOutcomeIssue { - - r4:OperationOutcomeIssue issueBBE = { - severity: detail.severity, - code: detail.code - }; - - (r4:CodeableConcept)? details = detail.details; - if details != () { - issueBBE.details = details; - } - - string? diagnostic = detail.diagnostic; - if diagnostic != () { - issueBBE.diagnostics = string `${diagnostic}`; - } else { - issueBBE.diagnostics = ""; - } - - string[]? expression = detail.expression; - if expression != () { - issueBBE.expression = expression; - } - - return issueBBE; -} - service http:Service / on new http:Listener(9090) { @http:ResourceConfig { @@ -49,7 +26,7 @@ service http:Service / on new http:Listener(9090) { } } - resource function post validate(@http:Payload json message) returns http:Response { + isolated resource function post validate(@http:Payload json message) returns http:Response { var validationResult = validator:validate(message); @@ -93,6 +70,8 @@ service http:Service / on new http:Listener(9090) { } + //When validation is Successful, creates an OperationOutcome with a single + //custom FHIRIssueDetail and returns it. log:printDebug("Validation successful"); r4:FHIRIssueDetail issue = { severity: "information", diff --git a/miscellaneous/validator-service/service_utils.bal b/miscellaneous/validator-service/service_utils.bal new file mode 100644 index 0000000..7fa0e89 --- /dev/null +++ b/miscellaneous/validator-service/service_utils.bal @@ -0,0 +1,47 @@ +// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). +// WSO2 LLC. 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 + +import ballerinax/health.fhir.r4; +import ballerinax/health.fhir.r4.validator; + +# FHIR validation error details record. +# +# + issues - FHIR issues +public type FHIRValidationErrorDetail record { + *r4:FHIRErrorDetail; + [validator:FHIRValidationIssueDetail, validator:FHIRValidationIssueDetail...] issues; +}; + +isolated function issueDetailToOperationOutcomeIssue(r4:FHIRIssueDetail detail) returns r4:OperationOutcomeIssue { + + r4:OperationOutcomeIssue issueBBE = { + severity: detail.severity, + code: detail.code + }; + + (r4:CodeableConcept)? details = detail.details; + if details != () { + issueBBE.details = details; + } + + string? diagnostic = detail.diagnostic; + if diagnostic != () { + issueBBE.diagnostics = string `${diagnostic}`; + } + + string[]? expression = detail.expression; + if expression != () { + issueBBE.expression = expression; + } + + return issueBBE; +} From a6d8e932e05053b27ecb0a725d965b7f79fa46c7 Mon Sep 17 00:00:00 2001 From: Gevin Karunarathne Date: Wed, 13 Mar 2024 14:05:06 +0530 Subject: [PATCH 4/5] Update licence year --- miscellaneous/validator-service/service.bal | 2 +- miscellaneous/validator-service/service_utils.bal | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/miscellaneous/validator-service/service.bal b/miscellaneous/validator-service/service.bal index bf6b8f7..484d5b8 100644 --- a/miscellaneous/validator-service/service.bal +++ b/miscellaneous/validator-service/service.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). // WSO2 LLC. 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. diff --git a/miscellaneous/validator-service/service_utils.bal b/miscellaneous/validator-service/service_utils.bal index 7fa0e89..abc2f71 100644 --- a/miscellaneous/validator-service/service_utils.bal +++ b/miscellaneous/validator-service/service_utils.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). +// Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). // WSO2 LLC. 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. From 778f63ff4a13d22d848d9da19557d4893c578487 Mon Sep 17 00:00:00 2001 From: Gevin Karunarathne Date: Wed, 13 Mar 2024 14:36:01 +0530 Subject: [PATCH 5/5] Fixed issues --- .../validator-service/.devcontainer.json | 4 ---- miscellaneous/validator-service/.gitignore | 1 + miscellaneous/validator-service/Dependencies.toml | 2 +- miscellaneous/validator-service/service.bal | 15 ++++++++------- miscellaneous/validator-service/service_utils.bal | 4 ++++ 5 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 miscellaneous/validator-service/.devcontainer.json diff --git a/miscellaneous/validator-service/.devcontainer.json b/miscellaneous/validator-service/.devcontainer.json deleted file mode 100644 index b9c505b..0000000 --- a/miscellaneous/validator-service/.devcontainer.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "image": "ballerina/ballerina-devcontainer:2201.8.1", - "extensions": ["WSO2.ballerina"], -} diff --git a/miscellaneous/validator-service/.gitignore b/miscellaneous/validator-service/.gitignore index 7512ebe..39c9ccc 100644 --- a/miscellaneous/validator-service/.gitignore +++ b/miscellaneous/validator-service/.gitignore @@ -1,3 +1,4 @@ target generated Config.toml +.devcontainer.json diff --git a/miscellaneous/validator-service/Dependencies.toml b/miscellaneous/validator-service/Dependencies.toml index 854e2e2..72d4b3a 100644 --- a/miscellaneous/validator-service/Dependencies.toml +++ b/miscellaneous/validator-service/Dependencies.toml @@ -61,7 +61,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.10.8" +version = "2.10.10" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, diff --git a/miscellaneous/validator-service/service.bal b/miscellaneous/validator-service/service.bal index 484d5b8..d5d2249 100644 --- a/miscellaneous/validator-service/service.bal +++ b/miscellaneous/validator-service/service.bal @@ -15,7 +15,8 @@ import ballerina/log; import ballerinax/health.fhir.r4; import ballerinax/health.fhir.r4.validator; -configurable string[] CORS_ALLOWED_ORIGINS = ?; +// Configure the array below if you want to allow only specific origins +configurable string[] CORS_ALLOWED_ORIGINS = ["*"]; service http:Service / on new http:Listener(9090) { @@ -74,12 +75,12 @@ service http:Service / on new http:Listener(9090) { //custom FHIRIssueDetail and returns it. log:printDebug("Validation successful"); r4:FHIRIssueDetail issue = { - severity: "information", - code: "informational", - diagnostic: "Validation Successful", - expression: (), - details: () - }; + severity: "information", + code: "informational", + diagnostic: "Validation Successful", + expression: (), + details: () + }; r4:OperationOutcomeIssue opIssue = issueDetailToOperationOutcomeIssue(issue); r4:OperationOutcome opOutcome = { diff --git a/miscellaneous/validator-service/service_utils.bal b/miscellaneous/validator-service/service_utils.bal index abc2f71..1054d9d 100644 --- a/miscellaneous/validator-service/service_utils.bal +++ b/miscellaneous/validator-service/service_utils.bal @@ -21,6 +21,10 @@ public type FHIRValidationErrorDetail record { [validator:FHIRValidationIssueDetail, validator:FHIRValidationIssueDetail...] issues; }; +# This util function is used to convert FHIR validation error detail to FHIR OperationOutcome issue. +# +# + detail - FHIR validation error detail +# + return - FHIR OperationOutcome issue isolated function issueDetailToOperationOutcomeIssue(r4:FHIRIssueDetail detail) returns r4:OperationOutcomeIssue { r4:OperationOutcomeIssue issueBBE = {