Recreate SRO Liver Function Testing key measure with Streamlit #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@alarthast and I worked together on this solution to recreate the SRO Liver Function Testing key measure with Streamlit.
Alice, I'd like to highlight the architecture of the solution.
app/sro_key_measures.py
is the presentation (application) layer; it constructs the user interface.app/measures.yaml
is, very loosely, the persistent storage (database) layer. Sitting between the two is a repository (OSJobsRepository
), which constructs domain model objects (Measure
) using information from the persistent storage layer and passes them to the presentation layer. You can find out more about layers, repositories, and domain model objects in Chapters 1 and 2 of Architecture Patterns with Python.I'm still learning about layers, repositories, and domain model objects myself, so we shouldn't assume that the solution is the only solution 🙂. However, I think that a well-defined architecture is going to help us iterate quickly.
You many have noticed the following:
open-pathology/justfile
Line 67 in aceb486
Streamlit Community Cloud seems to set
PYTHONPATH
to the directory within which the "main file" is located, which in this case isapp/sro_key_measures.py
. However, it's more convenient forPYTHONPATH
to be the project root directory. Imports are then relative to the project root directory...open-pathology/app/sro_key_measures.py
Line 3 in aceb486
...which makes interacting with code in a REPL, such as IPython, less faffy. However, when we deploy the app, we must remember to set
PYTHONPATH
. It looks like the mechanism for doing so is the same as that for managing secrets.You asked why I decided not to nest the various URLs in
app/measures.yaml
. That is, why this......rather than this...
I took the Zen of Python's advice that "Flat is better than nested." (
import this
). Thinking about it more, though, I don't think there's any reason why these URLs need to be grouped: We don't, for example, group strings or integers; or OS Jobs URLs and OpenCodelists URLs. So, I decided not to nest the various URLs. The flat structure of each record inapp/measures.yaml
is also consistent with the flat structure ofMeasure
.Closes #2