Created
July 16, 2024 16:37
-
-
Save atmonello/548fade4ebc0f205ae2e448efc350d44 to your computer and use it in GitHub Desktop.
Omint - Get doctors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @typedef {Object} FullMedico | |
* @property {number} Distancia | |
* @property {Prestador} Prestador | |
* @property {boolean} Favorito | |
*/ | |
/** | |
* @typedef {Object} Prestador | |
* @property {string} CodigoRede | |
* @property {string} CodigoPrestador | |
* @property {string} DescricaoPrestador | |
* @property {string} SrEndereco | |
* @property {string} TipoView | |
* @property {string} DescricaoEspecialidade | |
* @property {string} TipoLogradouro | |
* @property {string} EnderecoRua | |
* @property {string} EnderecoNumero | |
* @property {string} EnderecoComplemento | |
* @property {string} EnderecoBairro | |
* @property {string} EnderecoCidade | |
* @property {string} CodigoEstado | |
* @property {string} DescricaoObservacao | |
* @property {string} TpRede | |
* @property {string} TpAgenda | |
* @property {string} AtSincronizaAgenda | |
* @property {string} DsIdioma | |
* @property {string} WhatsApp | |
* @property {string} Teleconsulta | |
* @property {string} Agendamento | |
* @property {string[]} SubEspecialidades | |
* @property {string} Favorito | |
* @property {number} GmLatitude | |
* @property {number} GmLongitude | |
* @property {number} AtOrdem | |
* @property {number} ScoreTotal | |
* @property {number} Avaliacoes | |
* @property {number} Distancia | |
*/ | |
/** | |
* @typedef {Object} MedicoResult | |
* @property {string} Nome | |
* @property {string} Endereco | |
* @property {string} WhatsApp | |
* @property {string} Avaliacoes | |
* @property {string} Distancia | |
*/ | |
/** | |
* @param {FullMedico} medico | |
* @returns {string} | |
*/ | |
function getFullAddress(medico) { | |
let endereco = `${medico.Prestador.TipoLogradouro} ${medico.Prestador.EnderecoRua}, ${medico.Prestador.EnderecoNumero}`; | |
endereco += medico.Prestador.EnderecoComplemento | |
? ` - ${medico.Prestador.EnderecoComplemento}` | |
: ""; | |
return `${endereco} - ${medico.Prestador.EnderecoBairro}`; | |
} | |
/** | |
* @param {FullMedico} medico | |
*/ | |
function getDistance(medico) { | |
const isKm = medico.Distancia >= 1; | |
const unit = isKm ? "km" : "metros"; | |
const truncDistance = isKm | |
? Number(medico.Distancia).toFixed(2) | |
: Math.trunc(medico.Distancia * 1000); | |
return `${truncDistance} ${unit}`; | |
} | |
/** | |
* | |
* @param {FullMedico[]} medicos | |
* @returns {MedicoResult[]} | |
*/ | |
function parseDoctors(medicos) { | |
return medicos | |
.sort((mA, mB) => mA.Distancia - mB.Distancia) | |
.map((medico) => { | |
return { | |
Nome: medico.Prestador.DescricaoPrestador, | |
Endereco: getFullAddress(medico), | |
WhatsApp: medico.Prestador.WhatsApp || "não informado", | |
Avaliacoes: medico.Prestador.Avaliacoes, | |
Distancia: getDistance(medico), | |
}; | |
}); | |
} | |
const result = parseDoctors(medicos); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment