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
+81
View File
@@ -0,0 +1,81 @@
import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
import type { Bundle, CodeableConcept, Extension, FhirResource } from 'fhir/r4';
import { firstValueFrom } from 'rxjs';
import { ApiConfiguration } from './api/api-configuration';
/** Our extensions and code systems (core.fhir). */
export const EXT = 'https://isssteleon.org/fhir/StructureDefinition/';
export type Params = Record<string, string | number | readonly (string | number)[] | undefined>;
/** The domain's FHIR base (`/{domain}/fhir`): reads and searches, typed as R4. */
@Injectable({ providedIn: 'root' })
export class Fhir {
private readonly http = inject(HttpClient);
private readonly root = inject(ApiConfiguration).rootUrl;
read<T extends FhirResource>(domain: string, type: T['resourceType'], id: string): Promise<T> {
return firstValueFrom(this.http.get<T>(`${this.root}/${domain}/fhir/${type}/${id}`));
}
/** One page of a search. */
search(domain: string, type: string, params: Params = {}): Promise<Bundle> {
const query = Object.fromEntries(
Object.entries(params).filter(([, v]) => v !== undefined),
) as Record<string, string | number | readonly (string | number)[]>;
return firstValueFrom(
this.http.get<Bundle>(`${this.root}/${domain}/fhir/${type}`, { params: query }),
);
}
/** The page a bundle's `next` (or `previous`) link points to, through our own base. */
follow(domain: string, bundle: Bundle, relation: 'next' | 'previous'): Promise<Bundle> | null {
const link = bundle.link?.find((l) => l.relation === relation)?.url;
if (!link) return null;
const url = new URL(link);
const type = url.pathname.split('/').pop();
return firstValueFrom(
this.http.get<Bundle>(`${this.root}/${domain}/fhir/${type}${url.search}`),
);
}
/** Every page of a search. */
async all(domain: string, type: string, params: Params = {}): Promise<Bundle[]> {
const pages = [await this.search(domain, type, params)];
for (let next = this.follow(domain, pages[0], 'next'); next;) {
const page = await next;
pages.push(page);
next = this.follow(domain, page, 'next');
}
return pages;
}
}
/** The resources of a bundle (or of several pages), by search mode. */
export function resources<T extends FhirResource>(
bundles: Bundle | Bundle[],
type: T['resourceType'],
mode?: 'match' | 'include',
): T[] {
return [bundles]
.flat()
.flatMap((b) => b.entry ?? [])
.filter((e) => e.resource?.resourceType === type && (!mode || e.search?.mode === mode))
.map((e) => e.resource as T);
}
export function ext(
element: { extension?: Extension[] } | undefined,
name: string,
): Extension | undefined {
return element?.extension?.find((e) => e.url === EXT + name);
}
export function code(concept: CodeableConcept | undefined): string | undefined {
return concept?.coding?.[0]?.code;
}
export function label(concept: CodeableConcept | undefined): string {
return concept?.text ?? concept?.coding?.[0]?.display ?? concept?.coding?.[0]?.code ?? '';
}