Skip to content

Commit

Permalink
🚧 progress: Lint sources.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Jan 6, 2025
1 parent 5dadbf1 commit fa981ea
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 174 deletions.
3 changes: 2 additions & 1 deletion imports/api/_dev/populate/eids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const AGE_MAX = 130;

export const newEidData = makeTemplate({
xml: {
// eslint-disable-next-line unicorn/text-encoding-identifier-case
encoding: () => 'UTF-8',
version: () => '1.0',
},
Expand All @@ -20,7 +21,7 @@ export const newEidData = makeTemplate({
carddata_appl_version: () => faker.string.numeric(2),
cardnumber: () => faker.string.numeric(12),
chipnumber: () => faker.string.alphanumeric(32),
documenttype: () => "belgian_citizen",
documenttype: () => 'belgian_citizen',
validitydatebegin: () => format(faker.date.past({years: 30}), DATE_FORMAT),
validitydateend: () => format(faker.date.past({years: 30}), DATE_FORMAT),
deliverymunicipality: () => faker.location.county(),
Expand Down
97 changes: 54 additions & 43 deletions imports/api/collection/eids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,59 @@ import schema from '../../lib/schema';
import define from './define';

export const eidFields = schema.object({
xml: schema.object({
encoding: schema.string(),
version: schema.string(),
}).partial(),
eid: schema.object({
graphpersoversion: schema.string(),
version: schema.string(),
}).partial(),
card: schema.object({
carddata_appl_version: schema.string(),
cardnumber: schema.string(),
chipnumber: schema.string(),
documenttype: schema.string(),
validitydatebegin: schema.string(),
validitydateend: schema.string(),
deliverymunicipality: schema.string(),
}).partial(),
certificates: schema.object({
authentication: schema.string(),
citizenca: schema.string(),
root: schema.string(),
rrn: schema.string(),
signing: schema.string(),
}).partial(),
identity: schema.object({
nationality: schema.string(),
nationalnumber: schema.string(),
dateofbirth: schema.string(),
placeofbirth: schema.string(),
gender: schema.string(),
specialstatus: schema.string(),
name: schema.string(),
firstname: schema.string(),
middlenames: schema.string(),
photo: schema.string(),
}).partial(),
address: schema.object({
municipality: schema.string(),
streetandnumber: schema.string(),
zip: schema.string(),
}).partial(),
xml: schema
.object({
encoding: schema.string(),
version: schema.string(),
})
.partial(),
eid: schema
.object({
graphpersoversion: schema.string(),
version: schema.string(),
})
.partial(),
card: schema
.object({
carddata_appl_version: schema.string(),
cardnumber: schema.string(),
chipnumber: schema.string(),
documenttype: schema.string(),
validitydatebegin: schema.string(),
validitydateend: schema.string(),
deliverymunicipality: schema.string(),
})
.partial(),
certificates: schema
.object({
authentication: schema.string(),
citizenca: schema.string(),
root: schema.string(),
rrn: schema.string(),
signing: schema.string(),
})
.partial(),
identity: schema
.object({
nationality: schema.string(),
nationalnumber: schema.string(),
dateofbirth: schema.string(),
placeofbirth: schema.string(),
gender: schema.string(),
specialstatus: schema.string(),
name: schema.string(),
firstname: schema.string(),
middlenames: schema.string(),
photo: schema.string(),
})
.partial(),
address: schema
.object({
municipality: schema.string(),
streetandnumber: schema.string(),
zip: schema.string(),
})
.partial(),
});

export type EidFields = schema.infer<typeof eidFields>;
Expand All @@ -56,8 +68,7 @@ const eidMetadata = schema.object({

export type EidMetadata = schema.infer<typeof eidMetadata>;

export const eidDocument = eidFields
.merge(eidMetadata);
export const eidDocument = eidFields.merge(eidMetadata);
export type EidDocument = schema.infer<typeof eidDocument>;

const collection = 'eids';
Expand Down
26 changes: 14 additions & 12 deletions imports/api/collection/patients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ export const patientTag = schema.object({

export type PatientTag = schema.infer<typeof patientTag>;

export const patientIdFields = schema.object({
niss: schema.string(),
firstname: schema.string(),
lastname: schema.string(),
birthdate: schema.string(),
sex: patientSex,
photo: schema.string(),

municipality: schema.string(),
streetandnumber: schema.string(),
zip: schema.string(),
}).partial();
export const patientIdFields = schema
.object({
niss: schema.string(),
firstname: schema.string(),
lastname: schema.string(),
birthdate: schema.string(),
sex: patientSex,
photo: schema.string(),

municipality: schema.string(),
streetandnumber: schema.string(),
zip: schema.string(),
})
.partial();

export type PatientIdFields = schema.infer<typeof patientIdFields>;

Expand Down
123 changes: 66 additions & 57 deletions imports/api/eidParseXML.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,78 @@
import {xml2json} from 'xml-js';

import schema from '../lib/schema';

import {type EidFields} from './collection/eids';

const text = schema.object({
_text: schema.string()
_text: schema.string(),
});

export const eidXml = schema.object({
_declaration: schema.object({
_attributes: schema.object({
encoding: schema.string(),
version: schema.string(),
}).partial(),
_attributes: schema
.object({
encoding: schema.string(),
version: schema.string(),
})
.partial(),
}),
eid: schema.object({
_attributes: schema.object({
graphpersoversion: schema.string(),
version: schema.string(),
}).partial(),
address: schema.object({
municipality: text.optional(),
streetandnumber: text.optional(),
zip: text.optional(),
}).optional(),
card: schema.object({
_attributes: schema.object({
carddata_appl_version: schema.string(),
cardnumber: schema.string(),
chipnumber: schema.string(),
documenttype: schema.string(),
validitydatebegin: schema.string(),
validitydateend: schema.string(),
}).partial(),
deliverymunicipality: text.optional(),
}).optional(),
certificates: schema.object({
authentication: text.optional(),
citizenca: text.optional(),
root: text.optional(),
rrn: text.optional(),
signing: text.optional(),
}).optional(),
identity: schema.object({
_attributes: schema.object({
dateofbirth: schema.string(),
gender: schema.string(),
nationalnumber: schema.string(),
specialstatus: schema.string(),
}).partial(),
firstname: text.optional(),
middlenames: text.optional(),
name: text.optional(),
nationality: text.optional(),
photo: text.optional(),
placeofbirth: text.optional(),
}).optional(),
_attributes: schema
.object({
graphpersoversion: schema.string(),
version: schema.string(),
})
.partial(),
address: schema
.object({
municipality: text.optional(),
streetandnumber: text.optional(),
zip: text.optional(),
})
.optional(),
card: schema
.object({
_attributes: schema
.object({
carddata_appl_version: schema.string(),
cardnumber: schema.string(),
chipnumber: schema.string(),
documenttype: schema.string(),
validitydatebegin: schema.string(),
validitydateend: schema.string(),
})
.partial(),
deliverymunicipality: text.optional(),
})
.optional(),
certificates: schema
.object({
authentication: text.optional(),
citizenca: text.optional(),
root: text.optional(),
rrn: text.optional(),
signing: text.optional(),
})
.optional(),
identity: schema
.object({
_attributes: schema
.object({
dateofbirth: schema.string(),
gender: schema.string(),
nationalnumber: schema.string(),
specialstatus: schema.string(),
})
.partial(),
firstname: text.optional(),
middlenames: text.optional(),
name: text.optional(),
nationality: text.optional(),
photo: text.optional(),
placeofbirth: text.optional(),
})
.optional(),
}),
});

Expand All @@ -66,16 +83,8 @@ const eidParseXML = (xmlString: string): EidFields => {
console.debug('eidXMLToJSON', {json});

const {
_declaration: {
_attributes: xml,
},
eid: {
_attributes: eid,
address,
card,
certificates,
identity,
}
_declaration: {_attributes: xml},
eid: {_attributes: eid, address, card, certificates, identity},
} = eidXml.parse(json);

return {
Expand Down Expand Up @@ -105,7 +114,7 @@ const eidParseXML = (xmlString: string): EidFields => {
name: identity?.name?._text,
photo: identity?.photo?._text,
placeofbirth: identity?.placeofbirth?._text,
}
},
};
};

Expand Down
39 changes: 18 additions & 21 deletions imports/api/endpoint/patients/insertFromEid.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ import {Insurances} from '../../collection/insurances';

import {newEidData} from '../../_dev/populate/eids';
import invoke from '../invoke';

import {normalizedName, patientFieldsFromEid} from '../../patients';

import insertFromEid from './insertFromEid';
import { normalizedName, patientFieldsFromEid } from '../../patients';

server(__filename, () => {
it('cannot create a patient when not logged in', async () => {
return throws(
async () => invoke(
insertFromEid,
// @ts-expect-error Type-checking is working as expected.
{userId: undefined},
[newEidData()]
),
async () =>
invoke(
insertFromEid,
// @ts-expect-error Type-checking is working as expected.
{userId: undefined},
[newEidData()],
),
/not-authorized/,
);
});
Expand All @@ -38,8 +41,11 @@ server(__filename, () => {

const expectedPatientFields = patientFieldsFromEid(eid);
const expectedComputedFields = {
normalizedName: normalizedName(expectedPatientFields.firstname, expectedPatientFields.lastname),
}
normalizedName: normalizedName(
expectedPatientFields.firstname,
expectedPatientFields.lastname,
),
};

const expected = {
...expectedPatientFields,
Expand All @@ -55,17 +61,8 @@ server(__filename, () => {

assert.isAtMost(createdAt.valueOf(), Date.now());

assert.sameDeepMembers(
await Allergies.find().fetchAsync(),
[],
);
assert.sameDeepMembers(
await Doctors.find().fetchAsync(),
[],
);
assert.sameDeepMembers(
await Insurances.find().fetchAsync(),
[],
);
assert.sameDeepMembers(await Allergies.find().fetchAsync(), []);
assert.sameDeepMembers(await Doctors.find().fetchAsync(), []);
assert.sameDeepMembers(await Insurances.find().fetchAsync(), []);
});
});
3 changes: 2 additions & 1 deletion imports/api/endpoint/patients/insertFromEid.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {AuthenticationLoggedIn} from '../../Authentication';

import schema from '../../../lib/schema';
import { eidFields, Eids } from '../../collection/eids';
import {eidFields, Eids} from '../../collection/eids';
import {patientFieldsFromEid} from '../../patients';
import type TransactionDriver from '../../transaction/TransactionDriver';

import define from '../define';
import compose from '../compose';

import insert from './insert';

export default define({
Expand Down
Loading

0 comments on commit fa981ea

Please sign in to comment.