Testing contact summary

Hi,
I need some help improving this:

   const svReports = harness.state.reports.filter(r => r.fields.place_id === 'supervisor_area_id');
   const svContactSummary = await harness.getContactSummary('supervisor_area_id', svReports);
    expect(svContactSummary.context).to.deep.contain({
      stock_monitoring_sp_qty: 35
    });

At this point in harness.state I’ve reports attached, via the fields.place_id property, to the chw_area_id contact and others reports attached to the supervisor_area_id. In a more général case I could have reports attached with other object keys like, place_uuid, patient_id or others.

Is there another way to get from harness the reports of the contact supervisor_area_id, something like harness.getReports('supervisor_area_id') ?

This is not a direct answer to your question. But this is the signature for getContactSummary

getContactSummary(contact, reports, lineage)

If you just run getContactSummary('supervisor_area_id'), the default value of reports should be all of supervisor_area_id’s reports.

reports = An array of reports associated with contact. If left empty, the contact’s reports will be loaded from HarnessState

Is that not working for you as expected? Does it yield a different outcome from what you’re doing in this code snipet?

Hi @kenn


    harness.user = 'supervisor_id';
    harness.subject = 'supervisor_area_id';
    harness.pushMockedDoc({
      type: 'data_record',
      form: Forms.SMW_STOCK_RECEIPT,
      reported_date: DateTime.fromISO('2000-01-01T12:50:17').toMillis(),
      fields: { place_id: 'supervisor_area_id', sp_count: '35' },
      contact: {
        _id: 'supervisor_id',
        parent: {
          _id: 'supervisor_area_id',
          parent: {
            _id: 'health_area_id',
            parent: {
              _id: 'site_id'
            }
          }
        }
      }
    }
    );
    let svContactSummary = await 
    harness.getContactSummary('supervisor_area_id');
    console.log(svContactSummary.context.stock_monitoring_sp_qty);
    //this gives me 35 as expected

    harness.user = 'chw_area_contact_id';
    harness.subject = 'chw_area_id';
    harness.pushMockedDoc({
      type: 'data_record',
      form: Forms.SMW_STOCK_RECEIPT,
      reported_date: DateTime.fromISO('2000-01-01T12:51:17').toMillis(),

      fields: {place_id: 'chw_area_id', sp_count: '15' },
      contact: {
        _id: 'chw_area_contact_id',
        parent: {
          _id: 'chw_area_id',
          parent: {
            _id: 'supervisor_area_id',
            parent: {
              _id: 'health_area_id',
              parent: {
                _id: 'site_id'
              }
            }
          }
        }
      }
    });

    svContactSummary = await harness.getContactSummary('supervisor_area_id');
    console.log(svContactSummary.context.stock_monitoring_sp_qty);
   //this gives me 15

Our contact summary gets the latest stock_receipt, from this report the sp_count variable value is obtained and assigned to the stock_monitoring_sp_qty in the context,

I do not understand how the report with fields.place_id = ‘chw_area_id’ and sp_count = 15 is considered in the summary of ‘supervisor_area_id’, the contact.reports of supervisor_area_id are in this case, reports with fields.place_id equal to ‘supervisor_area_id’ and the reports belonging to supervisors (children) of supervisor_area_id, or where am I wrong ?

You’re right @victor. I’ve opened Contact Summary is passed reports of place's children even when that child is a place · Issue #272 · medic/cht-conf-test-harness · GitHub. Let me have a closer look.

A proposed fix is ready at Contact summary of a place should not receive reports of children which are places by kennsippell · Pull Request #273 · medic/cht-conf-test-harness · GitHub.

@bamatic Would you be available to test it out? \

Hi @kenn
Thank you very much, I will test it and let you know this week.

2 Likes

Hi @kenn
with the 272-reports-no-child-place branch I get now always 35 as expected, getContactSummary('supervisor_area_id')
only use reports related to ‘supervisor_area_id’
:grin:

1 Like

Fix is published as 5.0.3

4 Likes