From 3e0745b47cb820f6877ef8304eed5e9aa0205aef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= <skunk@xover.mud.at>
Date: Fri, 22 Feb 2019 20:52:22 +0100
Subject: [PATCH] Health: rewrite to group similar tags (e.g. amenity=hospital
 and healthcare=hospital)

---
 health.json | 111 ++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 87 insertions(+), 24 deletions(-)

diff --git a/health.json b/health.json
index 0bff69b..7f1119b 100644
--- a/health.json
+++ b/health.json
@@ -48,53 +48,116 @@
             "  {% set value = tags.emergency %}",
             "{% elseif tags.healthcare %}",
             "  {% set key = 'healthcare' %}",
-            "  {% set value = tags.healthcare %}",
+            "  {% set value = tags.healthcare|split(';')[0] %}",
             "{% else %}",
             "  {% set key = 'amenity' %}",
             "  {% set value = tags.amenity %}",
-            "{% endif %}"
+            "{% endif %}",
+            "{% set kv = key ~ '=' ~ value %}",
+            "{% set found = { sign: '' } %}",
+            "{% for data in const %}",
+            "  {% if kv in data.types %}{% set found = data %}{% endif %}",
+            "{% endfor %}"
         ],
         "description": [
-            "{{ tagTransList(key, value) }}",
+            "{{ tagTransList(key, attribute(tags, key)) }}",
             "{% if attribute(tags, 'healthcare:speciality') %}",
             "-",
             "{{ tagTransList('healthcare:speciality', attribute(tags, 'healthcare:speciality')) }}",
             "{% endif %}"
         ],
-        "markerSign": "{{ const[key ~ '=' ~ value]|raw }}"
+        "markerSign": "{{ found.sign|raw }}"
     },
     "info": [
         "<table>",
-        "{% for value, sign in const %}",
+        "{% for data in const %}",
         "  <tr>",
-        "    <td>{{ markerCircle({})|raw }}<div class='sign'>{{ sign|raw }}</div></td>",
-        "    <td>{{ tagTrans(value|split('=')[0], value|split('=')[1]) }}</td>",
+        "    <td>{{ markerCircle({})|raw }}<div class='sign'>{{ data.sign|raw }}</div></td>",
+        "    <td>{{ tagTrans(data.types[0]|split('=')[0], data.types[0]|split('=')[1]) }}</td>",
         "  </tr>",
         "{% endfor %}",
         "</table>"
     ],
-    "const": {
-        "amenity=baby_hatch": "🚼",
-        "healthcare=blood_bank": "<img src='maki:blood-bank'>",
-        "healthcare=blood_donation": "<img src='maki:blood-bank'>",
-        "healthcare=clinic": "🏥",
-        "emergency=defibrillator": "<img src='maki:defibrillator'>",
-        "healthcare=dentist": "<img src='maki:dentist'>",
-        "healthcare=doctor": "<img src='maki:doctor'>",
-        "amenity=doctors": "<img src='maki:doctor'>",
-        "amenity=hospital": "🏥",
-        "healthcare=hospital": "🏥",
-        "amenity=nursing_home": "",
-        "amenity=pharmacy": "<img src='maki:pharmacy'>",
-        "amenity=social_facility": "",
-        "amenity=veterinary": "<img src='maki:veterinary'>"
-    },
+    "const": [
+        {
+            "types": [
+                "amenity=baby_hatch"
+            ],
+            "sign": "🚼"
+        },
+        {
+            "types": [
+                "healthcare=blood_bank"
+            ],
+            "sign": "<img data-src='maki:blood-bank'>"
+        },
+        {
+            "types": [
+                "healthcare=blood_donation"
+            ],
+            "sign": "<img data-src='maki:blood-bank'>"
+        },
+        {
+            "types": [
+                "healthcare=clinic"
+            ],
+            "sign": "🏥"
+        },
+        {
+            "types": [
+                "emergency=defibrillator"
+            ],
+            "sign": "<img data-src='maki:defibrillator'>"
+        },
+        {
+            "types": [
+                "healthcare=dentist"
+            ],
+            "sign": "<img data-src='maki:dentist'>"
+        },
+        {
+            "types": [
+                "healthcare=doctor",
+                "amenity=doctors"
+            ],
+            "sign": "<img data-src='maki:doctor'>"
+        },
+        {
+            "types": [
+                "amenity=hospital",
+                "healthcare=hospital"
+            ],
+            "sign": "🏥"
+        },
+        {
+            "types": [
+                "amenity=nursing_home"
+            ]
+        },
+        {
+            "types": [
+                "amenity=pharmacy"
+            ],
+            "sign": "<img data-src='maki:pharmacy'>"
+        },
+        {
+            "types": [
+                "amenity=social_facility"
+            ]
+        },
+        {
+            "types": [
+                "amenity=veterinary"
+            ],
+            "sign": "<img data-src='maki:veterinary'>"
+        }
+    ],
     "filter": {
         "type": {
             "name": "{{ trans('filter:type') }}",
             "show_default": "true",
             "type": "select",
-            "values": "{% for k, v in const %}<option value=\"{{ k }}\" query=\"nwr[{{ k }}]\" minzoom=\"{{ v.zoom }}\">{{ tagTrans(k) }}</option>{% endfor %}"
+            "values": "{% for data in const %}<option value=\"{{ data.types[0] }}\" query=\"({% for t in data.types %}nwr[{{ t }}];{% endfor %})\" minzoom=\"{{ data.zoom }}\">{{ tagTrans(data.types[0]) }}</option>{% endfor %}"
         }
     }
 }