2018年9月14日金曜日

④検査結果表示について4

前回のコメントを参考にしながら再び編集を試みた。
  1. function(countries) {
  2. var list = countries.list[0];
  3. that.list = [];
  4. list.items.forEach(function(element){
  5. var normalValue = element.normalValue.split(/-/);
  6. var lower = parseFloat(normalValue[0]);
  7. var upper = parseFloat(normalValue[1]);
  8. var bgColor;
  9. if(element.value >= lower && element.value <= upper){
  10. bgColor ="normal";}else{
  11. bgColor ="abnormal";
  12. }
  13. that.list.push(
  14. {
  15. itemName:element.itemName,
  16. value:Math.round(element.value *100) /100 ,
  17. unit:element.unit,
  18. bgColor:bgColor
  19. }
  20. );
  21. });
まず、上記のリスト配列を、下記のものに差し替える。
  1. function(countries) {
  2. // 直近の検査日の検査結果を変数 list に格納
  3. var list = countries.list[0];
  4. // 検査グループ配列を空配列に初期化
  5. that.group = [];
  6. // 個々の検査グループを格納するための一変数を null で初期化
  7. var group = null;
  8. // 検査結果項目配列 list.items の個々の要素 element に対してループ処理
  9. list.items.forEach(function(element){
  10. // elementが一番最初の検査結果項目の場合、groupを初期化する
  11. if(group == null) {
  12. group = {
  13. 'groupName': element.groupName,
  14. 'items': []
  15. };
  16. // 検査グループが変わったとき、groupを検査グループ配列に追加してからgroupを初期化する
  17. } else if(group.groupName != element.groupName){
  18. that.group.push(group);
  19. group = {
  20. 'groupName': element.groupName,
  21. 'items': []
  22. };
  23. }
  24. // 基準値を求めて normalValue 変数に格納する
  25. var normalValue = getNormalValueRange(element.normalValue);
  26. // 基準値と検査結果を比較して背景色を決める
  27. var bgColor;
  28. if(element.value >= normalValue.lower && element.value <= normalValue.upper){
  29. bgColor ="normal";}else{
  30. bgColor ="abnormal";
  31. }
  32. // グループに検査結果を追加する
  33. group.items.push(
  34. {
  35. 'itemName': element.itemName,
  36. 'value': round(element.value), // 四捨五入
  37. 'unit': element.unit,
  38. 'bgColor': bgColor,
  39. }
  40. );
  41. });
  42. // 最後のgroupを検査グループ配列に追加する
  43. if(group != null) {
  44. that.group.push(group);
  45. }
  46. }
  47. );
また、getNormalValueRange関数およびround関数の定義を以下の様に行った。
  1. /*
  2. 基準値の下限と上限を求める
  3. */
  4. function getNormalValueRange(normalValue) {
  5. var normalValue = normalValue.split(/-/);
  6. var lower = parseFloat(normalValue[0]);
  7. var upper = parseFloat(normalValue[1]);
  8. return {
  9. lower: lower,
  10. upper: upper,
  11. };
  12. }
  13.  
  14. /*
  15. 四捨五入(小数第3位)
  16. */
  17. function round(value) {
  18. return Math.round(value * 100) / 100;
  19. }
jsのグループ対応付けが完了したところで、次にHTMLの編集を行う。
  1. <ons-list>
  2. <ons-list-item class="{{country.bgColor}}" ng-click="countries.showCountry(country.itemName)" modifier="chevron" ng-repeat="country in countries.list | filter:query">
  3. <ons-col width="50%">{{ country.itemName }}</ons-col>
  4. <ons-col>{{country.value}}</ons-col>
  5. <ons-col>{{country.unit}}</ons-col>
  6. </ons-list-item>
  7. </ons-list>
HTMLのこの記述を、以前のブログのコメントに記載されていたこの形式に書き換えた。
  1. <ons-list ng-repeat="group in countries.group">
  2. <ons-list-header>{{ group.groupName }}</ons-list-header>
  3. <ons-list-item class="{{country.bgColor}}" ng-click="countries.showCountry(country.itemName)" modifier="chevron" ng-repeat="country in group.items | filter:query">
  4. <ons-col width="65%">{{ country.itemName }}</ons-col>
  5. <ons-col>{{ country.value }}{{ country.unit }}</ons-col>
  6. </ons-list-item>
  7. </ons-list>
上記の書き換えを行った後、スマートフォンで確認したところ、以下の図1の様な結果が表示された。
図1 グルーピング処理を行った後の画面

こうして、なんとかグループごとに検査項目の表示を行う事が出来た。
次回は過去の検査データの表示が行えるような処理を行っていきたい。

【コメント】
検査項目のグルーピングができました。過去の検査データは 配列countries.listの中に入っています。だから、3行目の
var list = countries.list[0];
で、指定した日付に対応する配列要素を取り出せばよいでしょう(この場合は先頭の配列要素を取り出しているので直近の検査結果になっています)。やってみてください。

その前に、図1に表示された検査グループ名称「生化学的検査」ですが、デフォルトの表示だと控えめすぎるので、もっと存在感を出した方が良いように思います。 例えばCARADA健診手帳のような画面を参考にしてCSSを使って画面をデザインしてはどうでしょう?

0 件のコメント:

コメントを投稿

レーダーチャートの表示2

前回 レーダーチャートの表示を行うことが出来たので、今回は実際の値を代入したグラフの描画を試みる。 .controller('RaderChartController', ['$scope', 'Countries', funct...