Skip to main content

Data mapping for Swedish population register

This mapping is used when fetching contact information from the Swedish population register via the Population Register API.

Mapping

The mapping name is update.roaring.SwedishPopulationRegister. 

Updated fields

  • Name

  • Address

  • Tags

    • Deregistration

  • Key figures

    • Death date

    • Guardian

Mapping table

Row

Source field

FA field

Script

1

JSONPath:$.records[0].personId

c.contactId

2

JSONPath:$.records[0].populationRegistrationAddress[0].swedishAddress.deliveryAddress2

c.address1

3

JSONPath:$.records[0].populationRegistrationAddress[0].swedishAddress.zipCode

c.zipCode

4

JSONPath:$.records[0].populationRegistrationAddress[0].swedishAddress.city

c.city

5

FIRSTNAME

output = ""

6

JSONPath:$.records[0].name[0].firstName

FIRSTNAME

7

SURNAME

output = ""

8

JSONPath:$.records[0].name[0].surName

SURNAME

9

c.name

if("[FIRSTNAME]" != "" && "[SURNAME]" != "") {

   output = "[FIRSTNAME]" + " " + "[SURNAME]"

}

else {

   output = "***"

}

10

DEREGREASON

output = ""

11

JSONPath:$.records[0].details[0].deRegistrationReasonCode

DEREGREASON

12

DEATHDATE

output = ""

13

JSONPath:$.records[0].details[0].death.deathDate

DEATHDATE

14

GUARDIAN

output = ""

15

JSONPath:$.records[0].relation[?(@.relationType == "GUARDIAN")].personId

GUARDIAN

16

GUARDIANDATE

output = ""

17

JSONPath:$.records[0].relation[?(@.relationType == "GUARDIAN")].dateFrom

GUARDIANDATE

18

c.tags

output = ""

if("[DEREGREASON]" != "") {

   output = "Deregistration-[DEREGREASON],"

}

if('[GUARDIAN]' != "") {

   output += "Guardian"

}

19

c.keyFigures

output = "***:"

if("[DEATHDATE]" != "") {

   output += "DEATHDATE=[DEATHDATE]=[DEATHDATE]:"

}

if('[GUARDIAN]' != "") {

   // When JSONPath filters are used, it returns array of string whose elements cannot be accessed...

   // Hence we remove the extra characters.

   List<String> guardianParsed = '[GUARDIAN]'.substring(2, '[GUARDIAN]'.length() - 2).replace('"','').split(',')

   List<String> guardianDateParsed = '[GUARDIANDATE]'.substring(2, '[GUARDIANDATE]'.length() - 2).replace('"','').replace('"','').split(',')

   Map<String, List<String>> guardianMap = [:]

   int index = 0;

   for(String guardian: guardianParsed) {

       List<String> thisDate = guardianMap.getOrDefault(guardianDateParsed.get(index), [])

       thisDate.add(guardian)

       guardianMap.put(guardianDateParsed.get(index), thisDate)

       index++;

   }

   output += "GUARDIAN=" + guardianMap.collect {it.getKey() + "=" + it.getValue().join(';')}.join(',')

}