I want to access each data value of the below json in Angularjs . But I am unable to find a way

76 views Asked by At

I want to access each data value of the below JSON in Angularjs. But I am unable to find a way. let say I want to access type, name, magnitude, units of the below query. So how to access that, can anybody help me regarding about this, please?

{
"**openEHR-EHR-OBSERVATION.body_temperature.v1/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value**":{

"type": "DV_QUANTITY",

"name": "Temperature",

"serie":[
{
"magnitude": 34,

"units": "°C",

"date": "2016-12-28 13:23:32"

}

]
},
3

There are 3 answers

7
Sa E Chowdary On

you may do something like this with ng-repeat

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = {
"openEHR-EHR-OBSERVATION.body_temperature.v1/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value":{
"type": "DV_QUANTITY",
"name": "Temperature",
"serie":[
{
"magnitude": 34,
"units": "°C",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 34,
"units": "°C",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 38,
"units": "°C",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.blood_pressure.v1/data[at0001]/events[at0006]/data[at0003]/items[at0004]/value":{
"type": "DV_QUANTITY",
"name": "Systolic",
"serie":[
{
"magnitude": 4,
"units": "mm[Hg]",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 9,
"units": "mm[Hg]",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 7,
"units": "mm[Hg]",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.blood_pressure.v1/data[at0001]/events[at0006]/data[at0003]/items[at0005]/value":{
"type": "DV_QUANTITY",
"name": "Diastolic",
"serie":[
{
"magnitude": 6,
"units": "mm[Hg]",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 17,
"units": "mm[Hg]",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 12,
"units": "mm[Hg]",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.pulse.v1/data[at0002]/events[at0003]/data[at0001]/items[at0004]/value":{
"type": "DV_QUANTITY",
"name": "Rate",
"serie":[
{
"magnitude": 6,
"units": "/min",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 17,
"units": "/min",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 15,
"units": "/min",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.pulse.v1/data[at0002]/events[at0003]/data[at0001]/items[at0005]/value":{
"type": "DV_CODED_TEXT",
"name": "Regular?",
"serie":[
{
"code": "at0006at1028",
"value": "Regular",
"date": "2016-12-28 13:23:32"
},
{
"code": "at0006at1028",
"value": "Irregular",
"date": "2016-12-29 06:49:51"
},
{
"code": "at0006at1028",
"value": "Irregular",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.respiration.v1/data[at0001]/events[at0002]/data[at0003]/items[at0004]/value":{
"type": "DV_QUANTITY",
"name": "Rate",
"serie":[
{
"magnitude": 5,
"units": "/min",
"date": "2016-12-28 13:23:32"
},
{
"magnitude": 9,
"units": "/min",
"date": "2016-12-29 06:49:51"
},
{
"magnitude": 13,
"units": "/min",
"date": "2016-12-29 06:49:51"
}
]
},
"openEHR-EHR-OBSERVATION.respiration.v1/data[at0001]/events[at0002]/data[at0003]/items[at0005]/value":{
"type": "DV_CODED_TEXT",
"name": "Rhythm",
"serie":[
{
"code": "at0006at0007",
"value": "Regular",
"date": "2016-12-28 13:23:32"
},
{
"code": "at0006at0007",
"value": "Regular",
"date": "2016-12-29 06:49:51"
}
]
}
    
  }

});
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="[email protected]" src="https://code.angularjs.org/1.4.12/angular.js" data-semver="1.4.9"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
<div ng-repeat="(k,v) in name">
<p>{{v.type}}</p>
<p>{{v.name}}</p>
<span ng-repeat="x in v.serie">
   magnitude: {{x.magnitude}},
   units:{{x.units}},
   date:{{x.date}}<br>
</span>
</div>
    </body>

</html>

0
Rohìt Jíndal On

Working demo :

var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl', function($scope) {
  $scope.jsonObj = {
     "openEHR": {
       "type": "DV_QUANTITY",
       "name": "Temperature",
       "serie": [{
        "magnitude": 34,
        "units": "°C",
        "date": "2016-12-28 13:23:32"
      }]
     }
   }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
  Type : {{jsonObj.openEHR.type}}<br>
  Name : {{jsonObj.openEHR.name}}<br>
  <div ng-repeat="item in jsonObj.openEHR.serie">
     Magnitude : {{item.magnitude}}
  </div>
</div>

0
Pablo Pazos On

It seems that is a query result from the EHRServer.

The "serie" object is always an array of objects compliant with the "type", so you need to first check the type, to know which fields to expect in the "serie" objects.

For a type = DV_QUANTITY you will always get "magnitude" and "units". The "date" will always be there when you "group by path".

You can find more in the official documentation https://cloudehrserver.com/learn

By the way, I'm the creator of the EHRServer. If you have questions about it, we have a community support chat https://gitter.im/CaboLabs/EHRServer