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

Search dsf with birthdate #97

Merged
merged 4 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,22 @@ No input or output. Changes will be fetched from IDM

Fetches person info from [Det sentrale folkeregister](/~https://github.com/vtfk/azf-dsf)

#### `With ssn as parameter`
```json
{
"ssn": "01010101010"
}
```

#### `With birthdate and name as parameter (only works with one match)`
```json
{
"birthdate": "010101",
"firstName": "Per",
"lastName": "Son"
}
```

## Templates

Currently available archive templates
Expand Down
12 changes: 7 additions & 5 deletions SyncElevmappe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ module.exports = async function (context, req) {
}

const { ssn } = req.body
if (!ssn) {
logger('error', ['Missing required parameter "ssn"'])
return new HTTPError(400, 'Missing required parameter "ssn"').toJSON()
const { birthdate, firstName, lastName } = req.body
if (!ssn && !(birthdate && firstName && lastName)) {
logger('error', ['Missing required parameter "ssn" or "birthdate, firstname, lastname"'])
return new HTTPError(400, 'Missing required parameter "ssn" or "birthdate, firstname, lastname"').toJSON()
}

const dsfSearchParameter = ssn ? { ssn } : { birthdate, firstName, lastName }
try {
const dsfData = await getDsfData(ssn)
const dsfData = await getDsfData(dsfSearchParameter)
const dsfPerson = repackDsfObject(dsfData.RESULT.HOV)
const privatePerson = await syncPrivatePerson(dsfPerson)
const elevmappe = await syncElevmappe(privatePerson)

return getResponseObject({
msg: 'Succesfully synced elevmappe',
dsfPerson,
Expand Down
33 changes: 25 additions & 8 deletions lib/dsf/get-dsf-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,38 @@ const generateSystemJwt = require('../generate-system-jwt')
const HTTPError = require('../http-error')
const { DSF: { saksref, url, jwtSecret } } = require('../../config')

module.exports = async ssn => {
const payload = {
method: 'hentDetaljer',
massLookup: true,
query: {
saksref,
foedselsnr: ssn
module.exports = async dsfSearchParameter => {
let payload
if (dsfSearchParameter.ssn) {
payload = {
method: 'hentDetaljer',
massLookup: true,
query: {
saksref,
foedselsnr: dsfSearchParameter.ssn
}
}
} else {
payload = {
method: 'hentDetaljer',
massLookup: true,
query: {
saksref,
foedselsdato: dsfSearchParameter.birthdate,
etternavn: dsfSearchParameter.lastName,
fornavn: dsfSearchParameter.firstName
}
}
}

try {
const { data } = await axios.post(url, payload, { headers: { Authorization: generateSystemJwt(jwtSecret) } })
if (data.RESULT.ANTA === '0000') throw new HTTPError(404, 'Could not find any persons with given identification')
if (data.RESULT.ANTA) throw new HTTPError(404, 'Found several persons with given identification, cannot automate')
return data
} catch (error) {
const { status, data } = error.response
const status = error.response ? error.response.status : error.statusCode
const data = error.response ? error.response.data : error.message
logger('error', ['get-dsf-data', status, data])
throw new HTTPError(status, data)
}
Expand Down
14 changes: 14 additions & 0 deletions templates/vigo-SIGNOFF.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"archive": {
"service": "DocumentService",
"method": "SignOffDocument",
"parameter": {
"Document": "<<<documentNumber>>>",
"ResponseCode": "TO",
"Note": "Dokumentet er avskrevet med koden TO – Tatt til orientering"
}
},
"data": {
"documentNumber": "30/00000-1"
}
}