Inserting openEHR Data with SQL in TypeScript
We use the pg library to connect to the database:
import { Client } from 'pg'
const client = await new Client({database: 'arcehr', port: 5432, user: 'root', password: 'arcadedb'}).connect()
Inserting openEHR data with SQL INSERT statement:
// Insert a new composition
const content = {
archetype_node_id: 'openEHR-EHR-COMPOSITION.encounter.v1',
name: {value: 'Vital Signs'},
uid: {_type: 'OBJECT_VERSION_ID', value: '8849182c::openEHRSys.example.com::1'},
archetype_details: {
archetype_id: {value: 'openEHR-EHR-COMPOSITION.encounter.v1'},
template_id: {value: 'Example.v1::c7ec861c-c413-39ff-9965-a198ebf44747'},
rm_version: '1.0.2',
},
language: {terminology_id: { value: 'ISO_639-1' }, code_string: 'en'},
content: [{ _type: 'OBSERVATION' }]
}
const insert = `INSERT INTO create_composition (ehr_id, content) VALUES ($1, $2)`
await client.query(insert, ['ehr-1', content])
Result:
{
ehr_id: 'ehr-1',
content: '{"archetype_node_id":"openEHR-EHR-COMPOSITION.encounter.v1","name":{"value":"Vital Signs"},"uid":{"_type":"OBJECT_VERSION_ID","value":"8849182c::openEHRSys.example.com::1"},"archetype_details":{"archetype_id":{"value":"openEHR-EHR-COMPOSITION.encounter.v1"},"template_id":{"value":"Example.v1::c7ec861c-c413-39ff-9965-a198ebf44747"},"rm_version":"1.0.2"},"language":{"terminology_id":{"value":"ISO_639-1"},"code_string":"en"},"content":[{"_type":"COMPOSITION"}]}',
prefer: 'return=minimal',
content_type: null,
accept: null,
'@rid': '#72:1'
}