Skip to content

Commit

Permalink
sketch attempt at adding medical specialities
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoniecz committed Feb 5, 2023
1 parent 8374222 commit ca3ecde
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import de.westnordost.streetcomplete.osm.replaceShop
import de.westnordost.streetcomplete.overlays.AbstractOverlayForm
import de.westnordost.streetcomplete.overlays.AnswerItem
import de.westnordost.streetcomplete.quests.LocalizedNameAdapter
import de.westnordost.streetcomplete.quests.shop_type.topFeatureCodesOfPopularShoplikePOIs
import de.westnordost.streetcomplete.util.getLocalesForFeatureDictionary
import de.westnordost.streetcomplete.util.getLocationLabel
import de.westnordost.streetcomplete.util.ktx.geometryType
Expand Down Expand Up @@ -110,7 +111,8 @@ class ShopsOverlayForm : AbstractOverlayForm() {
countryOrSubdivisionCode,
featureCtrl.feature?.name,
::filterOnlyShops,
::onSelectedFeature
::onSelectedFeature,
topFeatureCodesOfPopularShoplikePOIs()
).show()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ import de.westnordost.streetcomplete.quests.seating.AddSeating
import de.westnordost.streetcomplete.quests.segregated.AddCyclewaySegregation
import de.westnordost.streetcomplete.quests.self_service.AddSelfServiceLaundry
import de.westnordost.streetcomplete.quests.shop_type.CheckShopType
import de.westnordost.streetcomplete.quests.shop_type.SpecifyMedicalSpecialistType
import de.westnordost.streetcomplete.quests.shop_type.SpecifyShopType
import de.westnordost.streetcomplete.quests.sidewalk.AddSidewalk
import de.westnordost.streetcomplete.quests.smoking.AddSmoking
Expand Down Expand Up @@ -518,6 +519,7 @@ fun questTypeRegistry(
1000014 to SpecifyBarrier(), // my own quest
96 to AddRoadName(),
80 to AddPlaceName(featureDictionaryFuture),
1000015 to SpecifyMedicalSpecialistType(),
// --modified heavily

// kept--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package de.westnordost.streetcomplete.quests.shop_type

import android.os.Bundle
import android.view.View
import android.widget.RadioButton
import de.westnordost.osmfeatures.Feature
import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.databinding.ViewShopTypeBinding
import de.westnordost.streetcomplete.quests.AbstractOsmQuestForm
import de.westnordost.streetcomplete.util.ktx.geometryType
import de.westnordost.streetcomplete.view.controller.FeatureViewController
import de.westnordost.streetcomplete.view.dialogs.SearchFeaturesDialog

class MedicalSpecialityTypeForm : AbstractOsmQuestForm<ShopTypeAnswer>() {

override val contentLayoutResId = R.layout.view_shop_type // TODO?
private val binding by contentViewBinding(ViewShopTypeBinding::bind)

private lateinit var radioButtons: List<RadioButton>
private var selectedRadioButtonId: Int = 0
private lateinit var featureCtrl: FeatureViewController

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

radioButtons = listOf(binding.vacantRadioButton, binding.replaceRadioButton, binding.leaveNoteRadioButton)
for (radioButton in radioButtons) {
radioButton.setOnClickListener { selectRadioButton(it) }
}

featureCtrl = FeatureViewController(featureDictionary, binding.featureView.textView, binding.featureView.iconView)
featureCtrl.countryOrSubdivisionCode = countryOrSubdivisionCode

binding.featureView.root.background = null
binding.featureContainer.setOnClickListener {
selectRadioButton(binding.replaceRadioButton)

SearchFeaturesDialog(
requireContext(),
featureDictionary,
element.geometryType,
countryOrSubdivisionCode,
featureCtrl.feature?.name,
::filterOnlySpecialitiesOfMedicalDoctors,
::onSelectedFeature,
listOf( // see https://taginfo.openstreetmap.org/keys/healthcare%3Aspeciality#values with chiropractic skipped (pseudomedicine), biology (no entry in presets)
"amenity/doctors/general",
"amenity/doctors/ophthalmology",
"amenity/doctors/paediatrics",
"amenity/doctors/gynaecology",
// dentist ?
// psychiatry - https://github.com/openstreetmap/id-tagging-schema/issues/778
"amenity/doctors/orthopaedics",
"amenity/doctors/internal",
// orthodontics
// dermatology
// osteopathy
// otolaryngology
// radiology
)
).show()
}
}

private fun filterOnlySpecialitiesOfMedicalDoctors(feature: Feature): Boolean {
if (!feature.tags.containsKey("healthcare:speciality")) {
return false
}
return feature.tags["amenity"] == "doctors"
}

private fun onSelectedFeature(feature: Feature) {
featureCtrl.feature = feature
checkIsFormComplete()
}

override fun onClickOk() {
when (selectedRadioButtonId) {
R.id.vacantRadioButton -> applyAnswer(IsShopVacant)
R.id.leaveNoteRadioButton -> composeNote()
R.id.replaceRadioButton -> applyAnswer(ShopType(featureCtrl.feature!!.addTags))
}
}

override fun isFormComplete() = when (selectedRadioButtonId) {
R.id.vacantRadioButton,
R.id.leaveNoteRadioButton -> true
R.id.replaceRadioButton -> featureCtrl.feature != null
else -> false
}

private fun selectRadioButton(radioButton: View) {
selectedRadioButtonId = radioButton.id
for (b in radioButtons) {
b.isChecked = selectedRadioButtonId == b.id
}
checkIsFormComplete()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class ShopGoneDialog(
countryCode,
featureCtrl.feature?.name,
::filterOnlyShops,
::onSelectedFeature
::onSelectedFeature,
topFeatureCodesOfPopularShoplikePOIs()
).show()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class ShopTypeForm : AbstractOsmQuestForm<ShopTypeAnswer>() {
countryOrSubdivisionCode,
featureCtrl.feature?.name,
::filterOnlyShops,
::onSelectedFeature
::onSelectedFeature,
topFeatureCodesOfPopularShoplikePOIs()
).show()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.westnordost.streetcomplete.quests.shop_type

fun topFeatureCodesOfPopularShoplikePOIs(): List<String> {
// ordered by usage number according to taginfo
return listOf(
"amenity/restaurant",
"shop/convenience",
"amenity/cafe",
"shop/supermarket",
"amenity/fast_food",
"amenity/pharmacy",
"shop/clothes",
"shop/hairdresser"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package de.westnordost.streetcomplete.quests.shop_type

import de.westnordost.streetcomplete.R
import de.westnordost.streetcomplete.data.osm.geometry.ElementGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.Element
import de.westnordost.streetcomplete.data.osm.mapdata.MapDataWithGeometry
import de.westnordost.streetcomplete.data.osm.mapdata.filter
import de.westnordost.streetcomplete.data.osm.osmquests.OsmFilterQuestType
import de.westnordost.streetcomplete.data.user.achievements.EditTypeAchievement.CITIZEN
import de.westnordost.streetcomplete.osm.IS_SHOP_OR_DISUSED_SHOP_EXPRESSION
import de.westnordost.streetcomplete.osm.Tags
import de.westnordost.streetcomplete.osm.removeCheckDates

class SpecifyMedicalSpecialistType : OsmFilterQuestType<ShopTypeAnswer>() {

override val elementFilter = """
nodes, ways with (
amenity = doctors and !healthcare:speciality
and !man_made
and !historic
and !military
and !power
and !tourism
and !attraction
and !leisure
and !aeroway
and !railway
and !craft
and (!healthcare or healthcare = doctor)
and !office
and !shop
)
""" // add test to protect against future me adding !amenity here, see similar test for shop=yes quest, the same for healthcare = doctor

override val changesetComment = "Survey specialities of medical practicioners"
override val wikiLink = "Key:healthcare:speciality"
override val icon = R.drawable.ic_quest_crown // TODO
override val isReplaceShopEnabled = true
override val achievements = listOf(CITIZEN)

override fun getTitle(tags: Map<String, String>) = R.string.quest_medical_speciality_type_title

override fun getHighlightedElements(element: Element, getMapData: () -> MapDataWithGeometry) =
getMapData().filter(IS_SHOP_OR_DISUSED_SHOP_EXPRESSION) // TODO

override fun createForm() = MedicalSpecialityTypeForm()

override fun applyAnswerTo(answer: ShopTypeAnswer, tags: Tags, geometry: ElementGeometry, timestampEdited: Long) {
tags.removeCheckDates()
when (answer) {
is IsShopVacant -> {
tags.remove("amenity")
if (tags.containsKey("healthcare")) {
tags.remove("healthcare")
}
tags["disused:shop"] = "yes"
}
is ShopType -> {
if (!answer.tags.containsKey("amenity")) {
tags.remove("amenity")
}
if (!answer.tags.containsKey("healthcare")) {
if (tags.containsKey("healthcare")) {
tags.remove("healthcare")
}
}
for ((key, value) in answer.tags) {
tags[key] = value
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class SearchFeaturesDialog(
private val countryOrSubdivisionCode: String? = null,
text: String? = null,
private val filterFn: (Feature) -> Boolean = { true },
private val onSelectedFeatureFn: (Feature) -> Unit
private val onSelectedFeatureFn: (Feature) -> Unit,
private val quickAceessValues: List<String>
) : AlertDialog(context) {

private val binding = ViewSelectPresetBinding.inflate(LayoutInflater.from(context))
Expand All @@ -37,17 +38,7 @@ class SearchFeaturesDialog(
private val searchText: String? get() = binding.searchEditText.nonBlankTextOrNull

private val defaultFeatures: List<Feature> by lazy {
listOf(
// ordered by usage number according to taginfo
"amenity/restaurant",
"shop/convenience",
"amenity/cafe",
"shop/supermarket",
"amenity/fast_food",
"amenity/pharmacy",
"shop/clothes",
"shop/hairdresser"
).mapNotNull {
quickAceessValues.mapNotNull {
featureDictionary
.byId(it)
.forLocale(*locales)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,8 @@ If there are no signs along the whole street which apply for the highlighted sec
<string name="quest_maxweight_answer_other_sign">Sign looks different…</string>
<string name="quest_maxweight_unsupported_sign_request_photo">Would you like to leave a note? A note with a photo will enable other mappers to take care of it.</string>

<string name="quest_medical_speciality_type_title">What type of doctor is this?</string>

<string name="quest_memorialType_title">What kind of memorial is this?</string>
<string name="quest_memorialType_statue">Statue</string>
<string name="quest_memorialType_bust">Bust</string>
Expand Down

0 comments on commit ca3ecde

Please sign in to comment.