Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Default FHIR Patient to DHIS 2 Tracked Entity Instance Mapping (1.0)

Volker edited this page Jan 22, 2019 · 1 revision

This page describes the default mapping of FHIR patient to DHIS 2 tracked entity instance mapping and how this can be modified.

The adapter has two pre-configured rules for the transformation of FHIR resource Patient and FHIR resource RelatedPerson that perform the transformation of the included data to the DHIS 2 tracked entity type Person. The FHIR resource RelatedPerson (has no ID and exists just within the FHIR resource Patient) may be a contained resource of the FHIR resource Patient.

The two rules have the following unique names:

  • FHIR Patient transformation: FHIR Patient to Person
  • FHIR RelatedPerson transformation: FHIR Related Person to Person

The rule configuration for the transformation of FHIR Patient can be retrieved by executing the following command:

$ -i -u 'admin:district' 'http://localhost:8081/api/rules?name=FHIR+Patient+to+Person'
{
  "_embedded" : {
    "trackedEntityRules" : [ {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "name" : "FHIR Patient to Person",
      "description" : null,
      "enabled" : true,
      "evaluationOrder" : 0,
      "dhisResourceType" : "TRACKED_ENTITY",
      "fhirResourceType" : "PATIENT",
      "containedAllowed" : false,
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35"
        },
        "trackedEntityRule" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35"
        },
        "locationLookupScript" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35/locationLookupScript"
        },
        "applicableInScript" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35/applicableInScript"
        },
        "teiLookupScript" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35/teiLookupScript"
        },
        "applicableCodeSet" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35/applicableCodeSet"
        },
        "orgUnitLookupScript" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35/orgUnitLookupScript"
        },
        "transformInScript" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35/transformInScript"
        },
        "trackedEntity" : {
          "href" : "http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35/trackedEntity"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8081/api/rules{?page,size,sort}",
      "templated" : true
    },
    "profile" : {
      "href" : "http://localhost:8081/api/profile/rules"
    },
    "search" : {
      "href" : "http://localhost:8081/api/rules/search"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 1,
    "totalPages" : 1,
    "number" : 0
  }
}

The JavaScript that performs the transformation is referenced by the link transformInScript above. The corresponding executable script can be returned by executing the following command:

$  curl -u 'admin:district' http://localhost:8081/api/trackedEntityRules/5f9ebdc9-852e-4c83-87ca-795946aabc35/transformInScript

{
  "createdAt" : "2018-11-19T01:54:36.276Z",
  "lastUpdatedBy" : null,
  "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
  "name" : "Transforms FHIR Patient to DHIS Person",
  "code" : "TRANSFORM_FHIR_PATIENT_DHIS_PERSON",
  "description" : "Transforms FHIR Patient to DHIS Person.",
  "overrideArguments" : [ ],
  "_links" : {
    "self" : {
      "href" : "http://localhost:8081/api/executableScripts/72451c8f-7492-4707-90b8-a3e0796de19e"
    },
    "executableScript" : {
      "href" : "http://localhost:8081/api/executableScripts/72451c8f-7492-4707-90b8-a3e0796de19e"
    },
    "script" : {
      "href" : "http://localhost:8081/api/executableScripts/72451c8f-7492-4707-90b8-a3e0796de19e/script"
    }
  }
}

More than one executable script may exist for one script. Each executable script may override arguments of the script itself. This increases the reusability of the script itself. The script above does not override an argument of the script. Als arguments will be taken from the script itself when performing the transformation. By executing the following command the script definition itself can be returned:

$ curl -u 'admin:district' http://localhost:8081/api/executableScripts/72451

{
  "createdAt" : "2018-11-19T01:54:36.276Z",
  "lastUpdatedBy" : null,
  "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
  "name" : "Transforms FHIR Patient to DHIS Person",
  "description" : "Transforms FHIR Patient to DHIS Person.",
  "code" : "TRANSFORM_FHIR_PATIENT_DHIS_PERSON",
  "scriptType" : "TRANSFORM_TO_DHIS",
  "returnType" : "BOOLEAN",
  "inputType" : "FHIR_PATIENT",
  "outputType" : "DHIS_TRACKED_ENTITY_INSTANCE",
  "variables" : [ "CONTEXT", "INPUT", "OUTPUT" ],
  "_links" : {
    "self" : {
      "href" : "http://localhost:8081/api/scripts/ea887943-5e94-4e31-9441-c7661fe1063e"
    },
    "script" : {
      "href" : "http://localhost:8081/api/scripts/ea887943-5e94-4e31-9441-c7661fe1063e"
    },
    "arguments" : {
      "href" : "http://localhost:8081/api/scripts/ea887943-5e94-4e31-9441-c7661fe1063e/arguments"
    },
    "sources" : {
      "href" : "http://localhost:8081/api/scripts/ea887943-5e94-4e31-9441-c7661fe1063e/sources"
    }
  }
}

As it can be seen above, the source code of the script is not included. A separate version of the script may exist for each supported FHIR version. Normally most scripts should work for multiple FHIR versions. The following command can be executed to retrieve all arguments of the script:

$ curl -u 'admin:district' http://localhost:8081/api/scripts/ea887943-5e94-4e31-9441-c7661fe1063e/arguments

{
  "_embedded" : {
    "scriptArgs" : [ {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "name" : "lastNameAttribute",
      "dataType" : "TRACKED_ENTITY_ATTRIBUTE_REF",
      "mandatory" : true,
      "array" : false,
      "defaultValue" : "ID:aW66s2QSosT",
      "description" : "The reference of the tracked entity attribute that contains the last name of the Person.",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/scriptArgs/0a7c26cb-7bd3-4394-9d47-a610ac231f8a"
        },
        "scriptArg" : {
          "href" : "http://localhost:8081/api/scriptArgs/0a7c26cb-7bd3-4394-9d47-a610ac231f8a"
        },
        "script" : {
          "href" : "http://localhost:8081/api/scriptArgs/0a7c26cb-7bd3-4394-9d47-a610ac231f8a/script"
        }
      }
    }, {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "name" : "uniqueIdAttribute",
      "dataType" : "TRACKED_ENTITY_ATTRIBUTE_REF",
      "mandatory" : false,
      "array" : false,
      "defaultValue" : "ID:KSr2yTdu1AI",
      "description" : "The reference of the tracked entity attribute that contains a unique ID and should be set to the identifier that is used by FHIR.",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/scriptArgs/276b26f2-ba01-41e6-89c6-b1100580b1f3"
        },
        "scriptArg" : {
          "href" : "http://localhost:8081/api/scriptArgs/276b26f2-ba01-41e6-89c6-b1100580b1f3"
        },
        "script" : {
          "href" : "http://localhost:8081/api/scriptArgs/276b26f2-ba01-41e6-89c6-b1100580b1f3/script"
        }
      }
    }, {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "name" : "genderAttribute",
      "dataType" : "TRACKED_ENTITY_ATTRIBUTE_REF",
      "mandatory" : false,
      "array" : false,
      "defaultValue" : "ID:CklPZdOd6H1",
      "description" : "The reference of the tracked entity attribute that contains the gender of the Person.",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/scriptArgs/8e3efdc7-6ce4-4899-bb20-faed7d5e3279"
        },
        "scriptArg" : {
          "href" : "http://localhost:8081/api/scriptArgs/8e3efdc7-6ce4-4899-bb20-faed7d5e3279"
        },
        "script" : {
          "href" : "http://localhost:8081/api/scriptArgs/8e3efdc7-6ce4-4899-bb20-faed7d5e3279/script"
        }
      }
    }, {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "name" : "birthDateAttribute",
      "dataType" : "TRACKED_ENTITY_ATTRIBUTE_REF",
      "mandatory" : false,
      "array" : false,
      "defaultValue" : "ID:BiTsLcJQ95V",
      "description" : "The reference of the tracked entity attribute that contains the birth date of the Person.",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/scriptArgs/90b3c110-38e4-4291-934c-e2569e8af1ba"
        },
        "scriptArg" : {
          "href" : "http://localhost:8081/api/scriptArgs/90b3c110-38e4-4291-934c-e2569e8af1ba"
        },
        "script" : {
          "href" : "http://localhost:8081/api/scriptArgs/90b3c110-38e4-4291-934c-e2569e8af1ba/script"
        }
      }
    }, {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "name" : "resetDhisValue",
      "dataType" : "BOOLEAN",
      "mandatory" : true,
      "array" : false,
      "defaultValue" : "false",
      "description" : "Specifies if existing values in DHIS can be reset by null values (except first and last name).",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/scriptArgs/9c62145d-55a6-4e3f-bfb8-df81ae43146a"
        },
        "scriptArg" : {
          "href" : "http://localhost:8081/api/scriptArgs/9c62145d-55a6-4e3f-bfb8-df81ae43146a"
        },
        "script" : {
          "href" : "http://localhost:8081/api/scriptArgs/9c62145d-55a6-4e3f-bfb8-df81ae43146a/script"
        }
      }
    }, {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "name" : "addressTextAttribute",
      "dataType" : "TRACKED_ENTITY_ATTRIBUTE_REF",
      "mandatory" : false,
      "array" : false,
      "defaultValue" : "ID:Y0i71Y6CVdy",
      "description" : "The reference of the tracked entity attribute that contains as most as possible from the address of the Person.",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/scriptArgs/ae13ceca-86d7-4f60-8d54-25587d53a5bd"
        },
        "scriptArg" : {
          "href" : "http://localhost:8081/api/scriptArgs/ae13ceca-86d7-4f60-8d54-25587d53a5bd"
        },
        "script" : {
          "href" : "http://localhost:8081/api/scriptArgs/ae13ceca-86d7-4f60-8d54-25587d53a5bd/script"
        }
      }
    }, {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "name" : "firstNameAttribute",
      "dataType" : "TRACKED_ENTITY_ATTRIBUTE_REF",
      "mandatory" : true,
      "array" : false,
      "defaultValue" : "ID:TfdH5KvFmMy",
      "description" : "The reference of the tracked entity attribute that contains the first name of the Person.",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/scriptArgs/b41dd571-a129-4fa6-a807-35ea5663e8e3"
       },
       "scriptArg" : {
         "href" : "http://localhost:8081/api/scriptArgs/b41dd571-a129-4fa6-a807-35ea5663e8e3"
       },
       "script" : {
         "href" : "http://localhost:8081/api/scriptArgs/b41dd571-a129-4fa6-a807-35ea5663e8e3/script"
       }
    }
  } ]
},
"_links" : {
  "self" : {
    "href" : "http://localhost:8081/api/scripts/ea887943-5e94-4e31-9441-c7661fe1063e/arguments"
  }
}

}

As it can be seen above, for the first name of the patient the tracked entity attribute with ID TfdH5KvFmMy. In order to change this to the tracked entity attribute with unique code PERSON_FIRST_NAME the following command can be executed:

$ curl -u 'admin:district' -XPATCH -H 'Content-Type: application/merge-patch+json' -d '{"defaultValue": "CODE:PERSON_FIRST_NAME"}' http://localhost:8081/api/scriptArgs/b41dd571-a129-4fa6-a807-35ea5663e8e3

{
  "createdAt" : "2018-11-19T01:54:36.276Z",
  "lastUpdatedBy" : "M5zQapPyTZI",
  "lastUpdatedAt" : "2018-11-19T19:10:31.690Z",
  "name" : "firstNameAttribute",
  "dataType" : "TRACKED_ENTITY_ATTRIBUTE_REF",
  "mandatory" : true,
  "array" : false,
  "defaultValue" : "CODE:PERSON_FIRST_NAME",
  "description" : "The reference of the tracked entity attribute that contains the first name of the Person.",
  "_links" : {
    "self" : {
      "href" : "http://localhost:8081/api/scriptArgs/b41dd571-a129-4fa6-a807-35ea5663e8e3"
    },
    "scriptArg" : {
      "href" : "http://localhost:8081/api/scriptArgs/b41dd571-a129-4fa6-a807-35ea5663e8e3"
    },
    "script" : {
      "href" : "http://localhost:8081/api/scriptArgs/b41dd571-a129-4fa6-a807-35ea5663e8e3/script"
    }
  }
}

The following command retrieved the source code of the corresponding script:

$ curl -u 'admin:district' http://localhost:8081/api/scripts/ea887943-5e94-4e31-9441-c7661fe1063e/sources

{
  "_embedded" : {
    "scriptSources" : [ {
      "createdAt" : "2018-11-19T01:54:36.276Z",
      "lastUpdatedBy" : null,
      "lastUpdatedAt" : "2018-11-19T01:54:36.276Z",
      "sourceText" : "output.setOptionalValue(args['uniqueIdAttribute'], output.getIdentifier());\noutput.setValue(args['lastNameAttribute'], humanNameUtils.getPrimaryName(input.name).family, context.getFhirRequest().getLastUpdated());\noutput.setValue(args['firstNameAttribute'], humanNameUtils.getSingleGiven(humanNameUtils.getPrimaryName(input.name)), context.getFhirRequest().getLastUpdated());\nvar birthDate = dateTimeUtils.getPreciseDate(input.birthDateElement);\nif ((birthDate != null) || args['resetDhisValue'])\n{\n  output.setOptionalValue(args['birthDateAttribute'], birthDate, context.getFhirRequest().getLastUpdated());\n}\nif ((input.gender != null) || args['resetDhisValue'])\n{\n  output.setOptionalValue(args['genderAttribute'], input.gender, context.getFhirRequest().getLastUpdated());\n}\nvar addressText = addressUtils.getConstructedText(addressUtils.getPrimaryAddress(input.address));\nif ((addressText != null) || args['resetDhisValue'])\n{\n  output.setOptionalValue(args['addressTextAttribute'], addressText, context.getFhirRequest().getLastUpdated());\n}\ntrue",
      "sourceType" : "JAVASCRIPT",
      "fhirVersions" : [ "DSTU3" ],
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/api/scriptSources/b2cfaf30-6ede-41f2-bd6c-448e76c429a1"
        },
        "scriptSource" : {
          "href" : "http://localhost:8081/api/scriptSources/b2cfaf30-6ede-41f2-bd6c-448e76c429a1"
        },
        "script" : {
          "href" : "http://localhost:8081/api/scriptSources/b2cfaf30-6ede-41f2-bd6c-448e76c429a1/script"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8081/api/scripts/ea887943-5e94-4e31-9441-c7661fe1063e/sources"
    }
  }
}

As it can be seen above, the tracked entity attribute with the first name of the patient will be set to the value that is extracted with the script functions humanNameUtils.getSingleGiven(humanNameUtils.getPrimaryName(input.name)) from the name field of the FHIR resource Patient.

All available script functions can be retrieved by executing the following command:

$ http://localhost:8081/scripts/to-dhis2-all-mapping.js
Clone this wiki locally