I have 2 get request which return details that corresponds to a patient.
First GET request
returns patient’s details and encrypted patientId, which is used on the Second GET request to get the patient’s name. I need to save both the value of get request into an array in the state on patients: [{ }]
but that patient on state shows empty with what I've tried.
const getUserConfig = await axios.get(`/room/room01/userconfig`);
const uuId = getUserConfig.data.room01.patientId;
console.log(uuid) // is the patientId
`Returned Data`
{
"room01": {
"conditions": [
"Fever”, “Headache”
],
"room": "room01",
"patientId": "e1040efd-dwe6-4956-a4g5-2a6caa6318f9",
"observationLevel": "1",
}
}
The `Second GET request`
let getPatientName = await axios.get(`/patient/${uuId}/name`);
console.log(getPatientName.data); // is the patient name
How I'm trying to save on state but isn't working
this.setState({
patients: [
{
patientName: getPatientName.data,
label: patientData.data.room01.label,
observationLevel: patientData.data.room01.observationLevel,
}
]
});
What the state should be looking like after both GET requests, and I would like to keep adding new patient to the next index in the array on the next GET request.
this.state = {
patients: [
{patientName: ‘string’, room: `room01`, observationLevel: `1`, …..}
]
};