Below is my JSON response.
I would like to fetch taskids = [20785, 20792, 20796], patientids = [Patient/20787,Patient/20794,Patient/20798], encounterids = [Encounter/20784, Encounter/20791,Encounter/20795]
I have tried using map.
let response = pm.response.json(),
taskids = _.map(response.entry, ({ data }) => ( data.resource.id ));
console.log(taskids);
patientids = _.map(response.entry, ({ data }) => ( data.resource.for.reference ));
console.log(patientids);
encounterids = _.map(response.entry, ({ data }) => ( data.resource.encounter.reference ));
console.log(encounterids);
Received error “TypeError: Cannot read properties of undefined (reading ‘resource’)”
{
“resourceType”: “Bundle”,
“id”: “3351d9a3-ceab-4d78-949d-ea56be19f07e”,
“meta”: {
“lastUpdated”: “2022-12-08T17:07:06.442+00:00”
},
“type”: “searchset”,
“link”: [
{
“relation”: “self”,
},
{
“relation”: “next”,
}
],
“entry”: [
{
“resource”: {
“resourceType”: “Task”,
“id”: “20785”,
“meta”: {
“versionId”: “1”,
“lastUpdated”: “2022-12-05T21:13:40.248+00:00”,
“source”: “#Kf7z9UFdnUviJO6v”
},
“identifier”: [
{
“value”: “2000001262-5671”
}
],
“status”: “requested”,
“intent”: “plan”,
“code”: {
“coding”: [
{
"code": "pre-admission-registration",
"display": "Pre-admission Registration"
},
{
"code": "healthcare",
"display": "healthcare"
}
],
"text": "healthcare"
},
"description": "long string",
"for": {
"reference": "Patient/20787"
},
"encounter": {
"reference": "Encounter/20784"
},
"authoredOn": "2022-12-05"
},
"search": {
"mode": "match"
}
},
{
"resource": {
"resourceType": "Task",
"id": "20792",
"meta": {
"versionId": "1",
"lastUpdated": "2022-12-05T22:43:29.682+00:00",
"source": "#W9R3bex9SstLY6bD"
},
"identifier": [
{
"value": "2200104825-1964"
}
],
"status": "requested",
"intent": "plan",
"code": {
"coding": [
{
"code": "pre-admission-registration",
"display": "Pre-admission Registration"
},
{
"code": "healthcare",
"display": "healthcare"
}
],
"text": "healthcare"
},
"description": "long string",
"for": {
"reference": "Patient/20794"
},
"encounter": {
"reference": "Encounter/20791"
},
"authoredOn": "2022-12-05"
},
"search": {
"mode": "match"
}
},
{
"resource": {
"resourceType": "Task",
"id": "20796",
"meta": {
"versionId": "1",
"lastUpdated": "2022-12-06T16:26:07.647+00:00",
"source": "#fhxGrbXtk160CiDx"
},
"identifier": [
{
"value": "9001360-0"
}
],
"status": "requested",
"intent": "plan",
"code": {
"coding": [
{
"code": "pre-admission-registration",
"display": "Pre-admission Registration"
},
{
"code": "healthcare",
"display": "healthcare"
}
],
"text": "healthcare"
},
"description": "long string",
"for": {
"reference": "Patient/20798"
},
"encounter": {
"reference": "Encounter/20795"
},
"authoredOn": "2022-12-06"
},
"search": {
"mode": "match"
}
}
]
}