Development environment for building and testing Vue 3 forms that integrate with the iChart EMR system. Forms are loaded dynamically at runtime and communicate with the iChart backend API.
- Node.js 18+ (LTS recommended)
- npm 9+
- Access to an iChart backend (for API calls during development)
- jQuery and Select2 — place
jquery.min.jsandselect2.full.min.jsinsrc/js/(required bymain.js)
npm installThis installs:
| Package | Purpose |
|---|---|
vue |
Vue 3 framework |
vue3-sfc-loader |
Runtime compiler for remote .vue forms |
bootstrap |
UI styling |
moment |
Date/time formatting |
vite |
Dev server and build tool |
@vitejs/plugin-vue |
Vue SFC support |
Run the dev server and a production preview in two separate terminals.
npm run devStarts Vite on http://0.0.0.0:5173 (accessible on your local network). Hot reload is enabled.
npm run build
npm run previewnpm run build— bundles the app intodist/npm run preview— serves the production build locally for verification
The app includes TestForm.vue, a form loader for local development.
- Open the dev server URL in a browser.
- Click a local file chip (
test.vue,test.js,default.js) or paste a path and press โหลดฟอร์ม. - Switch กรอกฟอร์ม / พิมพ์. Press Enter in the path field to reload.
- Set VID to load patient data from the API. Last path, mode, and VID are remembered.
Example paths:
/test/test.vue
/test/default.js
/test/test.js
/รพ-ราชบุรี/dischargeSummary.js
Note: Form paths starting with
/รพ-*are served from the iChart backend in production. During local dev you may need a Vite proxy or to place form files underpublic/.
API calls use a Bearer token from localStorage.userdata. Before testing, set user data in the browser console:
localStorage.setItem('userdata', JSON.stringify({
Token: 'your-jwt-token',
FirstName: 'ชื่อ',
LastName: 'นามสกุล',
RID: 1
}))Optional permissions:
localStorage.setItem('Permission', JSON.stringify([
{ Name: 'permissionname', RID: 1, Correction: true }
]))Each form is a Vue options component exported as default from a .js or .vue file.
.js— options object with atemplatestring (legacy / iChart Form Builder).vue— Single File Component (<template>+<script>). Local files are compiled by Vite. Remote.vuefiles are compiled at runtime withvue3-sfc-loader.
See test/test.vue for a working SFC example. Forms should keep the Options API so setdata / savedata / loaddata remain callable by the host.
<template>
<div class="bg-white">
<div v-if="mode == 'form'">
<!-- editable form UI -->
</div>
<div v-if="mode == 'print'">
<!-- print layout -->
</div>
</div>
</template>
<script>
export default {
data() {
return {
val: {}
}
},
props: {
mode: '',
visitid: '',
rid: '',
formdataid: undefined,
PatientAccess_RID: '',
cuserid: '',
formtype: '',
vid: '',
},
mounted() {
this.loaddata()
},
methods: {
setdata(d) { /* load saved form data */ },
loaddata() { /* fetch patient / hospital data */ },
savedata() { /* create new record */ },
updatedata() { /* update existing record */ },
}
}
</script>export default {
template: `
<div class="bg-white">
<div v-if="mode == 'form'">
<!-- editable form UI -->
</div>
<div v-if="mode == 'print'">
<!-- print layout -->
</div>
</div>
`,
data() {
return {
val: {} // all form field values go here
}
},
props: {
mode: '', // 'form' | 'print'
visitid: '',
rid: '', // form builder ID
formdataid: undefined, // existing saved record ID (undefined = new)
PatientAccess_RID: '',
cuserid: '',
formtype: '',
vid: '', // visit ID
},
mounted() {
this.loaddata()
},
methods: {
setdata(d) { /* load saved form data */ },
loaddata() { /* fetch patient / hospital data */ },
savedata() { /* create new record */ },
updatedata() { /* update existing record */ },
}
}See test/default.js for a complete working example with Select2 and API integration.
| Prop | Type | Description |
|---|---|---|
mode |
string |
'form' or 'print' |
visitid |
string |
Visit identifier |
rid |
string |
Form builder ID |
formdataid |
number | undefined |
Saved form data ID; undefined means new record |
PatientAccess_RID |
string |
Patient access record ID |
cuserid |
string |
Current user ID |
formtype |
string |
Form type identifier |
vid |
string |
Visit ID used for patient lookup |
| Method | When called | Purpose |
|---|---|---|
setdata(d) |
Host loads saved data | Populate val from stored FormDB JSON |
loaddata() |
mounted |
Fetch hospital info, patient visit, vitals |
savedata() |
Save button click | POST new record to /api/formdatas/ |
updatedata() |
Save button click (existing) | PUT update to /api/FormDatas/updateForm |
On successful save, emit formsaved with the API response:
this.$emit('formsaved', res)Create (formdataid is undefined):
{
FormDB: JSON.stringify(this.val),
Formbuilder_RID: this.rid,
Owner_RID: this.cuserid,
CreateByID: this.cuserid,
Type: this.formtype,
Visit_RID: this.vid,
DateUpdate: moment().format('YYYY-MM-DDtHH:mm:ss'),
}Update (formdataid is set):
{
FormDB: JSON.stringify(this.val),
RID: this.formdataid,
UserEdit_RID: this.cuserid,
}| Endpoint | Method | Purpose |
|---|---|---|
/api/OPDCard/loadhospitalinformation |
POST | Hospital name |
/api/VisitDatas/Searchpatientvisit |
POST | Patient visit data |
/api/EMR/loadopdscreenprogress |
POST | CC, HPI from OPD screen |
/api/formdatas/ |
POST | Create form data |
/api/FormDatas/updateForm |
PUT | Update form data |
/api/UserDatas/SearchAll |
POST | User/doctor search (Select2) |
Imported in main.js and exposed on window:
| Function | Description |
|---|---|
CallWebAPI(url, data, method, callback) |
Authenticated fetch wrapper |
moment |
Date formatting library |
toDateString(date, format?) |
Thai locale date string |
toDateTimeString(date, format?) |
Thai locale date + time |
toTimeString(date, format?) |
Time string |
getAgeYMD(bdate, sdate?) |
Age as years/months/days (Thai) |
getYearAge(bdate, sdate?) |
Age in years only |
getGender(code) |
M → ชาย, F → หญิง |
getBathText(number) |
Number to Thai baht text |
getpermission(...names) |
Check user permissions |
OpenLoading / CloseLoading |
Bootstrap modal loading |
CallConfirmBox(callback) |
Confirmation dialog |
Helper methods are also injected into loaded form components by TestForm.vue:
toDateString, toDateTimeString, toTimeString, getAgeYMD, getYearAge, moment
Registered globally as <select2>. Used for AJAX search dropdowns:
<select2
v-model="val.phyname"
:url="'/api/UserDatas/SearchAll'"
minlen="1"
sendpropname="kw"
:processresult="processsearchphyresutl"
ref="searchadmisowner"
/>| Prop | Description |
|---|---|
url |
API endpoint |
minlen |
Minimum characters before search |
sendpropname |
JSON property name for search term (default: term) |
processresult |
Transform API response to { id, text }[] |
processrequest |
Transform search term before sending |
selectedcallback |
Called on selection |
Use this.$refs.searchadmisowner.setRawvalue(value) in setdata() to restore a saved selection.
ichart-form/
├── index.html # Entry HTML
├── vite.config.js # Vite config (host: 0.0.0.0)
├── package.json
├── src/
│ ├── main.js # App bootstrap, global imports
│ ├── App.vue # Root component
│ ├── Commonfunction.js # Shared utilities (CallWebAPI, dates, etc.)
│ ├── formLoader.ts # Dynamic .js / .vue form loader
│ ├── style.css # Global styles
│ ├── adminlte.min.css # AdminLTE theme
│ ├── components/
│ │ ├── TestForm.vue # Dev form loader
│ │ ├── Select2.vue # AJAX select dropdown
│ │ └── HelloWorld.vue
│ ├── fontawesome-pro/ # Font Awesome Pro icons
│ └── js/ # jQuery, Select2 (add manually)
├── test/
│ ├── default.js # Example form with Select2
│ ├── test.js # Example form (JS module)
│ └── test.vue # Example form (Vue SFC)
└── dist/ # Production build output
npm run buildOutput is written to dist/. Deploy this folder to your web server or integrate form .js files into the iChart Form Builder.
In production, forms are typically served from:
/api/FormBuilders/vue/getform/{Formbuilder_RID}
or hospital-specific paths such as /รพ-{hospital}/{formName}.js or /รพ-{hospital}/{formName}.vue.
| Command | Description |
|---|---|
npm run dev |
Start Vite dev server with HMR |
npm run build |
Production build to dist/ |
npm run preview |
Preview production build locally |