Skip to content

Commit

Permalink
fix(CDAs): Agrega control al crear bucket (#1907)
Browse files Browse the repository at this point in the history
  • Loading branch information
silviroa committed May 31, 2024
1 parent 55a06ad commit 58a9bba
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 40 deletions.
81 changes: 45 additions & 36 deletions modules/cda/controller/CDAPatient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,16 @@ export function searchByPatient(pacienteId, prestacion, { limit, skip }, org = n
*/
export async function loadCDA(cdaID) {
return new Promise(async (resolve, reject) => {
const CDAFiles = makeFs();
CDAFiles.readFile({ filename: String(cdaID) + '.xml' }, (err, buffer) => {
const xml = buffer.toString('utf8');
return resolve(xml);
});
try {
const CDAFiles = makeFs();
CDAFiles.readFile({ filename: String(cdaID) + '.xml' }, (err, buffer) => {
const xml = buffer.toString('utf8');
return resolve(xml);
});
} catch (e) {
return reject(null);
}

});
}

Expand Down Expand Up @@ -835,39 +840,43 @@ export function cdaToJSON(idCDA) {
const _base64 = idCDA;
let contexto = await cdaCtr.loadCDA(_base64);
let setText = false;
// Limpiamos xml previo al parsing
contexto = contexto.toString().replace(new RegExp('<br>', 'g'), ' ');
contexto = contexto.toString().replace(new RegExp('[\$]', 'g'), '');
contexto = contexto.toString().replace(new RegExp('&#xD', 'g'), '');

/**
* ATENCION: FIX para poder visualizar los informes de evolución que traen caracteres raros.
* Obtenemos el texto dentro de los tags <text> del xml, la extraemos tal cual está y la agregamos luego de la ejecución del parser
* para conservala tal cual la escribieron.
* PD: Deberemos mejorar esto a futuro!
*/
let resultado = contexto.toString().match('(<text>)[^~]*(<\/text>)')[0];
if (!resultado.includes('Sin datos')) {
resultado = resultado.replace('<text>', '');
resultado = resultado.replace('</text>', '');
setText = true;
}
contexto = contexto.toString().replace(new RegExp('(<text>)[^~]*(<\/text>)'), '');
to_json(contexto, (error, data) => {
if (error) {
return reject(error);
} else {
if (setText) {
// Volvemos a agregar el texto de la evolución
if (typeof data.ClinicalDocument.component.structuredBody.component.section === 'object') {
data.ClinicalDocument.component.structuredBody.component.section.text = resultado;
} else {
data.ClinicalDocument.component.structuredBody.component.section = { text: resultado };
if (contexto) {
// Limpiamos xml previo al parsing
contexto = contexto.toString().replace(new RegExp('<br>', 'g'), ' ');
contexto = contexto.toString().replace(new RegExp('[\$]', 'g'), '');
contexto = contexto.toString().replace(new RegExp('&#xD', 'g'), '');

/**
* ATENCION: FIX para poder visualizar los informes de evolución que traen caracteres raros.
* Obtenemos el texto dentro de los tags <text> del xml, la extraemos tal cual está y la agregamos luego de la ejecución del parser
* para conservala tal cual la escribieron.
* PD: Deberemos mejorar esto a futuro!
*/
let resultado = contexto.toString().match('(<text>)[^~]*(<\/text>)')[0];
if (!resultado.includes('Sin datos')) {
resultado = resultado.replace('<text>', '');
resultado = resultado.replace('</text>', '');
setText = true;
}
contexto = contexto.toString().replace(new RegExp('(<text>)[^~]*(<\/text>)'), '');
to_json(contexto, (error, data) => {
if (error) {
return reject(error);
} else {
if (setText) {
// Volvemos a agregar el texto de la evolución
if (typeof data.ClinicalDocument.component.structuredBody.component.section === 'object') {
data.ClinicalDocument.component.structuredBody.component.section.text = resultado;
} else {
data.ClinicalDocument.component.structuredBody.component.section = { text: resultado };
}
}
return resolve(data);
}
return resolve(data);
}
});
});
} else {
return reject(null);
}
});
}

10 changes: 6 additions & 4 deletions modules/mobileApp/routes/paciente.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,12 @@ router.get('/laboratorios/(:id)', async (req: any, res, next) => {
const cdas: any[] = await cdaCtr.searchByPatient(paciente.vinculos, '4241000179101', { limit, skip });
for (const cda of cdas) {
const _xml = await cdaCtr.loadCDA(cda.cda_id);
const dom: any = xmlToJson(_xml);
cda.confidentialityCode = dom.ClinicalDocument.confidentialityCode['@attributes'].code;
cda.title = dom.ClinicalDocument.title['#text'];
cda.organizacion = dom.ClinicalDocument.author.assignedAuthor.representedOrganization.name['#text'];
if (_xml) {
const dom: any = xmlToJson(_xml);
cda.confidentialityCode = dom.ClinicalDocument.confidentialityCode['@attributes'].code;
cda.title = dom.ClinicalDocument.title['#text'];
cda.organizacion = dom.ClinicalDocument.author.assignedAuthor.representedOrganization.name['#text'];
}
}
res.json(cdas);
} else {
Expand Down

0 comments on commit 58a9bba

Please sign in to comment.