Scored Observation Base Class¶
-
class
nh_observations.models.nh_clinical_patient_observation_scored.NhClinicalPatientObservationScored(pool, cr)[source]¶ Extends the ‘nh.clinical.patient.observation’ model to introduce the concept of a score. Provides a computed ‘score’ field with a default implementation for its calculation.
-
calculate_score(*args, **kwargs)[source]¶ Gets the values of the ‘score fields’ that contribute to the overall score of the observation and maps them to an integer score.
This generic score calculation implementation is then to simply sum all the individual fields scores to get the overall score for the observation.
Parameters: - obs_data (record or dict) – Observation field values. If an Odoo record is passed then the ‘score fields’ are looked up for the calculation. If a dictionary of field data is passed, only the fields in the dictionary are used.
- return_dictionary (bool) – Would you like the score returned in a dictionary?
Returns: scoreReturn type:
-
convert_field_values_to_labels(obs)[source]¶ Convert the values in the passed dictionary to their corresponding labels.
NOTE: Only converts fields whose names are not in the _scored class variable. This is a temporary implementation to get the functionality working for GCS / Neurological.
Parameters: obs (list) –
-
convert_field_values_to_scores(obs)[source]¶ Converts the values of all ‘score fields’ to their individual field scores.
Parameters: obs (list of dict) – Returns: Return type: list of dict
-
fields_view_get(*args, **kwargs)[source]¶ Hack to allow display of field scores instead of field values in Odoo views. When an Odoo view is rendered the field definitions are retrieved via this method as well as the field values themselves. Validation occurs client-side and if it fails the values seem to be silently omitted from the view.
This method intercepts the retrieval of the field definition and converts the type of the fields to ‘text’, effectively allowing the converted score value of the field (which is a string representation of a number) to pass validation.
Parameters: - args –
- kwargs –
Returns:
-
get_form_description(*args, **kwargs)[source]¶ Returns a description in dictionary format of the input fields that would be required in the user gui to submit the observation.
Parameters: patient_id (int) – patientidReturns: a list of dictionaries Return type: list
-
classmethod
get_score_for_value(model, field_name, field_value)[source]¶ The values of ‘score fields’ are decoupled from the integer score that they contribute to the overall score of the observation. This is to make changes to the scoring system easier as score values themselves are not stored in the database, so adding or changing the scores certain field values map to has less impact.
This method returns the integer score a field value represents based on the position it is declared in the fields ‘selection’ attribute.
Parameters: Returns: Return type:
-
read(*args, **kwargs)[source]¶ An override of read to ensure that for scored observations, reads will by default return the mapped score values for fields rather then their actual field values. Usually when read is called instead of browse it is because the raw data is needed to send over the network. Often in these situations the score value is desirable over the normal score-agnostic value.
The decision to make this behaviour default is based only on a few use cases encountered since starting to use this model, it may be that refactoring is appropriate in future.
Parameters: - fields –
- load –
- convert_field_values_to_scores (bool) –
Returns: Return type:
-
score¶
-