This is the Groovy reference implementation of the openEHR REST Client for connecting to openEHR REST API implementations.
It compiles to Java bytecode so it can be used as any Java library with any language that compiles to the JVM.
$ gradle build
It generates a JAR file in the build/libs
folder.
$ gradle test --tests "OpenEhrRestClientTest.create demographic family trees"
$ gradle test --tests "OpenEhrRestClientTest.B*4*a* get composition at version"
$ gradle test --tests "OpenEhrRestClientTest.B*4*"
// Setup authentication using a token
def token = "abc...."
def auth = new TokenAuth(token)
// Build the client
def client = new OpenEhrRestClient(
"http://localhost:8090/openehr/v1",
auth,
ContentTypeEnum.JSON
)
// Set committer metadata headers
client.setCommitterHeader('name="John Doe", external_ref.id="BC8132EA-8F4A-11E7-BB31-BE2E44B06B34", external_ref.namespace="demographic", external_ref.type="PERSON"')
// Upload EHR_STATUS template
String opt = this.getClass().getResource('/ehr_status_any_en_v1.opt').text
client.uploadTemplate(opt)
// Create EHR
client.createEhr()
// Commit a clinical document
// - Upload template for clinical document
// - Get sample document, parse it into a COMPOSITION, commit the COMPOSITION
String opt1 = this.getClass().getResource('/minimal_evaluation.opt').text
client.uploadTemplate(opt1)
String json_doc = this.getClass().getResource('/minimal_evaluation.en.v1_20230205.json').text
def parser = new OpenEhrJsonParserQuick()
def doc = parser.parseJson(json_doc)
client.createComposition(ehr.ehr_id.value, doc)