Frontend Hotfixes & Backend improvements
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user