Skip to main content

Migration and Seeding Tool

The migration and seeding tool can be used to migrate the EWA database, seed locations and configure the EWA system.

Before use​

The tool needs a connection string to the MSSQL database it should migrate/insert data to.

Configuration by version​

VersionConfiguration File
Below 21.10Bliksund.EWA.MigrationTool.exe.config
21.10 and laterappsettings.json

Command Timeout Configuration (v40.2.7+)​

Starting from version 40.2.7, you can configure the command timeout for database migration operations in appsettings.json:

{
"ConnectionStrings": {
"PEPJDatabaseConnection": "your-connection-string"
},
"CommandTimeoutSeconds": 600
}
PropertyTypeDefaultDescription
CommandTimeoutSecondsint600The maximum time (in seconds) to wait for a migration command to execute before timing out.

Important notes:

  • The default value is 600 seconds (10 minutes), which is suitable for most migrations.
  • If a value lower than the default is configured, the tool will automatically use the default value (600 seconds) and log a warning.
  • Increase this value if you have large database or complex migrations that may take longer to complete.

Usage​

The tool can be invoked via the command line with command line options or it can be run interactively by double-clicking the Bliksund.EWA.MigrationTool.exe file in file explorer.

Command line options​

OptionDescription
--helpDisplay help text for the tool.
-m, --migrateMigrates the database to the newest version
-s, --seedSeeds all JSON files from the Data folder into the database
--seed-files <file> [<file>...]Seeds the specified files. Bare filenames are resolved from the Data/ folder; full paths are used as-is. Example: --seed-files Location.json /data/Checklists.json
--seed-folder <path>Seeds all JSON files found in the specified folder. Example: --seed-folder /data/seed
-v, --validateValidates that the Data folder contains the required JSON files for seeding
--openidUse OpenID Connect for authentication and authorization in the system. Configuration should be set in file "OpenIdConnectConfiguration.json"
--role-access-mappingUpdate the role to access right mapping that the system should use for authorization. Configuration should be set in file "RoleToAccessMapping.json"
--pdf-configurationUpdate or inserts the pdf configuration settings. Configuration should be set in file "PdfConfiguration.json"
--department-id-mappingInserts or updates the Department ID mapping configuration which is used for OpenIdConnect with departments as single claim and rolepicker display values. Configuration should be set in file "DepartmentIdMapping.json"
--named-location-seedInserts the named location categories that are not in the database yet, and makes the ID types match the file. It never changes or deletes a category, because categories are edited in Insight. Configuration should be set in file "NamedLocationSeed.json"; the image holds an empty placeholder and each deployment supplies its own file. Runs before --run-converter. See the NamedLocationSeed.json section below.
--run-converterRuns a specific converter. The converter name should be provided after this argument.
--address-lookup [path]Loads the address lookup data (AddressLookup.dacpac, or its folder; default: the Data/ folder) when its data version changed. Skipped with a warning when the file is missing or SQL Server has no Full-Text Search. Takes several minutes; only address search is unavailable meanwhile.

Seeding files from custom paths​

--seed-files accepts both bare filenames (resolved from the Data/ folder) and full file paths. This is useful for files that are not bundled in the tool's Data/ folder, such as the checklist-related files (Checklists.json, ChecklistPhases.json, ChecklistInstances.json, FormConfigurations.json, FormConfigurationSections.json, FormBranchingConditions.json, DboChecklists.json, DboChecklistResources.json).

Running --seed does not attempt to seed any of these files since they are not present in the Data/ folder.

Examples​

To re-run data conversions, or resume a conversion that was interrupted, the --run-converter option can be used. The name of the converter to run should be provided after the option.

.\Bliksund.EWA.MigrationTool.exe --run-converter CreateRecordConfMissionTypeTable

To seed checklist files from a custom location (e.g. files produced by an automated test setup), pass the full paths to --seed-files:

.\Bliksund.EWA.MigrationTool.exe --seed-files C:\data\Checklists.json C:\data\FormConfigurations.json

Bare filenames and full paths can be mixed freely:

.\Bliksund.EWA.MigrationTool.exe --seed-files Location.json C:\data\DboChecklists.json C:\data\DboChecklistResources.json

Interactive use​

When using the tool interactively, the following menu will be displayed in a console window after startup:

Menu ItemDescription
ListEnter menu to list pending, deployed and all migrations for the current version
MigrateMigrate the database up to the current version. With no migration pending it still runs the data conversions that run on every migration run, as -m does, and does not ask to seed
SeedSeed data from the JSON files in Data folder to the database
Validate DataValidates that the Data folder contains the required JSON files for seeding
System ConfigurationOpens the system configuration menu
HelpDisplay help text
ExitExits the program

List menu​

Menu ItemDescription
PendingList pending migrations
DeployedList deployed migrations
AllList all migrations

System Configuration menu​

Menu ItemDescription
Authentication and AuthorizationConfigure which authentication and authorization method the system should use
Role to Access Rights MappingInsert or update the role to access rights mapping configuration that the system should use for authorization
Seed PDF configurationInsert or update the PDF configuration object that the system should use when generating PDFs
Department ID MappingInserts or updates the Department ID mapping configuration which is used for OpenIdConnect with departments as single claim and rolepicker display values

Configuration files​

OpenIdConnectConfiguration.json​

The OpenIdConnectConfiguration file consists of two objects with the same internal structure; InsightConfiguration and ClientConfiguration.

The InsightConfiguration object is used by the Insight component, while the ClientConfiguration object is used by the ClientAPI component.

PropertyTypeIsRequiredDefault valueDescription
ClientIdstringYesThe "client_id" part of the authentication flow
ClientSecretstringYesThe "client_secret" part of the authentication flow
AuthoritystringYesUrl to the Authority that should be used when making OpenIdConnect calls
SSNClaimTypestringYesClaim type of the claim that should be used for getting the "social security number" for the user. Can be any claim that will uniquely identify a user
NameClaimTypestringYesClaim type of the claim that should be used for getting the user's full name
UserIdClaimTypestringYesClaim type of the claim that should be used for getting the user's "UserId"
WorkplacesClaimTypestringYesClaim type of the claim(s) that should be used for getting the user's list of department level workplaces
OrganizationClaimTypestringYesClaim type of the claim(s) that should be used for getting the user's list of organizations. Ignored if "DepartmentsAsSingleClaim" = true
ValidAudienceslist<string>YesList of valid audiences
AdditionalScopeslist<string>No[]List of additional scopes to use
AppRoleClaimTypestringNo"roles"Claim type of the claim(s) that should be used for getting the user's list of roles
ValidIssuerslist<string>NoList of valid issuers. Uses authority as valid issuer if property is missing or value is null
DepartmentsAsSingleClaimboolNofalseTells the system to treat the value in the WorkplacesClaimType claim as a semi-colon separated list, and to use configured DepartmentIdMapping to build the user's organization hierarchy tree
RolePickerEnabledboolNofalseIs only used in InsightConfiguration. Enables a role picker in Insight which requires the user's to pick Department and Role before being able to use the rest of Insight
DepartmentsClaimSeparatorstringNo";"The separator used to separate department id values from the WorkplacesClaimType claim when DepartmentsAsSingleClaim is true
AllowedRedirectUrislist<string>No[]Is only used in ClientConfiguration. The approve list (whitelist) of redirect URIs that ClientHub accepts as an authentication callback target. Supports * as a wildcard. If the property is missing or the list is empty, ClientHub falls back to the built-in default URI only. See Seeding the redirect URI approve list

OpenIdConnectConfiguration.json - Example​

{
"InsightConfiguration": {
"ClientId": "4a821d50-11a1-483f-8782-e865ab3033a1",
"ClientSecret": "[REDACTED]",
"Authority": "https://login.microsoftonline.com/73935988-7e75-46c2-8cc6-d2d91985f67b/v2.0",
"SSNClaimType": "extn.ssn",
"NameClaimType": "name",
"UserIdClaimType": "preferred_username",
"WorkplacesClaimType": "groups",
"OrganizationClaimType": "extn.OrganizationIdentification",
"ValidAudiences": [
"4a821d50-11a1-483f-8782-e865ab3033a1"
],
"RolePickerEnabled": true,
"DepartmentsAsSingleClaim": false
},
"ClientConfiguration": {
"ClientId": "4a821d50-11a1-483f-8782-e865ab3033a1",
"ClientSecret": "[REDACTED]",
"Authority": "https://login.microsoftonline.com/73935988-7e75-46c2-8cc6-d2d91985f67b/v2.0",
"SSNClaimType": "extn.ssn",
"NameClaimType": "name",
"UserIdClaimType": "preferred_username",
"WorkplacesClaimType": "groups",
"OrganizationClaimType": "extn.OrganizationIdentification",
"ValidAudiences": [
"4a821d50-11a1-483f-8782-e865ab3033a1"
],
"RolePickerEnabled": true,
"DepartmentsAsSingleClaim": false,
"AllowedRedirectUris": [
"ewa://login-user*",
"https://myclient.example.com/callback",
"https://anotherclient.example.com/*"
]
}
}

Seeding the redirect URI approve list​

The approve list (whitelist) of redirect URIs that ClientHub accepts as an authentication callback target is seeded into the database as part of the OpenID Connect configuration, using this tool.

How it works​
  • The approve list is the AllowedRedirectUris property of the ClientConfiguration object. ClientHub only reads it from ClientConfiguration; setting it on InsightConfiguration has no effect.
  • Running the tool with --openid reads Configuration/OpenIdConnectConfiguration.json and writes the whole configuration, approve list included, to the database. There is no separate argument for the approve list.
  • In the container image, the file can be replaced at runtime through the OpenIdConnectConfiguration environment variable, which takes either raw JSON or base64-encoded JSON (prefixed base64: or b64_). See Container.
  • ClientHub reads the configuration at startup, so it must be restarted before a reseeded approve list takes effect.
Matching rules​
PatternMatches
https://myclient.example.com/callbackThat exact URI, compared case-insensitively
ewa://login-user*Any URI starting with ewa://login-user, for example ewa://login-user?id=42&name=ada
https://anotherclient.example.com/*Any URI under that host
*Every redirect URI. Do not use outside local development

* may appear anywhere in a pattern and matches any sequence of characters, including /, ? and &. All other characters are matched literally.

If AllowedRedirectUris is missing or empty, ClientHub allows one URI only:

ewa://login-user?id={__userId__}&name={__userName__}&cookie={__cookieValue__}&timeout={__timeout__}
Example - adding allowed redirect URIs​

To allow ewa://login-user*, https://myclient.example.com/callback and https://anotherclient.example.com/*, add the property to ClientConfiguration:

{
"ClientConfiguration": {
"ClientId": "4a821d50-11a1-483f-8782-e865ab3033a1",
"ClientSecret": "[REDACTED]",
"Authority": "https://login.microsoftonline.com/73935988-7e75-46c2-8cc6-d2d91985f67b/v2.0",
"SSNClaimType": "extn.ssn",
"NameClaimType": "name",
"UserIdClaimType": "preferred_username",
"WorkplacesClaimType": "groups",
"OrganizationClaimType": "extn.OrganizationIdentification",
"ValidAudiences": [
"4a821d50-11a1-483f-8782-e865ab3033a1"
],
"AllowedRedirectUris": [
"ewa://login-user*",
"https://myclient.example.com/callback",
"https://anotherclient.example.com/*"
]
}
}

Then seed it. From the command line:

.\Bliksund.EWA.MigrationTool.exe --openid

Or, in the container, supply the file through the environment variable and pass --openid in ARGUMENTS:

env:
- name: OpenIdConnectConfiguration
value: "base64:<base64-encoded-json>"
- name: ARGUMENTS
value: "--openid"

The graphical route is described in Configuration of Authentication and Authorization.

RoleToAccessMapping.json​

List of objects which tells the system which access rights are given by which roles.

Definition of available access rights can be found in Access Rights document.

PropertyTypeIsRequiredDefault valueDescription
RolestringYesId/value of a role that the user's can have in their token after login
AccessRightslist<string>YesList of access rights that should be given by the Role
DisplayNamestringNoThe display name to use for the role in the role picker in Insight if it's enabled

RoleToAccessMapping - Example​

[
{
"Role": "sys_role_journalregistration",
"DisplayName": "Journalregistrering",
"AccessRights": [
"OrganizationClient",
"UserJournalView",
"UserJournalEdit",
"UserJournalPrint",
"UserJournalComplete"
]
},
{
"Role": "sys_role_patient_complaint_handler",
"DisplayName": "Klagesakshåndtering",
"AccessRights": [
"OrganizationJournalView",
"OrganizationJournalPrint",
"OrganizationJournalDelete",
"BlacklistWhitelist",
"OrganizationAuditLog",
"OrganizationMainWithMedicalData"
]
},
]

DepartmentIdMapping.json​

List of objects which tells the system which organization id a department belongs to, and what the name of the department is.

This list is used by the access control middleware to construct the user's organization hierarchy when DepartmentsAsSingleClaim is enabled, and to display more user-friendly names for departments in the role picker.

PropertyTypeIsRequiredDefault valueDescription
DepartmentIdstringYesId of the department. Usually a RESH-ID in Norway
DepartmentNamestringYesName of the department
OrganizationIdstringYesId of the organization that the department belongs to

DepartmentIdMapping - Example​

[
{
"DepartmentId": "9ccda3e6-320a-4504-9386-97b2117ec744",
"DepartmentName": "Cardiology outpatient clinic",
"OrganizationId": "100000001",
},
{
"DepartmentId": "f45eaef5-1e97-4a15-95c3-6d77a689b9ac",
"DepartmentName": "Grimstad emergency room",
"OrganizationId": "100000001",
}
]

NamedLocationSeed.json​

One file per installation, read by two steps: --named-location-seed reads categories and idTypes, and the NamedLocationsCopy converter reads the other three properties. The image holds an empty placeholder, and each deployment supplies its own file.

PropertyTypeIsRequiredDefault valueDescription
defaultCountrystringFor the copyISO 3166-1 alpha-2 country every copied location gets, for example NO
categoriesarrayFor the seed[]The categories the installation starts with, see below
idTypesarrayNo[]The ID types the installation uses, see below
legacyTypeMapobjectNo{}Old place tag value to category keyName, for example "Somatisk sykehus": "SomaticHospital". When it is empty, the copy makes each place tag a category of its own, see below. null is refused
genericNamesarrayFor the copy[]Names that make an old row under a mapped tag generic, with or without an address, for example Sykehus
tagCategoriesobjectNononeOnly with an empty legacyTypeMap. codeSystem names the code system the place tags are codes of (Ambustat, Hl7, ElsObjectType or OsmTag), sameCategory puts a tag in the category of another tag, for example "KHS": "KH", and names gives a tag's category its names by culture, for example "KH": { "en-GB": "Hospital", "de-DE": "Krankenhaus" }

Each category:

PropertyTypeIsRequiredDefault valueDescription
keyNamestringYesThe English name in PascalCase, for example SomaticHospital: ASCII letters and digits, starting with a letter, at most 64 characters. Unique and never changed; the database gives the category its number
namesobjectYesThe name in each language, keyed by culture name. An English name is required. The seed writes each name to the translation service under the language alone (en-GB is stored as en), in module Location.Category with the keyName as its key
codesarrayNo[]Codes in other systems, each { "system": "Hl7", "code": "HOSP" }. The systems are Ambustat, Hl7, ElsObjectType and OsmTag
isDefaultboolNofalseThe installation's Default category. At most one

The seed is insert-only for categories: a category whose keyName is already in the register, deleted or not, is never changed, and a name the translation service already has in that language is never overwritten, because categories and their names are edited in Insight after the first run.

Each ID type:

PropertyTypeIsRequiredDefault valueDescription
idTypestringYesExactly one of Resh, Her, OrganisationNumber, ElsFKey and Osm, at most once in the file
namesobjectYesThe name in each language, as for a category. An English name is required. Written in module Location.IdType with the idType as its key
systemstringYesThe system URI (FHIR Identifier.system), for example urn:oid:2.16.578.1.12.4.1.4.102. ASCII, at most 256 characters. Insight never shows it
patternstringNonullA .NET regular expression the whole value must match, run with ECMAScript and IgnoreCase: \d matches only 0 to 9, and F-\d{6} also accepts f-900001, as the duplicate check compares values without case. Empty or null allows any value
uniqueboolYesWhen true, two active named locations may not share a value of this type
usedByarrayNo[]Where an ID of this type is used, each one of LiveView, DIPS, ELS and billing

ID types are not insert-only, because Bliksund sets them and Insight only shows them: every run inserts the types the register does not have, updates the fields and names that differ from the file, and logs what it changed. A type the register has and the file does not is left as it is, with a warning, because official IDs of that type may exist. There is no audit entry; the seed file's history is the record.

Copying dbo.Locations​

--run-converter NamedLocationsCopy copies every row of dbo.Locations into the named location register. Run it together with --named-location-seed, which always runs first: the copy stops if a category it maps to is missing.

Neither flag is in the default migration arguments. Every installation, on-prem included, adds both to its own arguments and supplies its own seed file before it gets the app version that uses the register for every resource (Task 46572). Without them the register is empty, so the crew has no location to pick and a mandatory location tile never completes. Leave both flags in after the first run: the copy then picks up what the old Insight page saves until that page is gone.

  • Every LocationGuid becomes one named location, with a revision for each old row. The register gives each revision a new Id: records link a location by GUID and revision, not by the old row id. Generic entries such as "Sykehjem", generic names such as "Sykehus" (with an address or not), district names and consultation boards are copied too, but deactivated, so they stay out of the Insight list, the search and the device sync. The kind of the newest row of a GUID decides. A row with a blank name is sorted as if it were named after its place tag.
  • Every copied location gets the copy time from the database clock as its last change, so a device that synced before the copy still gets it. Its creation time and the revision dates stay the old ones.
  • The place tag picks the category through legacyTypeMap. A district name gets OtherPlace, and the copy stops if a district name needs it and the register has none. A consultation board, and a place under a tag that is not in the map, get no category.
  • When legacyTypeMap is empty, as in Luxembourg, whose ELS object type codes are not confirmed yet, the map is the only thing that changes: each place tag that holds a real place (a row whose name differs from the tag) becomes a category of its own, and the usual rules then run on that map. The keyName is the tag in ASCII letters and digits: BUSHAL stays BUSHAL, umlauts become two letters (MILITÄR is MILITAER), other accents are dropped, any other character is removed, and a tag that starts with a digit gets Tag in front. The category's English name is the tag as written, such as MILITÄR. A tag whose rows are all named after it, such as a village name or "Anderer Ort", stays a district name in OtherPlace. The copy adds a category only if its keyName is not in the register, and a name only if the category has no English name, so a category or name changed in Insight stays as it is. It stops before it writes anything if two tags give one keyName or a tag has no letter or digit; map those tags in legacyTypeMap, which then decides every tag. On a re-run, a tag whose category is in the register and not deleted keeps it, also when the only new row under it is named after the tag. The log lists the categories it added by name, so a village that became a category by mistake shows there.
  • tagCategories adjusts those tag categories. With codeSystem, each new category keeps its tags as codes in that system, written as the tag is, so Luxembourg's categories carry their ELS object type codes (MILITÄR, not MILITAER) and a location from the dispatch centre can get its category from the object type. sameCategory puts a tag in the category of another tag: ELS has a second code for a part of a site, such as KHS for a ward of a hospital (KH), and both then give the category KH with the two codes. The tag it points to names the category, also when no row uses that tag, and must not be listed in sameCategory itself. A new category gets the codes of all its tags from the seed at once, whether a row uses them yet or not. names gives the category of a tag its name in each language; without an English name there, the tag as written is the English name. A tag listed in sameCategory cannot be named, since the tag it points to names the category. Luxembourg's German names are from CGDIS's list of ELS object types of 2024-02-29, and the English and French ones are Bliksund's translations of them. A category that is in the register already keeps the codes it has. A name is written only in a language the category has no name in yet.
  • Old revision numbers are kept. Only when two rows of one GUID share a number is that GUID numbered again by creation time.
  • Re-runs add only what is missing and never overwrite an edit made in Insight. A GUID not in the register yet is copied whole. A GUID the old Insight page saved again after the copy gets the new old rows as its next revisions, with their old dates, and the newest old row decides again whether it is active. The copy tells its own revisions apart by their creation time, which is an old row's.
  • A GUID that was saved on the old page and also on the new Locations page since the copy is left as it is, because both saves cannot be the current one. The log warns about it with its GUID on every run, and the Job does not fail on it. An admin compares the location in Insight and redoes on the Locations page what the old page changed.
  • A GUID that fails is rolled back and logged, and the others go on. After the first run, with nothing saved on the old page, a deployment only runs the checks.
  • Text is trimmed, as Insight trims it on save. A blank old name takes the place tag as its name, or Location <old row id> if the tag is blank too, and goes on the review list.
  • Every revision gets the seed's defaultCountry, except a row under a county tag for a country abroad: Sverige, Danmark, Deutschland, Belgien or Frankreich, which gets SE, DK, DE, BE or FR.
  • The log shows a report for the rows it copies (counts, tag values and old row ids, never names or addresses) and ends with two after-checks: every old GUID has at least as many revisions as old rows, apart from the GUIDs saved on both pages, and every named location has a current revision. A failed GUID or a failed check fails the migration Job.

Linking migrated locations to OSM places​

When the copy and its checks pass, the same run links migrated named locations to their OSM place, so the search shows such a place once, as the named location, and not a second time as an OSM hit. --run-converter NamedLocationsOsmMatch runs only this step.

  • It looks only at active migrated locations that no one has changed since the copy: those with exactly as many revisions as old rows, a position and no OSM ID yet. A location made or edited in Insight is never touched.
  • A location links to an OSM place only when exactly one place fits: the same name (case, accents and punctuation do not count), within 500 metres, among the places the search shows, and in the location's category if that category has OSM tag rules. If that one place is linked to another location already, or two locations both fit it, the location is left.
  • A link is a new revision with the OSM ID added, with the database clock as the location's last change, as an edit in Insight is. So the change history shows it, the device sync sends it, and a location is linked once at most. Removing the link in Insight is an edit, so a later run does not add it back.
  • The link is an official ID of type Osm, so the seed file must declare that type in idTypes, as the defaults and Luxembourg seeds do. Its unique flag keeps an OSM place to one location when an admin edits a link in Insight. On an installation whose seed has no Osm entry, the step only logs that and links nothing, because an installation takes no official IDs of a type it does not declare.
  • A location with no fitting place stays a candidate, so a run after a new address data import may link it. Without OSM places (a country marked none in countries.tsv, or a server without Full-Text Search) the step only logs that and does nothing.
  • The log shows counts only. A location the database refuses, or cannot lock while it is edited in Insight, is rolled back and logged, and the others go on. Any other error stops the step with a warning. It never fails the migration Job, because a location it could not link only shows twice in the search, as before.

NamedLocationSeed - Example​

{
"defaultCountry": "NO",
"idTypes": [
{
"idType": "Resh",
"names": { "en-GB": "RESH ID", "nb-NO": "RESH-ID" },
"system": "urn:oid:2.16.578.1.12.4.1.4.102",
"pattern": null,
"unique": true,
"usedBy": [ "DIPS" ]
}
],
"categories": [
{
"keyName": "SomaticHospital",
"names": { "en-GB": "Somatic hospital", "nb-NO": "Somatisk sykehus" },
"codes": [ { "system": "Hl7", "code": "HOSP" }, { "system": "OsmTag", "code": "amenity=hospital" } ]
}
],
"legacyTypeMap": { "Somatisk sykehus": "SomaticHospital" },
"genericNames": [ "Sykehus" ]
}