forked from streetcomplete/StreetComplete
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sketch attempt at adding medical specialities
- Loading branch information
1 parent
8374222
commit ca3ecde
Showing
9 changed files
with
201 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...src/main/java/de/westnordost/streetcomplete/quests/shop_type/MedicalSpecialityTypeForm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/de/westnordost/streetcomplete/quests/shop_type/ShopUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
} |
73 changes: 73 additions & 0 deletions
73
.../main/java/de/westnordost/streetcomplete/quests/shop_type/SpecifyMedicalSpecialityType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters