onaio / fhir-tooling

A command line utility to support FHIR Core content authoring
Other
2 stars 1 forks source link

EUSM - Add support for users and teams #159

Closed Wambere closed 6 months ago

Wambere commented 7 months ago

Current structure from opensrp 1.0

From https://example.smartregister.org/opensrp/rest/practitioner

{
        "identifier": "7449181a-9472-eeaa-9b3c-e76d3de32d24",
        "active": true,
        "name": "John Doe",
        "userId": "2d43b35e-cece-4c81-a5f4-3132a808463d",
        "username": "johnD",
        "dateCreated": "2022-11-17T05:40:10.538Z",
        "dateEdited": "2022-12-08T08:03:43.801Z",
        "serverVersion": 33
}

From https://example.smartregister.org/opensrp/rest/practitionerRole

{
        "identifier": "335e4285-b98c-4506-93b4-4a2f5f0ed147",
        "active": true,
        "organization": "578c4814-ca77-4e1a-b8a1-b734e0b8c3ed",
        "practitioner": "7449181a-9472-eeaa-9b3c-e76d3de32d24",
        "code": {
            "text": "Community Health Worker"
        }
}

I couldn't get any users from https://example.smartregister.org/opensrp/rest/user?page_size=10&source=OpenMRS&start_index=0

{
    "message": "The server encountered an error processing the request.",
    "status": "500 INTERNAL_SERVER_ERROR",
    "data": null,
    "success": false
}
Wambere commented 7 months ago

FHIR version

{
  "resourceType": "Practitioner",
  "id": "7449181a-9472-eeaa-9b3c-e76d3de32d24",
  "identifier": [
    {
      "use": "official",
      "value": "7449181a-9472-eeaa-9b3c-e76d3de32d24"
    },
    {
      "use": "secondary",
      "type": {
        "coding": [
          {
            "system": "http://hl7.org/fhir/identifier-type",
            "code": "KUID",
            "display": "Keycloak user ID"
          }
        ],
        "text": "Keycloak user ID"
      },
      "value": "2d43b35e-cece-4c81-a5f4-3132a808463d"
    }
  ],
  "active": true,
  "name": [
    {
      "use": "official",
      "family": "Doe",
      "given": [
        "John",
        "N"
      ]
    }
  ],
  "telecom": [
    {
      "system": "phone",
      "value": "800-651-2242",
      "use": "home"
    },
    {
      "system": "email",
      "value": "john.doe@example.com"
    }
  ],
  "address": [
    {
      "use": "home",
      "line": [
        "27 South Ave"
      ],
      "city": "Tulsa",
      "state": "OK",
      "postalCode": "74126",
      "country": "USA"
    }
  ],
  "gender": "male"
}
{
  "resource": {
    "resourceType": "PractitionerRole",
    "id": "430",
    "active": true,
    "practitioner": {
      "reference": "Practitioner/7449181a-9472-eeaa-9b3c-e76d3de32d24",
      "display": "John Doe"
    },
    "organization": {
      "reference": "Organization/578c4814-ca77-4e1a-b8a1-b734e0b8c3ed",
      "display": "Team A"
    },
    "code": [
      {
        "coding": [
          {
            "system": "http://terminology.hl7.org/CodeSystem/practitioner-role",
            "display": "Community Health Worker"
          }
        ]
      }
    ]
  }
}

@dubdabasoduba please assist with filling in the above

Wambere commented 7 months ago

After a meeting discussion we realized that we do not need to do this any more, we can just map the opensrp 1.0 data into the already existing user creation csv here

Wambere commented 7 months ago

Re-opening this to track the mapping of values from opensrp 1 to the current existing csv

Wambere commented 7 months ago

Mapping to current location csv json payload this maps to for context

Column Source
FirstName split_part(name,' ',1)
LastName split_part(name,' ',2) + split_part(name,' ',3)
Username username
Email ??
id user_id
UserType ??
EnableUser active
KeycloakGroupID ??
KeycloakGroupName ??
ApplicationID ??
Password ??

Leaving these all empty because I think it makes sense to pull from the users endpoint instead of the practitioners if this information is available there. So pending until we can get data from there

cc @dubdabasoduba @ageryck @AnnieMungai

ageryck commented 7 months ago

current fhir resource generated from web;

{
    "resourceType": "Practitioner",
    "id": "8d9a8364-2dfd-4f30-bdd2-c47e2d821a0a",
    "meta": {
        "versionId": "1",
        "lastUpdated": "2024-03-06T06:57:39.798+00:00",
        "source": "#c67c16120b33e790"
    },
    "identifier": [
        {
            "use": "official",
            "value": "8d9a8364-2dfd-4f30-bdd2-c47e2d821a0a"
        },
        {
            "use": "secondary",
            "value": "e15ee5c5-871a-4043-996a-bc3eeefe019a"
        }
    ],
    "active": true,
    "name": [
        {
            "use": "official",
            "family": "Practitioner",
            "given": [
                "Importer"
            ]
        }
    ],
    "telecom": [
        {
            "system": "email",
            "value": "test@importer.org"
        }
    ]
}

Sample CSV Export Query from team.practitioner

COPY (SELECT split_part(name,' ',1) AS FirstName, split_part(name,' ',2) || ' ' || split_part(name,' ',3) AS LastName, username, 
null as Email, user_id as id, null as UserType, active as EnableUser, null as KeycloakGroupID, null as KeycloakGroupName, 'eusm' as ApplicationID, null as Password  
FROM team.practitioner; ) To 'PATH/test.csv' With CSV DELIMITER ',' HEADER

team.practitioner does not have email

Sample CSV Export Query from team.organization

COPY (SELECT name, active, 'update' as method, identifier as id, identifier, 'Health Org' as alias FROM team.organization) To 'PATH/test.csv' With CSV DELIMITER ',' HEADER

sample CSV Export Query from core.location_metadata

SELECT a.name, a.status, 'udpate' as method, a.geojson_id as id, (select b.name from core.location_metadata b where b.geojson_id=a.parent_id) as parentName, a.parent_id,
null as Type, null as TypeCode, null as physicalType, null as physicalTypeCode from core.location_metadata a

Org to Location Sample Query

SELECT b.name, b.identifier, c.name, c.geojson_id 
FROM team.organization_location a INNER JOIN team.organization b ON a.organization_id=b.id INNER JOIN core.location_metadata c ON a.location_id=c.id
ageryck commented 7 months ago

Mapping to current location csv json payload this maps to for context

Column Source FirstName split_part(name,' ',1) LastName split_part(name,' ',2) + split_part(name,' ',3) Username username Email ?? id user_id UserType ?? EnableUser active KeycloakGroupID ?? KeycloakGroupName ?? ApplicationID ?? Password ?? Leaving these all empty because I think it makes sense to pull from the users endpoint instead of the practitioners if this information is available there. So pending until we can get data from there

cc @dubdabasoduba @ageryck @AnnieMungai

@Wambere we may need to update the payload to read values for "active": true since there could exists some users that are false intentionally

Wambere commented 6 months ago

@ageryck good catch 👍🏾

Where should we apply this change? Practitioner, Practitioner Role, Group, or all three?

ageryck commented 6 months ago

@ageryck good catch 👍🏾

Where should we apply this change? Practitioner, Practitioner Role, Group, or all three?

I want to say all three however I need @peterMuriuki to confirm web client behavior that will be used to manage these after import if re-activating the practitioner re-activates all of the other resources.

peterMuriuki commented 6 months ago

a change in the active status of a keycloak user is synced to the associated fhir resources: Group, practitioner, and practitionerRole.

ageryck commented 6 months ago

tested ok