Outbound Push: Full Doc

Hi all,

Is it possible to post a full document via outbound push without mapping?

2 Likes

Hi @irene

From what I can tell, this is not possible. I would not think it’s advisable either, since a lot of documents will contain CouchDb metadata (like _attachments for example) or CHT-Core metadata which would not be relevant outside of the CHT scope.

Can you please share a few more details about your use-case and the need to push a whole document?
Thanks!

Source code: cht-core/shared-libs/outbound/src/outbound.js at master · medic/cht-core · GitHub

1 Like

Thank you @diana.

The need to push a whole doc was informed by having most of the fields from person registration being sent to another service, and also visibility of the payload in the service.

There’s probably some other use-cases perhaps @kitsao can add on to this.

1 Like

Hey @diana,

One of the echis integration points is community referrals by CHVs to be added to a shared health record (FHIR) to be consumed at health facility via an EHR system.

  • We are required to push danger signs screening info and if applicable, medication given.
  • The datapoints are not necessarily configured in the same groups or fields in the forms.
  • There are about 10 forms that are sources of the data.

We wish to configure a generic outbound push module (rather than a module for each of the forms) to serve all 10 sources then handle the formatting logic in the OpenHIM mediator.

  • Quickest way out would be to push whole docs.
  • Higher LoE way would be to update the source forms to include a uniform section to hold the information required.
  • Inconvenient way would be to write a module per source form.

cc @irene

1 Like

@diana

I will try but it might be possible because it seems that obectpath.get can retrieve complex object

    "mapping":{
      "orgUnit": "doc.fields.inputs.contact.external_id",
      "reported_date": "doc.reported_date",
      "case_id":"doc._id",
      "properties: "doc.fields"
   }

I will keep you posted

1 Like

doc.fields seems to work fine

1 Like

little follow up because doc.fields have the full structure which can be annoying to process (in my case the structure does not matter because I don’t use repeats)

this is a openFN lightining job that flatten the payload

alterState((state) => {
  // Function to process object entries and flatten the structure
  const processObjectEntries = (result, entries, prefix = '') => {
    for (let [key, value] of entries) {
      const newKey =  key; // Create a flat key with dot notation
      if (value === null || typeof value !== 'object') {
        result[newKey] = value; // Store leaf value in result
      } else {
        // Recursively process nested objects or arrays
        if (Array.isArray(value)) {
          value.forEach((item, index) => {
            processObjectEntries(result, Object.entries(item), `${newKey}[${index}]`);
          });
        } else {
          processObjectEntries(result, Object.entries(value), newKey);
        }
      }
    }
    return result;
  };

  // Initialize result as an object, not an array
  let result = {};
  
  // Start processing with the state.data
  result = processObjectEntries(result, Object.entries(state.data.properties));

  // Update state.data with the flattened result
  state.data.properties= result;

  return state;
});