Targets not being updated

Hi all,

Is there any reason the targets wouldn’t get updated anymore? is there maybe a field in the form that is expected?
I have an expression to trigger only when a particular form has been filled and I am sure the right form is being filled and uploaded to the server (can see it by other users). It used to work but doesn’t work anymore. When I change it to all values as opposed to monthly, it shows particular forms from a while back but not the most recent ones. Is there a direction someone could point me out to?

{
    id: 'assessments-total',
    type: 'count',
    icon: 'icon-infant',
    goal: -1,
    translation_key: 'targets.assessment.exams.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'reports',
    appliesToType: ['yi'],
    date: 'reported',
    idType:'report'
}

Hi @magp18

I don’t think any form fields are required to count for targets (except when you add your own appliesIf functions).
Can you please provide an example of a report that should be counted but isn’t?

Hi @diana I am not sure if I can share it but will do if possible, meanwhile I will try to give you what I think might help.
I do have appliesIf functions but without that and just with the one posted, that should be independent, I am not getting a count up which is strange.
We are performing the forms from a location, not from a patient.
We set the targets to have values of all time and after deleting some and checking if the value goes up or down we noticed that forms being counted have “Submitted by Clinician …” in the report tag underneath the hiearchy, as opposed to others without. I am not sure what the issue is, but could this be related?

Hi @magp18

Unfortunately, without seeing one of these reports, I can’t really tell.
Please share the report (you can redact the PHI) and the target config, including the appliesIf functions.

I did a small one with dummy data:
report not triggering either total consultation as per definition above or severe jaundice as per definition below

{
    "_id": "15c1a789-5f80-4c25-9d27-79854163bf58",
    "_rev": "1-3cdeec3e02e898a76c4e9f64325ba2dc",
    "form": "yi",
    "type": "data_record",
    "content_type": "xml",
    "reported_date": 1664862649042,
    "contact": {
      "_id": "20731cda-950f-525e-9651-2bd54ade04d2",
      "parent": {
        "_id": "677f8849-e2b4-5d5c-915a-ee496441d594",
        "parent": {
          "_id": "930e8b2d-a7d3-57a3-8fbf-540d785e464f"
        }
      }
    },
    "from": "",
    "hidden_fields": [
      "meta"
    ],
    "fields": {
      "inputs": {
        "meta": {
          "location": {
            "lat": "",
            "long": "",
            "error": "",
            "message": ""
          },
          "deprecatedID": ""
        },
        "source": "contact",
        "source_id": "",
        "user": {
          "contact_id": "20731cda-950f-525e-9651-2bd54ade04d2",
          "facility_id": "677f8849-e2b4-5d5c-915a-ee496441d594",
          "name": "head-template"
        },
        "contact": {
          "_id": "677f8849-e2b4-5d5c-915a-ee496441d594",
          "data_load": ""
        }
      },
      "created_by_person_uuid": "20731cda-950f-525e-9651-2bd54ade04d2",
      "created_by_place_uuid_user": "677f8849-e2b4-5d5c-915a-ee496441d594",
      "created_by": "head-template",
      "created_by_place_uuid": "677f8849-e2b4-5d5c-915a-ee496441d594",
      "place_data_load": "",
      "init": {
        "_id": "20731cda-950f-525e-9651-2bd54ade04d2",
        "role": "",
        "name": "Project Head Template"
      },
      "person_uuid": "20731cda-950f-525e-9651-2bd54ade04d2",
      "person_name": "Project Head Template",
      "person_role": "",
      "ds_ASAQ": "1",
      "ds_azythro": "1.5",
      "ds_AZT": "1.5",
      "gt_danger_signs": {
        "select_danger_signs": "opt_none",
        "boolt_danger_signs": ""
      },
      "g_regisration": {
        "unit_age": "opt_2",
        "p_age_days": "2",
        "p_weight": "3",
        "gender": "male",
        "p_temp": "36",
        "label_rr_rate": "",
        "respiratory_rate": "55"
      },
      "d_hypothermia": "0",
      "d_fever": "0",
      "d_temperature_normal": "1",
      "d_pneumonia": "0",
      "p_age": "2",
      "gt_danger_signs_additional": {
        "select_danger_signs_additional": "opt_4",
        "boolt_danger_signs_additional": ""
      },
      "d_jaundice_severe": "1",
      "dm_d_jaundice_severe": "",
      "d_infection_syphilis_unlikely": "0",
      "screening_syphilis_finished": "0",
      "screening_tbc_finished": "0",
      "summary": {
        "label_summary_details": "",
        "label_patient_details": "",
        "gender_name": "Boy",
        "label_summary": "",
        "label_jaundice_severe": "",
        "label_danger_signs": "",
        "label_ds_convulsions": "",
        "label_referrals": ""
      },
      "load_malaria_transmission_area": "0",
      "load_glucometer": "0",
      "d_vsd": "0",
      "d_malaria_severe_possible": "0",
      "d_malaria_severe": "0",
      "referral": "0",
      "g_tt": {
        "facility24h": "0",
        "d_risk_syhpilis_congenital_low": "0",
        "d_risk_syhpilis_congenital_high": "0"
      },
      "g_tt2": {
        "label_e_9rE0Or44ScOD_MXuO2-2": "",
        "label_35hSubIr_pK7-H9XSdCW-17": ""
      },
      "g_L7sjl3C3wMsvSdH2PupB-113": {
        "tt_appropriate": "opt_1",
        "label_h14JGrknZNCZngEn730B-118": "",
        "immunization_status": "opt_1"
      },
      "text_end": "",
      "meta": {
        "instanceID": "uuid:fd295645-9366-462c-9716-8804611e6ec0"
      }
    },
    "_attachments": {
      "content": {
        "content_type": "application/xml",
        "revpos": 1,
        "digest": "md5-eSqyTA1+/G8OOLhr6PnvDQ==",
        "length": 11425,
        "stub": true
      }
    }
  }

Target severe jaundice def:

{
    id: 'assessments-severe-jaundice',
    type: 'count',
    icon: 'icon-infant',
    goal: -1,
    translation_key: 'targets.severe.jaundice.title',
    subtitle_translation_key: 'targets.this_month.subtitle',
    appliesTo: 'reports',
    appliesToType: ['yi'],
    appliesIf: function (contact, report) {
      return hasCondition(contact, report, 'd_jaundice_severe');
    },
    date: 'reported',
    idType: 'report'
  },
function hasCondition(contact, report, condition) {
  if (getField(report,condition)){
    const has_condition = getField(report,condition).valueOf();
    return has_condition ==='1' || has_condition.toLowerCase().trim() ==='yes';
  }else {return false;}
}

As for the assessments-severe-jaundice, the appliesToType does not match the report form: young_infant vs yi. Is this an error in redacting or the actual target definition?

total consultation target definition is exactly the one you shared above?

yes, error form redacting sorry, those should match.
The one for the consultation is the exact one from above

Are any of the field names (not values) in the report redacted?

no, only values. And removed the geo location object (shouldn’t be relevant right?)

1 Like

Sorry for not getting back to this in good time, it’s on my to-do list for tomorrow.

1 Like

The way reports are associated with a contact is with a couple of fields: patient_id, patient_uuid, place_id or place_uuid. More details about schema: Database schema conventions | Community Health Toolkit
We also support case based workflows, and reports can be associated with a case via the case_id field.

Currently, reports that are not associated with any contact or case are not taken into consideration when calculating tasks or targets. I believe this limitation existed to some extent historically, ever since targets were introduced, and became established when tasks and targets became persistent on disk (because of the view that is queried to retrieve reports: cht-core/ddocs/medic-db/medic-client/views/reports_by_subject/map.js at master · medic/cht-core · GitHub) .

In your report, I’m not seeing any of the schema fields that would associate it with a contact, however I see you have a person_uuid? Are you intentionally not associating these reports with the contacts they are reported against? If not, I think your task calculation will work if you change this field to patient_uuid (or have both fields).

I’m going to enquire internally if there are any use cases where we want to count targets on reports that don’t have a subject (association to a contact or a case).

Thank you for looking this up! Yes we changed it to not include the patient ID (we are assessing them on a facility level) so that we can keep data anonymized (we are not using the electronic health record feature of CHT). But from your message, including a case_id would already do the job right?

Unfortunately, I don’t think so :frowning: (Source: I tried and I had to make code changes in 3 places to get my target to count a report that had only a case_id field).

I think this is a bug or miss in case based workflows. Looking at the original commit, there was an explicit intent to support tasks for case based workflows (Ability to generate case_id short codes · Issue #6291 · medic/cht-core · GitHub) but targets were never mentioned.

I’ve added an issue in cht-core to get opinions about this further: Reports from `case_id` based workflows don't count as target emissions · Issue #7833 · medic/cht-core · GitHub

To make things clear, right now only reports that are associated with a contact will be counted towards targets.

1 Like

Thanks for clarifying and creating an issue!