From 9b026418045597c869c34c6647b7813f829cf459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Trevi=C3=B1o?= Date: Wed, 25 Nov 2026 16:17:23 -0600 Subject: [PATCH] ConceptMap editor, names and CURP shown, catalog codes read --- e2e/pages.spec.ts | 17 +- openapi.json | 465 ++++++++++++++++++++-- src/app/api/fn/fhir/post-bundle.ts | 44 ++ src/app/api/fn/fhir/search-encounter.ts | 44 ++ src/app/api/fn/ingest/concept-maps.ts | 33 ++ src/app/api/fn/ingest/get-concept-map.ts | 35 ++ src/app/api/fn/ingest/save-concept-map.ts | 39 ++ src/app/api/fn/review/conflicts.ts | 2 +- src/app/api/fn/review/held.ts | 2 +- src/app/api/functions.ts | 10 + src/app/api/models.ts | 1 + src/app/api/models/correction.ts | 2 +- src/app/api/models/extract.ts | 12 +- src/app/api/models/fhir.ts | 20 + src/app/api/models/map.ts | 9 +- src/app/api/models/pipeline.ts | 3 +- src/app/api/models/rejection.ts | 2 +- src/app/api/models/target.ts | 2 +- src/app/conectar/concept-map-editor.ts | 164 ++++++++ src/app/conectar/conectar.html | 3 + src/app/conectar/conectar.ts | 7 + src/app/indicadores/follow-up.ts | 22 +- src/app/indicadores/tab-riesgos.html | 7 +- src/app/indicadores/tab-riesgos.scss | 6 +- src/app/paciente/paciente.html | 10 +- src/app/paciente/paciente.ts | 26 +- src/app/revision/revision.ts | 1 - 27 files changed, 901 insertions(+), 87 deletions(-) create mode 100644 src/app/api/fn/fhir/post-bundle.ts create mode 100644 src/app/api/fn/fhir/search-encounter.ts create mode 100644 src/app/api/fn/ingest/concept-maps.ts create mode 100644 src/app/api/fn/ingest/get-concept-map.ts create mode 100644 src/app/api/fn/ingest/save-concept-map.ts create mode 100644 src/app/api/models/fhir.ts create mode 100644 src/app/conectar/concept-map-editor.ts diff --git a/e2e/pages.spec.ts b/e2e/pages.spec.ts index 785c5ff..de21c12 100644 --- a/e2e/pages.spec.ts +++ b/e2e/pages.spec.ts @@ -36,15 +36,16 @@ test("indicators: the KPIs are the API's MeasureReports, every tab and the patie const list = page.waitForResponse((r) => r.url().includes('/fhir/Patient?')); await page.getByRole('tab', { name: 'Análisis de riesgos' }).click(); const bundle = await (await list).json(); - const first = bundle.entry.find((e: any) => e.search.mode === 'match').resource.id; + const patient = bundle.entry.find((e: any) => e.search.mode === 'match').resource; + const first = patient.name?.[0]?.text ?? patient.id.slice(0, 10); const rows = page.locator('table.worklist tbody tr'); await expect(rows).toHaveCount(Math.min(20, bundle.total)); - await expect(rows.first().locator('a.id')).toHaveText(first.slice(0, 10)); + await expect(rows.first().locator('a').first()).toHaveText(first); await page.getByRole('button', { name: 'Siguiente' }).click(); await expect(page.getByText(`21–`)).toBeVisible(); await page.getByRole('button', { name: 'Anterior' }).click(); - await rows.first().locator('a.id').click(); + await rows.first().locator('a').first().click(); await expect(page.getByText('Historial médico')).toBeVisible(); await expect(page.getByText('Pruebas y resultados')).toBeVisible(); await expect( @@ -67,6 +68,16 @@ test('conectar: open the hospital pipeline, preview a source, run it to success' await expect(page.locator('formly-form')).toBeVisible(); await page.getByRole('button', { name: 'Vista previa' }).click(); await expect(page.locator('.preview tr[mat-row]').first()).toBeVisible(); + // A map node shows the site's codes in platform terms (its ConceptMap), editable as rows. + await page.getByText('Mapear · cytology', { exact: true }).click(); + await expect(page.getByText('Códigos del sitio')).toBeVisible(); + await expect + .poll(() => + page + .locator('app-concept-map-editor input') + .evaluateAll((els) => els.map((e) => (e as HTMLInputElement).value)), + ) + .toContain('LIEAG'); await page.getByRole('button', { name: 'Ejecutar' }).click(); await expect(page.getByText('SUCCESS')).toBeVisible({ timeout: 10 * 60_000 }); expect(problems).toEqual([]); diff --git a/openapi.json b/openapi.json index 03fdd2b..0b2e913 100644 --- a/openapi.json +++ b/openapi.json @@ -67,8 +67,7 @@ "curp", "nss", "birth_date", - "sex", - "postal_code" + "sex" ], "title": "Field", "type": "string" @@ -101,21 +100,34 @@ }, "Extract": { "additionalProperties": false, - "description": "Platform fields read from text, each kept with the text it was read from.\n\n`auto` asks the LLM when one is configured and answering, else applies `patterns`;\nwith neither, the row is held. Patterns are regexes with one group, per field (the\nLLM can propose them from sample documents); their values go through `values` and\n`formats` as in `map`.", + "description": "Platform fields read from text, each kept with the text it was read from.\n\n`auto` asks the LLM when one is configured and answering, else applies `patterns`;\nwith neither, the row is held. Patterns are regexes with one group, per field (the\nLLM can propose them from sample documents); their values go through the ConceptMap\nand `formats` as in `map`.", "properties": { "column": { "title": "Column", "type": "string" }, + "concept_map": { + "anyOf": [ + { + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Concept Map" + }, "entity": { "enum": [ "identity", - "death", - "clinical_note", "cervical_cytology", "cervical_biopsy", "mammography", - "breast_biopsy" + "breast_biopsy", + "clinical_note", + "death" ], "title": "Entity", "type": "string" @@ -187,17 +199,6 @@ "type": "null" } ] - }, - "values": { - "additionalProperties": { - "additionalProperties": { - "type": "string" - }, - "type": "object" - }, - "default": {}, - "title": "Values", - "type": "object" } }, "required": [ @@ -208,6 +209,86 @@ "title": "Extract", "type": "object" }, + "Fhir": { + "additionalProperties": false, + "description": "FHIR R4 Bundles a standard hospital sent (a column of their JSON) as rows of one\nentity: identity, death or a study (core.fhir_in). The sender's own codes go through\nits ConceptMap.", + "properties": { + "column": { + "default": "doc", + "title": "Column", + "type": "string" + }, + "concept_map": { + "anyOf": [ + { + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Concept Map" + }, + "entity": { + "enum": [ + "identity", + "cervical_cytology", + "cervical_biopsy", + "mammography", + "breast_biopsy", + "clinical_note", + "death" + ], + "title": "Entity", + "type": "string" + }, + "id": { + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "title": "Id", + "type": "string" + }, + "inputs": { + "default": [], + "items": { + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "type": "string" + }, + "title": "Inputs", + "type": "array" + }, + "kind": { + "const": "fhir", + "default": "fhir", + "title": "Kind", + "type": "string" + }, + "label": { + "default": "", + "title": "Label", + "type": "string" + }, + "position": { + "anyOf": [ + { + "$ref": "#/components/schemas/Position" + }, + { + "type": "null" + } + ] + } + }, + "required": [ + "id", + "entity" + ], + "title": "Fhir", + "type": "object" + }, "HTTPValidationError": { "properties": { "detail": { @@ -376,8 +457,21 @@ }, "Map": { "additionalProperties": false, - "description": "Columns to platform fields, with the site's codes and date formats.", + "description": "Columns to platform fields, the site's codes translated by its ConceptMap\n(core.concept_map), and its date formats.", "properties": { + "concept_map": { + "anyOf": [ + { + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "type": "string" + }, + { + "type": "null" + } + ], + "title": "Concept Map" + }, "fields": { "additionalProperties": { "type": "string" @@ -429,17 +523,6 @@ "type": "null" } ] - }, - "values": { - "additionalProperties": { - "additionalProperties": { - "type": "string" - }, - "type": "object" - }, - "default": {}, - "title": "Values", - "type": "object" } }, "required": [ @@ -479,6 +562,7 @@ "discriminator": { "mapping": { "extract": "#/components/schemas/Extract", + "fhir": "#/components/schemas/Fhir", "join": "#/components/schemas/Join", "link": "#/components/schemas/Link", "map": "#/components/schemas/Map", @@ -505,6 +589,9 @@ { "$ref": "#/components/schemas/Extract" }, + { + "$ref": "#/components/schemas/Fhir" + }, { "$ref": "#/components/schemas/Join" }, @@ -602,12 +689,12 @@ "entity": { "enum": [ "identity", - "death", - "clinical_note", "cervical_cytology", "cervical_biopsy", "mammography", - "breast_biopsy" + "breast_biopsy", + "clinical_note", + "death" ], "title": "Entity", "type": "string" @@ -837,12 +924,12 @@ "entity": { "enum": [ "identity", - "death", - "clinical_note", "cervical_cytology", "cervical_biopsy", "mammography", - "breast_biopsy" + "breast_biopsy", + "clinical_note", + "death" ], "title": "Entity", "type": "string" @@ -1052,6 +1139,139 @@ "summary": "Health" } }, + "/ingest/concept-maps": { + "get": { + "description": "Every ConceptMap a site saved: its id, latest version and when.", + "operationId": "concept_maps", + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "items": { + "additionalProperties": true, + "type": "object" + }, + "title": "Response Concept Maps", + "type": "array" + } + } + }, + "description": "Successful Response" + } + }, + "summary": "Concept Maps", + "tags": [ + "ingest" + ] + } + }, + "/ingest/concept-maps/{map_id}": { + "get": { + "description": "A site's codes in platform terms (FHIR R4B ConceptMap), latest version.", + "operationId": "get_concept_map", + "parameters": [ + { + "in": "path", + "name": "map_id", + "required": true, + "schema": { + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "title": "Map Id", + "type": "string" + } + } + ], + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "additionalProperties": true, + "title": "Response Get Concept Map", + "type": "object" + } + } + }, + "description": "Successful Response" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "summary": "Get Concept Map", + "tags": [ + "ingest" + ] + }, + "put": { + "description": "Saves a new version of a ConceptMap. Its groups target the systems platform fields\ntake codes from, and only codes those fields allow (core.concept_map).", + "operationId": "save_concept_map", + "parameters": [ + { + "in": "path", + "name": "map_id", + "required": true, + "schema": { + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "title": "Map Id", + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "additionalProperties": true, + "title": "Doc", + "type": "object" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "additionalProperties": { + "type": "integer" + }, + "title": "Response Save Concept Map", + "type": "object" + } + } + }, + "description": "Successful Response" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "summary": "Save Concept Map", + "tags": [ + "ingest" + ] + } + }, "/ingest/pipelines": { "get": { "operationId": "pipelines", @@ -1139,7 +1359,7 @@ ] }, "put": { - "description": "Saves a new version. Masked secrets sent back are kept as they were saved.", + "description": "Saves a new version. Masked secrets sent back are kept as they were saved; every\nConceptMap a node names must exist.", "operationId": "save_pipeline", "parameters": [ { @@ -1852,12 +2072,12 @@ "schema": { "enum": [ "identity", - "death", - "clinical_note", "cervical_cytology", "cervical_biopsy", "mammography", - "breast_biopsy" + "breast_biopsy", + "clinical_note", + "death" ], "title": "Entity", "type": "string" @@ -1955,12 +2175,12 @@ "schema": { "enum": [ "identity", - "death", - "clinical_note", "cervical_cytology", "cervical_biopsy", "mammography", - "breast_biopsy" + "breast_biopsy", + "clinical_note", + "death" ], "title": "Entity", "type": "string" @@ -2200,6 +2420,77 @@ ] } }, + "/{domain}/fhir": { + "post": { + "description": "A standard hospital's Bundle: checked as FHIR, kept as sent in the sender's inbox,\nand placed by the sender's pipeline (a run starts; follow it at the Location).", + "operationId": "post_bundle", + "parameters": [ + { + "in": "path", + "name": "domain", + "required": true, + "schema": { + "$ref": "#/components/schemas/Domain" + } + }, + { + "description": "the sender's pipeline (its fhir nodes read this inbox)", + "in": "query", + "name": "sender", + "required": true, + "schema": { + "description": "the sender's pipeline (its fhir nodes read this inbox)", + "maxLength": 40, + "pattern": "^[a-z][a-z0-9_]*$", + "title": "Sender", + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "additionalProperties": true, + "description": "a FHIR R4 batch or transaction Bundle", + "title": "Bundle", + "type": "object" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/fhir+json": { + "schema": { + "type": "object" + } + } + }, + "description": "FHIR" + }, + "202": { + "description": "Successful Response" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "summary": "Post Bundle", + "tags": [ + "fhir" + ] + } + }, "/{domain}/fhir/Condition": { "get": { "description": "What clinical notes diagnosed.", @@ -2288,7 +2579,7 @@ }, "/{domain}/fhir/DiagnosticReport": { "get": { - "description": "Cervical cytologies and biopsies, as known by the last day with data.", + "description": "The domain's reports (each study of the catalog with a report), as known by the last\nday with data.", "operationId": "search_diagnostic_report", "parameters": [ { @@ -2372,6 +2663,92 @@ ] } }, + "/{domain}/fhir/Encounter": { + "get": { + "description": "Consultations: each study of the catalog without a report, as an encounter.", + "operationId": "search_encounter", + "parameters": [ + { + "in": "path", + "name": "domain", + "required": true, + "schema": { + "$ref": "#/components/schemas/Domain" + } + }, + { + "description": "Patient/, comma-separated", + "in": "query", + "name": "subject", + "required": false, + "schema": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "description": "Patient/, comma-separated", + "title": "Subject" + } + }, + { + "in": "query", + "name": "_count", + "required": false, + "schema": { + "anyOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ], + "title": " Count" + } + }, + { + "in": "query", + "name": "_offset", + "required": false, + "schema": { + "default": 0, + "title": " Offset", + "type": "integer" + } + } + ], + "responses": { + "200": { + "content": { + "application/fhir+json": { + "schema": { + "type": "object" + } + } + }, + "description": "FHIR" + }, + "422": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HTTPValidationError" + } + } + }, + "description": "Validation Error" + } + }, + "summary": "Search Encounter", + "tags": [ + "fhir" + ] + } + }, "/{domain}/fhir/Measure": { "get": { "description": "Every measure of the domain (none for a domain without them yet).", @@ -2620,7 +2997,7 @@ }, "/{domain}/fhir/Observation": { "get": { - "description": "The results of cervical cytologies (Bethesda, adequacy, HPV).", + "description": "Every result of the domain's reports, one per field of the catalog.", "operationId": "search_observation", "parameters": [ { diff --git a/src/app/api/fn/fhir/post-bundle.ts b/src/app/api/fn/fhir/post-bundle.ts new file mode 100644 index 0000000..1475811 --- /dev/null +++ b/src/app/api/fn/fhir/post-bundle.ts @@ -0,0 +1,44 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { StrictHttpResponse } from '../../strict-http-response'; +import { RequestBuilder } from '../../request-builder'; + +import { Domain } from '../../models/domain'; + +export interface PostBundle$Params { + domain: Domain; + +/** + * the sender's pipeline (its fhir nodes read this inbox) + */ + sender: string; + body: { +[key: string]: any; +} +} + +export function postBundle(http: HttpClient, rootUrl: string, params: PostBundle$Params, context?: HttpContext): Observable> { + const rb = new RequestBuilder(rootUrl, postBundle.PATH, 'post'); + if (params) { + rb.path('domain', params.domain, {}); + rb.query('sender', params.sender, {}); + rb.body(params.body, 'application/json'); + } + + return http.request( + rb.build({ responseType: 'json', accept: 'application/fhir+json', context }) + ).pipe( + filter((r: any): r is HttpResponse => r instanceof HttpResponse), + map((r: HttpResponse) => { + return r as StrictHttpResponse<{ + }>; + }) + ); +} + +postBundle.PATH = '/{domain}/fhir'; diff --git a/src/app/api/fn/fhir/search-encounter.ts b/src/app/api/fn/fhir/search-encounter.ts new file mode 100644 index 0000000..a75e808 --- /dev/null +++ b/src/app/api/fn/fhir/search-encounter.ts @@ -0,0 +1,44 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { StrictHttpResponse } from '../../strict-http-response'; +import { RequestBuilder } from '../../request-builder'; + +import { Domain } from '../../models/domain'; + +export interface SearchEncounter$Params { + domain: Domain; + +/** + * Patient/, comma-separated + */ + subject?: (string | null); + '_count'?: (number | null); + '_offset'?: number; +} + +export function searchEncounter(http: HttpClient, rootUrl: string, params: SearchEncounter$Params, context?: HttpContext): Observable> { + const rb = new RequestBuilder(rootUrl, searchEncounter.PATH, 'get'); + if (params) { + rb.path('domain', params.domain, {}); + rb.query('subject', params.subject, {}); + rb.query('_count', params['_count'], {}); + rb.query('_offset', params['_offset'], {}); + } + + return http.request( + rb.build({ responseType: 'json', accept: 'application/fhir+json', context }) + ).pipe( + filter((r: any): r is HttpResponse => r instanceof HttpResponse), + map((r: HttpResponse) => { + return r as StrictHttpResponse<{ + }>; + }) + ); +} + +searchEncounter.PATH = '/{domain}/fhir/Encounter'; diff --git a/src/app/api/fn/ingest/concept-maps.ts b/src/app/api/fn/ingest/concept-maps.ts new file mode 100644 index 0000000..93f1c1a --- /dev/null +++ b/src/app/api/fn/ingest/concept-maps.ts @@ -0,0 +1,33 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { StrictHttpResponse } from '../../strict-http-response'; +import { RequestBuilder } from '../../request-builder'; + + +export interface ConceptMaps$Params { +} + +export function conceptMaps(http: HttpClient, rootUrl: string, params?: ConceptMaps$Params, context?: HttpContext): Observable>> { + const rb = new RequestBuilder(rootUrl, conceptMaps.PATH, 'get'); + if (params) { + } + + return http.request( + rb.build({ responseType: 'json', accept: 'application/json', context }) + ).pipe( + filter((r: any): r is HttpResponse => r instanceof HttpResponse), + map((r: HttpResponse) => { + return r as StrictHttpResponse>; + }) + ); +} + +conceptMaps.PATH = '/ingest/concept-maps'; diff --git a/src/app/api/fn/ingest/get-concept-map.ts b/src/app/api/fn/ingest/get-concept-map.ts new file mode 100644 index 0000000..d08f250 --- /dev/null +++ b/src/app/api/fn/ingest/get-concept-map.ts @@ -0,0 +1,35 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { StrictHttpResponse } from '../../strict-http-response'; +import { RequestBuilder } from '../../request-builder'; + + +export interface GetConceptMap$Params { + map_id: string; +} + +export function getConceptMap(http: HttpClient, rootUrl: string, params: GetConceptMap$Params, context?: HttpContext): Observable> { + const rb = new RequestBuilder(rootUrl, getConceptMap.PATH, 'get'); + if (params) { + rb.path('map_id', params.map_id, {}); + } + + return http.request( + rb.build({ responseType: 'json', accept: 'application/json', context }) + ).pipe( + filter((r: any): r is HttpResponse => r instanceof HttpResponse), + map((r: HttpResponse) => { + return r as StrictHttpResponse<{ + [key: string]: any; + }>; + }) + ); +} + +getConceptMap.PATH = '/ingest/concept-maps/{map_id}'; diff --git a/src/app/api/fn/ingest/save-concept-map.ts b/src/app/api/fn/ingest/save-concept-map.ts new file mode 100644 index 0000000..aa9989a --- /dev/null +++ b/src/app/api/fn/ingest/save-concept-map.ts @@ -0,0 +1,39 @@ +/* eslint-disable */ +/* Code generated by ng-openapi-gen DO NOT EDIT. */ + +import { HttpClient, HttpContext, HttpResponse } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { filter, map } from 'rxjs/operators'; +import { StrictHttpResponse } from '../../strict-http-response'; +import { RequestBuilder } from '../../request-builder'; + + +export interface SaveConceptMap$Params { + map_id: string; + body: { +[key: string]: any; +} +} + +export function saveConceptMap(http: HttpClient, rootUrl: string, params: SaveConceptMap$Params, context?: HttpContext): Observable> { + const rb = new RequestBuilder(rootUrl, saveConceptMap.PATH, 'put'); + if (params) { + rb.path('map_id', params.map_id, {}); + rb.body(params.body, 'application/json'); + } + + return http.request( + rb.build({ responseType: 'json', accept: 'application/json', context }) + ).pipe( + filter((r: any): r is HttpResponse => r instanceof HttpResponse), + map((r: HttpResponse) => { + return r as StrictHttpResponse<{ + [key: string]: number; + }>; + }) + ); +} + +saveConceptMap.PATH = '/ingest/concept-maps/{map_id}'; diff --git a/src/app/api/fn/review/conflicts.ts b/src/app/api/fn/review/conflicts.ts index eed56cb..feccf16 100644 --- a/src/app/api/fn/review/conflicts.ts +++ b/src/app/api/fn/review/conflicts.ts @@ -9,7 +9,7 @@ import { RequestBuilder } from '../../request-builder'; export interface Conflicts$Params { - entity: 'identity' | 'death' | 'clinical_note' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy'; + entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'clinical_note' | 'death'; } export function conflicts(http: HttpClient, rootUrl: string, params: Conflicts$Params, context?: HttpContext): Observable; + kind?: 'fhir'; + label?: string; + position?: (Position | null); +} diff --git a/src/app/api/models/map.ts b/src/app/api/models/map.ts index bcf6db0..0e0d5a0 100644 --- a/src/app/api/models/map.ts +++ b/src/app/api/models/map.ts @@ -4,9 +4,11 @@ import { Position } from '../models/position'; /** - * Columns to platform fields, with the site's codes and date formats. + * Columns to platform fields, the site's codes translated by its ConceptMap + * (core.concept_map), and its date formats. */ export interface Map { + concept_map?: (string | null); fields: { [key: string]: string; }; @@ -18,9 +20,4 @@ export interface Map { kind?: 'map'; label?: string; position?: (Position | null); - values?: { -[key: string]: { -[key: string]: string; -}; -}; } diff --git a/src/app/api/models/pipeline.ts b/src/app/api/models/pipeline.ts index c7b6707..239cca0 100644 --- a/src/app/api/models/pipeline.ts +++ b/src/app/api/models/pipeline.ts @@ -2,6 +2,7 @@ /* Code generated by ng-openapi-gen DO NOT EDIT. */ import { Extract } from '../models/extract'; +import { Fhir } from '../models/fhir'; import { Join } from '../models/join'; import { Link } from '../models/link'; import { Map } from '../models/map'; @@ -10,5 +11,5 @@ import { Route } from '../models/route'; import { Source } from '../models/source'; import { Target } from '../models/target'; export interface Pipeline { - nodes: Array<(Source | Read | Route | Map | Extract | Join | Link | Target)>; + nodes: Array<(Source | Read | Route | Map | Extract | Fhir | Join | Link | Target)>; } diff --git a/src/app/api/models/rejection.ts b/src/app/api/models/rejection.ts index 233a577..08644d1 100644 --- a/src/app/api/models/rejection.ts +++ b/src/app/api/models/rejection.ts @@ -2,7 +2,7 @@ /* Code generated by ng-openapi-gen DO NOT EDIT. */ export interface Rejection { - entity: 'identity' | 'death' | 'clinical_note' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy'; + entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'clinical_note' | 'death'; reason: string; record: string; } diff --git a/src/app/api/models/target.ts b/src/app/api/models/target.ts index 9bc0325..7f70839 100644 --- a/src/app/api/models/target.ts +++ b/src/app/api/models/target.ts @@ -8,7 +8,7 @@ import { Position } from '../models/position'; * one `link` node among the inputs. Rule breaks are held for review. */ export interface Target { - entity: 'identity' | 'death' | 'clinical_note' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy'; + entity: 'identity' | 'cervical_cytology' | 'cervical_biopsy' | 'mammography' | 'breast_biopsy' | 'clinical_note' | 'death'; id: string; inputs?: Array; kind?: 'target'; diff --git a/src/app/conectar/concept-map-editor.ts b/src/app/conectar/concept-map-editor.ts new file mode 100644 index 0000000..cf6f19c --- /dev/null +++ b/src/app/conectar/concept-map-editor.ts @@ -0,0 +1,164 @@ +import { HttpErrorResponse } from '@angular/common/http'; +import { Component, inject, input, output, signal } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; +import { MatIconModule } from '@angular/material/icon'; +import { Api } from '../api/api'; +import { getConceptMap } from '../api/fn/ingest/get-concept-map'; +import { saveConceptMap } from '../api/fn/ingest/save-concept-map'; + +/** One translation: a site's code onto a platform code of one target system. */ +interface Row { + target: string; + code: string; + platform: string; +} + +/** A site's codes in platform terms (a FHIR ConceptMap), edited as a table: a new + * laboratory spelling is one more row. The API refuses a code no platform field allows. */ +@Component({ + selector: 'app-concept-map-editor', + imports: [FormsModule, MatButtonModule, MatIconModule], + template: ` +

+ Códigos del sitio · {{ id() }} +

+ + + + + + + + + + + @for (row of rows(); track $index) { + + + + + + + } + +
Sistema destinoCódigo del sitioCódigo de la plataforma
+ + + + + + + +
+
+ + + {{ message() }} +
+ `, + styles: ` + h3 { + font-size: 0.95rem; + font-weight: 500; + margin: 16px 0 8px; + } + input, + select { + width: 100%; + box-sizing: border-box; + font: inherit; + padding: 4px; + } + .actions { + display: flex; + flex-wrap: wrap; + align-items: center; + gap: 8px; + margin-top: 8px; + } + `, +}) +export class ConceptMapEditor { + private readonly api = inject(Api); + readonly id = input.required(); + readonly saved = output(); + protected readonly rows = signal([]); + protected readonly targets = signal([]); + protected readonly message = signal(''); + private source = 'urn:isssteleon:site'; + + async ngOnInit(): Promise { + try { + const doc = (await this.api.invoke(getConceptMap, { map_id: this.id() })) as Record< + string, + any + >; + const groups = (doc['group'] ?? []) as any[]; + this.source = groups[0]?.source ?? this.source; + this.targets.set([...new Set(groups.map((g) => g.target))]); + this.rows.set( + groups.flatMap((g) => + (g.element ?? []).map((e: any) => ({ + target: g.target, + code: e.code, + platform: e.target?.[0]?.code ?? '', + })), + ), + ); + } catch (e) { + this.message.set( + e instanceof HttpErrorResponse && e.status === 404 ? 'Nuevo: agregue filas.' : String(e), + ); + } + } + + protected short(url: string): string { + return url.split('/').pop() ?? url; + } + + protected add(): void { + this.rows.update((r) => [...r, { target: this.targets()[0] ?? '', code: '', platform: '' }]); + } + + protected remove(i: number): void { + this.rows.update((r) => r.filter((_, j) => j !== i)); + } + + /** The rows as a ConceptMap: one group per target system. */ + protected async save(): Promise { + const groups = new Map(); + for (const r of this.rows().filter((r) => r.target && r.code && r.platform)) { + groups.set(r.target, [...(groups.get(r.target) ?? []), r]); + } + const doc = { + resourceType: 'ConceptMap', + status: 'active', + group: [...groups].map(([target, rows]) => ({ + source: this.source, + target, + element: rows.map((r) => ({ + code: r.code, + target: [{ code: r.platform, equivalence: 'equivalent' }], + })), + })), + }; + try { + const { version } = await this.api.invoke(saveConceptMap, { map_id: this.id(), body: doc }); + this.message.set(`Versión ${version} guardada.`); + this.saved.emit(version); + } catch (e) { + const detail = e instanceof HttpErrorResponse ? e.error?.detail : e; + this.message.set(Array.isArray(detail) ? detail.join('; ') : String(detail)); + } + } +} diff --git a/src/app/conectar/conectar.html b/src/app/conectar/conectar.html index 79f7ba9..3b922c8 100644 --- a/src/app/conectar/conectar.html +++ b/src/app/conectar/conectar.html @@ -92,6 +92,9 @@ [model]="model" (modelChange)="edited($event)" /> + @if (conceptMap(d); as cm) { + + } @if (preview(); as rows) {
diff --git a/src/app/conectar/conectar.ts b/src/app/conectar/conectar.ts index f73b20f..912e5ed 100644 --- a/src/app/conectar/conectar.ts +++ b/src/app/conectar/conectar.ts @@ -22,6 +22,7 @@ import { startRun } from '../api/fn/ingest/start-run'; import { runStatus } from '../api/fn/runs/run-status'; import type { Pipeline } from '../api/models/pipeline'; import type { Source } from '../api/models/source'; +import { ConceptMapEditor } from './concept-map-editor'; import { FORMLY_TYPES, nodeSchema } from './schema-form'; type Doc = Pipeline['nodes'][number]; @@ -52,6 +53,7 @@ export const KINDS: Record = { route: 'Filtrar', map: 'Mapear', extract: 'Extraer', + fhir: 'FHIR', join: 'Unir', link: 'Vincular', target: 'Destino', @@ -73,6 +75,7 @@ const ID = /^[a-z][a-z0-9_]*$/; MatListModule, MatTableModule, Vflow, + ConceptMapEditor, ], // Forms are this page's only: Formly loads with it, not with the app. providers: [provideFormlyCore([...withFormlyMaterial(), FORMLY_TYPES])], @@ -304,6 +307,10 @@ export class Conectar { const run = this.run(); return run ? `${location.protocol}//${location.hostname}:5712/runs/${run.id}` : ''; }); + /** The ConceptMap a node names, if its kind takes one. */ + protected conceptMap(d: Doc): string | undefined { + return 'concept_map' in d ? (d.concept_map ?? undefined) : undefined; + } protected kindLabel(kind: Doc['kind']): string { return KINDS[kind ?? 'source']; } diff --git a/src/app/indicadores/follow-up.ts b/src/app/indicadores/follow-up.ts index b86017d..249ffa7 100644 --- a/src/app/indicadores/follow-up.ts +++ b/src/app/indicadores/follow-up.ts @@ -4,6 +4,8 @@ import { code, ext, resources } from '../fhir'; /** One row of the follow-up list: what the list shows of a patient at the cut-off. */ export interface Row { patient: Patient; + name?: string; + curp?: string; status: string; ageGroup: string; cytology?: { date: string; result?: string; adequacy?: string }; @@ -13,6 +15,8 @@ export interface Row { risk: Record<'cin2' | 'cancer', number | undefined>; } +export const CURP = 'https://isssteleon.org/fhir/sid/curp'; + const AGE_GROUPS: [number, number][] = [ [25, 34], [35, 44], @@ -72,17 +76,17 @@ export function rows(page: Bundle, start: string, cutoff: string, horizon: numbe return resources(page, 'Patient', 'match').map((patient) => { const mine = reports.filter((r) => r.subject?.reference === `Patient/${patient.id}`); const by = (kind: string) => mine.filter((r) => code(r.code) === kind); - const cytologies = by('cervical-cytology') + const cytologies = by('cervical_cytology') .filter((r) => start <= r.effectiveDateTime! && r.effectiveDateTime! <= cutoff) .sort((a, b) => a.effectiveDateTime!.localeCompare(b.effectiveDateTime!)); const last = cytologies.at(-1); const lastResults = last ? results(last) : new Map(); - const hpv = cytologies.filter((r) => results(r).has('hpv')).at(-1); + const hpv = cytologies.filter((r) => results(r).has('cervical_cytology.hpv')).at(-1); const hpvResults = hpv ? results(hpv) : new Map(); - const types = ['hpv-16', 'hpv-18'] + const types = ['cervical_cytology.hpv_16', 'cervical_cytology.hpv_18'] .filter((k) => hpvResults.has(k)) .map((k) => hpvResults.get(k)!.valueBoolean); - const biopsy = by('cervical-biopsy') + const biopsy = by('cervical_biopsy') .filter((r) => ext(r, 'report-date')) .sort((a, b) => ext(a, 'report-date')!.valueDate!.localeCompare(ext(b, 'report-date')!.valueDate!), @@ -91,22 +95,24 @@ export function rows(page: Bundle, start: string, cutoff: string, horizon: numbe const theirs = risks.filter((r) => r.subject?.reference === `Patient/${patient.id}`); return { patient, + name: patient.name?.[0]?.text, + curp: patient.identifier?.find((i) => i.system === CURP)?.value, status: ext(patient, 'follow-up-status')?.valueCoding?.code ?? '', ageGroup: ageGroup(patient.birthDate, cutoff), cytology: last && { date: last.effectiveDateTime!, - result: code(lastResults.get('cytology-result')?.valueCodeableConcept), - adequacy: code(lastResults.get('cytology-adequacy')?.valueCodeableConcept), + result: code(lastResults.get('cervical_cytology.result')?.valueCodeableConcept), + adequacy: code(lastResults.get('cervical_cytology.adequacy')?.valueCodeableConcept), }, hpv: hpv && { date: hpv.effectiveDateTime!, - positive: !!hpvResults.get('hpv')?.valueBoolean, + positive: !!hpvResults.get('cervical_cytology.hpv')?.valueBoolean, types1618: types.length ? types.some((t) => t) : undefined, }, daysToDiagnosis: last ? ext(last, 'days-to-diagnosis')?.valueInteger : undefined, biopsy: biopsy && { date: ext(biopsy, 'report-date')!.valueDate!, - histology: code(biopsy.conclusionCode?.[0]), + histology: code(results(biopsy).get('cervical_biopsy.histology')?.valueCodeableConcept), }, risk: { cin2: currentRisk(theirs, 'cin2', horizon), diff --git a/src/app/indicadores/tab-riesgos.html b/src/app/indicadores/tab-riesgos.html index 6abbe5f..6caf560 100644 --- a/src/app/indicadores/tab-riesgos.html +++ b/src/app/indicadores/tab-riesgos.html @@ -75,9 +75,12 @@ @for (row of rows(); track row.patient.id) { - {{ - row.patient.id!.slice(0, 10) + {{ + row.name ?? row.patient.id!.slice(0, 10) }} + @if (row.curp) { +
{{ row.curp }}
+ } {{ row.ageGroup }} {{ name(row.status) }} diff --git a/src/app/indicadores/tab-riesgos.scss b/src/app/indicadores/tab-riesgos.scss index a29a118..1c5bc31 100644 --- a/src/app/indicadores/tab-riesgos.scss +++ b/src/app/indicadores/tab-riesgos.scss @@ -20,9 +20,13 @@ white-space: nowrap; } -.id { +a { color: var(--color-action); +} + +.curp { font-family: monospace; + font-size: 12px; } .pager { diff --git a/src/app/paciente/paciente.html b/src/app/paciente/paciente.html index fae1605..904dfd1 100644 --- a/src/app/paciente/paciente.html +++ b/src/app/paciente/paciente.html @@ -6,9 +6,17 @@ } @else if (patient(); as p) {

- Paciente {{ p.id!.slice(0, 10) }} + {{ identity().name ?? 'Paciente' }} {{ p.id!.slice(0, 10) }}

+
+
CURP
+
{{ identity().curp ?? 'Sin dato' }}
+
+
+
Expedientes
+
{{ identity().numbers.join(', ') || 'Sin dato' }}
+
Fecha de nacimiento
{{ p.birthDate ?? 'Sin dato' }}
diff --git a/src/app/paciente/paciente.ts b/src/app/paciente/paciente.ts index 526c315..65688e6 100644 --- a/src/app/paciente/paciente.ts +++ b/src/app/paciente/paciente.ts @@ -13,9 +13,19 @@ import type { RiskAssessment, } from 'fhir/r4'; import { code, ext, Fhir, label, resources } from '../fhir'; +import { CURP } from '../indicadores/follow-up'; import { name } from '../indicadores/measures'; import { Figure, PALETTE, Plot } from '../plot'; +/** An Observation's value as the screens say it, whatever its type. */ +function shown(o: Observation): string { + if (o.valueBoolean !== undefined) return o.valueBoolean ? 'positivo' : 'negativo'; + if (o.valueCodeableConcept) + return name(code(o.valueCodeableConcept) ?? '') || label(o.valueCodeableConcept); + if (o.valueQuantity) return `${o.valueQuantity.value} ${o.valueQuantity.unit ?? ''}`.trim(); + return o.valueString ?? o.valueDateTime ?? ''; +} + /** One patient: her history (conditions, procedures), her tests and results, and the * champion models' risks with their curves. Everything read from the FHIR API. */ @Component({ @@ -86,13 +96,7 @@ export class Paciente { reported: ext(r, 'report-date')?.valueDate, kind: label(r.code), status: r.status, - results: [ - ...results.map( - (o) => - `${label(o.code)}: ${o.valueBoolean !== undefined ? (o.valueBoolean ? 'positivo' : 'negativo') : name(code(o.valueCodeableConcept) ?? '')}`, - ), - ...(r.conclusionCode ?? []).map((c) => `Histología: ${name(code(c) ?? '')}`), - ], + results: [...results.map((o) => `${label(o.code)}: ${shown(o)}`)], }; }); }); @@ -169,6 +173,14 @@ export class Paciente { return Math.max(0, ...this.models().flatMap((m) => m.predictions.map((p) => p.high ?? p.p))); } protected readonly name = name; + protected readonly identity = computed(() => { + const p = this.patient(); + return { + name: p?.name?.[0]?.text, + curp: p?.identifier?.find((i) => i.system === CURP)?.value, + numbers: (p?.identifier ?? []).filter((i) => i.system !== CURP).map((i) => i.value), + }; + }); protected readonly status = computed(() => { const p = this.patient(); return p ? name(ext(p, 'follow-up-status')?.valueCoding?.code ?? '') : ''; diff --git a/src/app/revision/revision.ts b/src/app/revision/revision.ts index f342c29..a177dde 100644 --- a/src/app/revision/revision.ts +++ b/src/app/revision/revision.ts @@ -40,7 +40,6 @@ const IDENTITY_FIELDS: Correction['field'][] = [ 'nss', 'birth_date', 'sex', - 'postal_code', ]; /** Bookkeeping columns, not values a reviewer judges. */ const HIDDEN = [