One shell with the current look: indicators, follow-up list and patient view from FHIR; /conectar canvas; /revision; Playwright page tests

This commit is contained in:
Roberto Treviño
2026-11-25 10:21:30 -06:00
parent 70b6d6c646
commit cd7bbaf11a
70 changed files with 5459 additions and 182 deletions
+166
View File
@@ -0,0 +1,166 @@
import { Component } from '@angular/core';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { ReactiveFormsModule } from '@angular/forms';
import {
ConfigOption,
FieldArrayType,
FieldType,
FormlyField,
FormlyFieldConfig,
} from '@ngx-formly/core';
import type { JSONSchema7 } from 'json-schema';
type Schema = JSONSchema7 & { $defs?: Record<string, Schema>; prefixItems?: unknown };
/** The canvas edits these itself; the form leaves them out. */
const CANVAS_FIELDS = ['id', 'kind', 'inputs', 'position'];
/** A node kind's form schema from the pipeline's JSON Schema (pydantic's): `$ref`s inlined,
* optional values as their type, and maps or tuples (which forms don't draw) as JSON. */
export function nodeSchema(pipeline: Schema, kind: string): Schema {
const defs = pipeline.$defs ?? {};
const name = Object.keys(defs).find(
(k) => (defs[k].properties?.['kind'] as Schema | undefined)?.const === kind,
)!;
const node = structuredClone(defs[name]);
for (const field of CANVAS_FIELDS) delete node.properties?.[field];
node.required = (node.required ?? []).filter((f) => !CANVAS_FIELDS.includes(f));
delete node.additionalProperties;
return simplify(node, defs);
}
function simplify(schema: Schema, defs: Record<string, Schema>): Schema {
if (schema.$ref) {
const { $ref, ...rest } = schema;
return simplify({ ...structuredClone(defs[$ref.split('/').pop()!]), ...rest }, defs);
}
const options = schema.anyOf as Schema[] | undefined;
if (options) {
const kept = options.filter((o) => o.type !== 'null');
if (kept.length === 1) {
const { anyOf, ...rest } = schema;
return simplify({ ...kept[0], ...rest }, defs);
}
}
const isMap = schema.type === 'object' && !schema.properties;
const isTuple =
schema.type === 'array' &&
(schema.prefixItems || (schema.items as Schema | undefined)?.prefixItems);
if (isMap || isTuple || (!schema.type && !schema.enum && !schema.const)) {
return {
title: schema.title,
description: schema.description,
default: schema.default,
widget: { formlyConfig: { type: 'json' } },
} as Schema;
}
const out: Schema = { ...schema };
if (schema.properties) {
out.properties = Object.fromEntries(
Object.entries(schema.properties).map(([k, v]) => [k, simplify(v as Schema, defs)]),
);
}
if (schema.items && !Array.isArray(schema.items))
out.items = simplify(schema.items as Schema, defs);
return out;
}
/** An object's fields, one after another. */
@Component({
selector: 'app-formly-object',
imports: [FormlyField],
template: `
@if (props.label) {
<div class="legend">{{ props.label }}</div>
}
@if (props.description) {
<p class="hint">{{ props.description }}</p>
}
@for (f of field.fieldGroup; track $index) {
<formly-field [field]="f" />
}
`,
styles:
'.legend { font-weight: 500; margin: 8px 0 4px; } .hint { color: var(--color-text-secondary); font-size: 12px; margin: 0 0 8px; }',
})
export class ObjectType extends FieldType {}
/** A list: each item with a remove button, and an add button. */
@Component({
selector: 'app-formly-array',
imports: [FormlyField, MatButtonModule, MatIconModule],
template: `
<div class="legend">{{ props.label }}</div>
@for (f of field.fieldGroup; track $index; let i = $index) {
<div class="item">
<formly-field [field]="f" />
<button mat-icon-button type="button" (click)="remove(i)" aria-label="Quitar">
<mat-icon>close</mat-icon>
</button>
</div>
}
<button mat-stroked-button type="button" (click)="add()">
<mat-icon>add</mat-icon> Agregar
</button>
`,
styles:
'.legend { font-weight: 500; margin: 8px 0 4px; } .item { display: flex; align-items: flex-start; gap: 4px; } .item formly-field { flex: 1; }',
})
export class ArrayType extends FieldArrayType {}
/** A value forms don't draw (a map, a pair, anything), edited as JSON. */
@Component({
selector: 'app-formly-json',
imports: [MatFormFieldModule, MatInputModule, ReactiveFormsModule],
template: `
<mat-form-field appearance="outline" class="json">
<mat-label>{{ props.label }} (JSON)</mat-label>
<textarea
matInput
rows="4"
[value]="text()"
(change)="parse($any($event.target).value)"
></textarea>
@if (error) {
<mat-error>{{ error }}</mat-error>
}
@if (props.description) {
<mat-hint>{{ props.description }}</mat-hint>
}
</mat-form-field>
`,
styles: '.json { width: 100%; } textarea { font-family: monospace; font-size: 12px; }',
})
export class JsonType extends FieldType<FormlyFieldConfig> {
protected error = '';
protected text(): string {
return this.formControl.value === undefined
? ''
: JSON.stringify(this.formControl.value, null, 1);
}
protected parse(value: string): void {
try {
this.formControl.setValue(value.trim() ? JSON.parse(value) : undefined);
this.formControl.markAsDirty();
this.error = '';
} catch {
this.error = 'No es JSON válido';
}
}
}
export const FORMLY_TYPES: ConfigOption = {
types: [
{ name: 'object', component: ObjectType },
{ name: 'array', component: ArrayType },
{ name: 'json', component: JsonType },
{ name: 'enum', extends: 'select' },
{ name: 'string', extends: 'input' },
{ name: 'number', extends: 'input', defaultOptions: { props: { type: 'number' } } },
{ name: 'integer', extends: 'input', defaultOptions: { props: { type: 'number' } } },
{ name: 'boolean', extends: 'checkbox' },
],
};