Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
458 changes: 231 additions & 227 deletions apps/docs/static/loco.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default [
'**/vite.config.*.timestamp*',
'**/vitest.config.*.timestamp*',
'apps/demo/public/**',
'apps/docs/static/**',
],
},
{
Expand Down
Empty file added index
Empty file.
17 changes: 16 additions & 1 deletion packages/adapters/src/fhir/fhir-adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,22 @@ describe('mapFhirTypeToEsheet', () => {

it('maps attachment to diagram by default', () => {
const result = mapFhirTypeToEsheet('attachment', makeItem('attachment'));
expect(result.fieldType).toBe('diagram');
expect(result.fieldType).toBe('file');
});

it('maps open-choice itemControl to openchoice field', () => {
const result = mapFhirTypeToEsheet(
'choice',
makeItem('choice', {
extension: [
{
url: FHIR_EXT.ITEM_CONTROL,
valueCodeableConcept: { coding: [{ code: 'open-choice' }] },
},
],
})
);
expect(result.fieldType).toBe('openchoice');
});

it('maps attachment with signatureRequired to signature', () => {
Expand Down
67 changes: 63 additions & 4 deletions packages/adapters/src/fhir/fhir-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,13 @@ function extractSingleAnswerValue(answer: FhirResponseAnswer): unknown {
if (answer.valueUri !== undefined) return answer.valueUri;
if (answer.valueCoding) return answer.valueCoding.code;
if (answer.valueQuantity) return answer.valueQuantity.value;
if (answer.valueAttachment) return answer.valueAttachment.data;
if (answer.valueAttachment)
return {
data: answer.valueAttachment.data,
contentType: answer.valueAttachment.contentType,
title: answer.valueAttachment.title,
url: answer.valueAttachment.url,
};
if (answer.valueReference) return answer.valueReference.reference;

return undefined;
Expand Down Expand Up @@ -731,6 +737,47 @@ function convertValueToAnswers(
},
];

case 'file': {
// value may be a string (base64) or an object with data/dataUrl/contentType/title
if (typeof value === 'string') {
return [
{
valueAttachment: {
contentType: 'application/octet-stream',
data: value,
},
},
];
}

const v = value as {
data?: string;
dataUrl?: string;
contentType?: string;
title?: string;
};
let dataBase64: string | undefined = undefined;
let contentType = v.contentType ?? 'application/octet-stream';
if (v.data) dataBase64 = v.data;
else if (v.dataUrl) {
const comma = v.dataUrl.indexOf(',');
dataBase64 = comma >= 0 ? v.dataUrl.slice(comma + 1) : v.dataUrl;
const prefix = v.dataUrl.slice(0, comma);
const m = prefix.match(/data:([^;]+)/);
if (m && m[1]) contentType = m[1];
}

return [
{
valueAttachment: {
contentType,
data: dataBase64,
title: v.title,
},
},
];
}

default:
return [{ valueString: String(value) }];
}
Expand Down Expand Up @@ -758,15 +805,27 @@ function convertTextAnswer(

function createCodingAnswer(
field: FieldDefinition,
selectedId: string
selectedIdOrObj: string | { id?: string; value?: string }
): FhirResponseAnswer {
const options = 'options' in field ? field.options : undefined;
const selectedId =
typeof selectedIdOrObj === 'string'
? selectedIdOrObj
: selectedIdOrObj.id ?? String(selectedIdOrObj.value ?? '');
const option = options?.find((o: FieldOption) => o.id === selectedId);

return {
valueCoding: {
code: option?.value ?? selectedId,
display: option?.text,
code:
option?.value ??
(typeof selectedIdOrObj === 'string'
? selectedIdOrObj
: selectedIdOrObj.value ?? selectedId),
display:
option?.text ??
(typeof selectedIdOrObj === 'object'
? selectedIdOrObj.value
: undefined),
},
};
}
12 changes: 11 additions & 1 deletion packages/adapters/src/fhir/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export function mapFhirTypeToEsheet(
if (hasSignatureRequired(item.extension)) {
return { fieldType: 'signature' };
}
return { fieldType: 'diagram' };
return { fieldType: 'file' };

case 'reference':
return { fieldType: 'text', subType: 'reference' };
Expand All @@ -181,6 +181,10 @@ function mapChoiceType(
: { fieldType: 'dropdown' };
}

if (itemControl === 'open-choice') {
return { fieldType: 'openchoice' };
}

if (itemControl === 'check-box') {
return { fieldType: 'check' };
}
Expand Down Expand Up @@ -251,6 +255,12 @@ export function mapEsheetTypeToFhir(
case 'diagram':
return { type: 'attachment' };

case 'file':
return { type: 'attachment' };

case 'openchoice':
return { type: 'choice', itemControl: 'open-choice' };

case 'singlematrix':
case 'multimatrix':
return { type: 'group' };
Expand Down
33 changes: 33 additions & 0 deletions packages/builder/src/lib/components/edit-panel/LogicEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,34 @@ function ExpectedValueInput({
}
}

// OpenChoice fields include predefined options plus a special "{fieldId}-other" option.
if (target?.fieldType === 'openchoice') {
if (
operator === 'equals' ||
operator === 'notEquals' ||
operator === 'includes'
) {
const otherOptionId = `${target.id}-other`;
return (
<select
id={`${idPrefix}-expected`}
aria-label="Expected value"
value={expected}
onChange={(e) => onUpdate({ expected: e.currentTarget.value })}
className="condition-expected ms:w-full ms:min-w-0 ms:px-2 ms:py-1.5 ms:text-xs ms:bg-mssurface ms:border ms:border-msborder ms:rounded ms:text-mstext ms:focus:outline-none ms:focus:ring-1 ms:focus:ring-msprimary ms:cursor-pointer"
>
<option value="">Select a value…</option>
{target.options?.map((opt) => (
<option key={opt.id} value={opt.id}>
{opt.value}
</option>
))}
<option value={otherOptionId}>Other</option>
</select>
);
}
}

// If target has options and we're using equals/notEquals/includes,
// show a dropdown of option values
if (target?.hasOptions && target.options && target.options.length > 0) {
Expand Down Expand Up @@ -1169,6 +1197,11 @@ function getOperatorsForTarget(target: TargetField): ConditionOperator[] {
return ['empty', 'notEmpty'];
}

// Media answers (file, signature, diagram) — only presence checks are meaningful.
if (answerType === 'media') {
return ['empty', 'notEmpty'];
}

// Single-value selection fields (radio/dropdown/boolean etc.).
if (answerType === 'selection') {
const ops: ConditionOperator[] = [
Expand Down
4 changes: 4 additions & 0 deletions packages/builder/src/lib/register-defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
MultiTextField,
RadioField,
CheckField,
OpenChoiceField,
BooleanField,
DropdownField,
MultiSelectDropdownField,
Expand All @@ -28,6 +29,7 @@ import {
ImageField,
HtmlField,
DisplayField,
FileField,
} from '@esheet/fields';

let defaultFieldComponentsRegistered = false;
Expand All @@ -41,6 +43,7 @@ export function ensureDefaultFieldComponentsRegistered(): void {
multitext: MultiTextField,
radio: RadioField,
check: CheckField,
openchoice: OpenChoiceField,
boolean: BooleanField,
dropdown: DropdownField,
multiselectdropdown: MultiSelectDropdownField,
Expand All @@ -53,6 +56,7 @@ export function ensureDefaultFieldComponentsRegistered(): void {
signature: SignatureField,
diagram: DiagramField,
image: ImageField,
file: FileField,
html: HtmlField,
display: DisplayField,
});
Expand Down
3 changes: 0 additions & 3 deletions packages/builder/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
},
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ export {
type BooleanFieldDefinition,
type DropdownFieldDefinition,
type MultiselectDropdownFieldDefinition,
type OpenChoiceFieldDefinition,
type RatingFieldDefinition,
type RankingFieldDefinition,
type SliderFieldDefinition,
type SingleMatrixFieldDefinition,
type MultiMatrixFieldDefinition,
type ImageFieldDefinition,
type FileFieldDefinition,
type HtmlFieldDefinition,
type SignatureFieldDefinition,
type DiagramFieldDefinition,
Expand Down
9 changes: 6 additions & 3 deletions packages/core/src/lib/functions/hydrate-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,12 @@ function extractAnswer(
response.signatureData ??
response.markupImage ??
response.markupData;
if (!dataUrl) return undefined;
const result: AttachmentAnswer = { contentType: 'image/png', dataUrl };
return result;
if (dataUrl) {
const result: AttachmentAnswer = { contentType: 'image/png', dataUrl };
return result;
}
// File fields store data in fileData with their actual contentType
return response.fileData;
}
default:
return undefined;
Expand Down
Loading
Loading