Views:

Scenario Overview

In this example the business requirement is to regularly update CRM with data from another system to keep the data synchronized. The example we will use here is a hospital system, sending data to CRM that is updated with information on Doctors, their team assignments and patients.

We will use a N52 scheduler to execute 2 workflows that call the REST API of the hospital system and receive a JSON response back which will then be processed by N52 formulas.

We will be primarily concerned with the Staff Position Assignment data for the Doctor, we will create any Team's that don't already exist in CRM, and then add Doctor to that team within CRM. Each Doctor can have multiple Staff Position Overview records returned in the JSON response and the team names are contained within 'teamInfo' section of each 'staffPositionAssignment' hierarchy. 

Sample JSON Response - From External Hospital System

N52 Formula Manager Solution

Two North 52 Formulas are created

N52 Formula 1

  • Formula of type 'Process Genie' is set up on the MedicalTeam entity  
  • The formula will call the Rest webservice of the Hospital System
  • It will create a JSON Entity Collection for each of the active assignments
  • It will then check if each listed team exists, if a team is Not Found then it will create that team

N52 Formula 2    

  • A formula of type 'Process Genie' is created on the  MedicalTeam entity
  • The formula will call the Rest webservice of the Hospital System 
  • It will create a JSON Entity Collection from the response
  • For each record in the Entity Collection the formula will use a FectchXML call to check if there is an existing Team Member on the Team
  • If not it will then create a Team Member and and add them to the team

N52 Formula Manager Steps

The following set of steps outline how to create this Formula:

  • Create the 2 Formulas listed above.
  • Copy in the formula code below
  • Create the Fetch XML query for the 2nd Formula
  • Create the Workflow with both Process Genie Calls
  • Create the N52 Schedule to power both formulas

Workflow

N52 Schedule

Fetch XML




Formula 1 : Check Teams

 
CallRestAPI(
       SetRequestBaseURL('https://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),
       SetRequestResource(),
       SetRequestDetails('GET'),
       SetRequestHeaders(),
       SetRequestParams(),
       SetRequestAuthenticationNone(),
       SetRequestFiles(),
       SetRequestExpected('OK'),
       SetRequestActionPass(
         
                            ForEachRecord(

                               GetVarJsonEC('staff.staffPositionAssignments'),

                               iftrue(FindValue('new_medteam',
                                                'new_name',  GetVarJsonValue('teamInfo.name', '', CurrentRecord('staffPositionOverview')),
                                                'new_name',
                                                'NotFound', True, False) = 'NotFound',
                                    CreateRecord('new_medteam', 
                                  SetAttribute('new_name', GetVarJsonValue('teamInfo.name', '', CurrentRecord('StaffPositionOverview')))))           
                                )
      ),
         SetRequestActionFail(Alert('No Data'))
)


Formula 2 : Add Team Members

CallRestAPI(
         SetRequestBaseURL('https://XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'),
        SetRequestResource(),
         SetRequestDetails('GET'),
         SetRequestHeaders(),
         SetRequestParams(),
         SetRequestAuthenticationNone(),
         SetRequestFiles(),
         SetRequestExpected('OK'),
         SetRequestActionPass(  
          
               ForEachRecord(                   
                                  
                    GetVarJsonEC('staff.staffPositionAssignments'),          
                            
                    iftrue(FindCountFD('DoesTeamMemberExist', 
                                        'new_medteammemberid', 
                                         0, 
                                         true, 
                                         SetParams(  FindValue('new_medteam', 'new_name',
                                                            GetVarJsonValue('teamInfo.name', '',
                                                            CurrentRecord('staffPositionOverview')), 
                                                            'new_medteamid', '?', true, false),
                                                   GetVarJsonValue('teamRoleCode', '',
                                                        CurrentRecord('staffPositionOverview')),
                                                   GetVarJsonValue('staff.staffInfo.firstName') 
                                                        + ' ' + GetVarJsonValue('staff.staffInfo.lastName'))
                            ) = 0,              
                                                   
                       CreateRecord('new_medteammember', 
                            SetAttribute('new_name', 
                                 GetVarJsonValue('staff.staffInfo.firstName') + ' ' 
                                 + GetVarJsonValue('staff.staffInfo.lastName')),
                            SetAttribute('new_teamrole', 
                                 GetVarJsonValue('teamRoleCode', '', 
                                   CurrentRecord('staffPositionOverview'))),
                            SetAttributeLookup('new_medteamid', 'new_medteam',
                                              FindValue('new_medteam', 'new_name', 
                                                  GetVarJsonValue('teamInfo.name', '',                                 
                                                  CurrentRecord('staffPositionOverview')) , 
                                                  'new_medteamid', '?', true, false)))

                                                    
                                   )      
                         )   
      ),
      SetRequestActionFail(Alert('No Data'))
)

Full JSON Response

{
  "staff": {
    "staffInfo": {
      "firstName": "JOHN",
      "middleName": null,
      "lastName": "GRACE",
      "prefix": null,
      "suffix": null,
      "fullDisplayName": "GRACE, JOHN",
      "ssn": "123455678",
      "birthDate": null,
      "title": "CORK CITY MEDICAL CENTER",
      "phoneNumber": null,
      "emailAddress": null,
      "city": null,
      "state": null,
      "zip": null,
      "terminationDate": null,
    },
    "staffPositionAssignments": [
      {
        "staffPositionOverview": {
          "teamInfo": {
            "name": "GRA_SAR4",
            "description": "",
            "careType": "PRIMARY CARE",
            "primaryFocus": "Primary Care Only",
            "secondaryFocus": null,
          },
          "teamLead": false,
          "primaryTeamContact": false,
          "secondaryTeamContact": false,
          "teamRoleCode": "ABV",
          "teamRoleName": "PRIMARY CARE PROVIDER",
          "teamRoleIsPrimaryCare": true,
          "description": "",
          "capacity": "10"
        },
        "staffRoleCode": "32",
        "staffRoleName": "PHYSICIAN",
        "startDate": "2011-08-28T20:20:00.000Z"
      },
      {
        "staffPositionOverview": {
          "teamInfo": {
            "name": "COR_SPL4",
            "description": "",
            "careType": "PRIMARY CARE",
            "primaryFocus": "Emergency",
            "secondaryFocus": "Children",
          },
          "teamLead": false,
          "primaryTeamContact": false,
          "secondaryTeamContact": false,
          "teamRoleCode": "ABC",
          "teamRoleName": "CLINICAL ASSOCIATE",
          "teamRoleIsPrimaryCare": false,
          "description": null,
          "capacity": "20"
        },
        "staffRoleCode": "12",
        "staffRoleName": "MEDICAL TECHNICIAN",
        "startDate": "2011-12-02T21:17:00.000Z",
      }
    ],
    "patients": [
      {
        "status": "Pending",
        "patientInfo": {
          "icn": "123456789",
          "fullDisplayName": "MCINERNEY, PATRICK",
          "firstName": "PATRICK",
          "middleName": null,
          "lastName": "MCINERNEY",
          "prefix": null,
          "suffix": null,
          "ssn": "12345677",
          "birthDate": "01011980"
          ]
        }
      }
    ]
  }
}