Frontend Hotfixes & Backend improvements
Run Tests on Branches / Detect Changes (push) Successful in 9s
Run Tests on Branches / Backend Tests (push) Successful in 1m51s
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Successful in 1m44s

This commit is contained in:
Ichitux
2026-07-09 00:58:31 +02:00
parent 16fea2de8f
commit 5f604b11ba
8 changed files with 73 additions and 31 deletions
+39 -9
View File
@@ -151,19 +151,52 @@ export async function getMedicineDetails(nregistro) {
return JSON.parse(cachedData);
}
// Consultar la API de CIMA
// Intentar obtener de la API de CIMA (endpoint individual puede no existir)
console.log(`🌐 Fetching medicine details from CIMA: ${nregistro}`);
const response = await axios.get(`${CIMA_API_BASE_URL}/medicamento/${nregistro}`, {
try {
const response = await axios.get(`${CIMA_API_BASE_URL}/medicamento/${nregistro}`, {
timeout: 5000
});
if (response.data) {
const med = response.data;
const medicineDetails = {
id: med.nregistro,
nregistro: med.nregistro,
name: med.nombre,
active_ingredient: med.principiosActivos?.[0]?.nombre || med.vtm?.nombre || null,
dosage: med.dosis || null,
form: med.formaFarmaceutica?.nombre || null,
formSimplified: med.formaFarmaceuticaSimplificada?.nombre || null,
laboratory: med.labtitular,
prescription: med.cpresc,
commercialized: med.comerc,
generic: med.generico,
photos: med.fotos || [],
docs: med.docs || [],
presentations: med.presentaciones || []
};
await redisClient.setEx(cacheKey, CACHE_TTL * 24, JSON.stringify(medicineDetails));
return medicineDetails;
}
} catch (apiError) {
console.log(`⚠️ Individual medicine endpoint failed, trying search fallback`);
}
// Fallback: buscar por nregistro usando el endpoint de búsqueda
const searchResponse = await axios.get(`${CIMA_API_BASE_URL}/medicamentos`, {
params: { nregistro },
timeout: 5000
});
if (response.data) {
const med = response.data;
if (searchResponse.data?.resultados?.length > 0) {
const med = searchResponse.data.resultados[0];
const medicineDetails = {
id: med.nregistro,
nregistro: med.nregistro,
name: med.nombre,
active_ingredient: med.principiosActivos?.[0]?.nombre || med.vtm?.nombre || null,
active_ingredient: med.vtm?.nombre || null,
dosage: med.dosis || null,
form: med.formaFarmaceutica?.nombre || null,
formSimplified: med.formaFarmaceuticaSimplificada?.nombre || null,
@@ -172,13 +205,10 @@ export async function getMedicineDetails(nregistro) {
commercialized: med.comerc,
generic: med.generico,
photos: med.fotos || [],
docs: med.docs || [],
presentations: med.presentaciones || []
docs: med.docs || []
};
// Guardar en caché (TTL más largo para detalles específicos)
await redisClient.setEx(cacheKey, CACHE_TTL * 24, JSON.stringify(medicineDetails));
return medicineDetails;
}