diff --git a/admin/src/js/services/import-contacts.js b/admin/src/js/services/import-contacts.js index c6b82196740..44ac358c690 100644 --- a/admin/src/js/services/import-contacts.js +++ b/admin/src/js/services/import-contacts.js @@ -1,3 +1,4 @@ +const constants = require('@medic/constants'); angular.module('services').factory('ImportContacts', function( $http, @@ -21,9 +22,9 @@ angular.module('services').factory('ImportContacts', } return $q.reject(new Error(`Unknown type "${provided}"" for person named "${contact.name}"`)); } - if (types.find(type => type.id === 'person')) { + if (types.some(type => type.id === constants.CONTACT_TYPES.PERSON)) { // retained for backwards compatibility - return 'person'; + return constants.CONTACT_TYPES.PERSON; } return $q.reject(new Error(`Undefined type for person named "${contact.name}"`)); }); @@ -37,7 +38,7 @@ angular.module('services').factory('ImportContacts', phone: doc.contact.phone, parent: doc }; - if (type === 'person') { + if (type === constants.CONTACT_TYPES.PERSON) { person.type = type; } else { person.type = 'contact'; diff --git a/shared-libs/cht-datasource/src/local/person.ts b/shared-libs/cht-datasource/src/local/person.ts index e3cf96c3e75..4f0bb8ade7f 100644 --- a/shared-libs/cht-datasource/src/local/person.ts +++ b/shared-libs/cht-datasource/src/local/person.ts @@ -15,7 +15,7 @@ import { assertPersonInput } from '../libs/parameter-validators'; import { CONTACT_TYPES } from '@medic/constants'; const DEFAULT_PERSON_TYPE = { - id: 'person', + id: CONTACT_TYPES.PERSON, parents: [ CONTACT_TYPES.DISTRICT_HOSPITAL, 'health_center', diff --git a/shared-libs/constants/src/index.js b/shared-libs/constants/src/index.js index ae4309d9984..165377c5963 100644 --- a/shared-libs/constants/src/index.js +++ b/shared-libs/constants/src/index.js @@ -19,6 +19,7 @@ const CONTACT_TYPES = { HEALTH_CENTER: 'health_center', CLINIC: 'clinic', DISTRICT_HOSPITAL: 'district_hospital', + PERSON: 'person', }; // Document Types diff --git a/shared-libs/contact-types-utils/src/index.js b/shared-libs/contact-types-utils/src/index.js index cb206192f36..b2c0b9fa355 100644 --- a/shared-libs/contact-types-utils/src/index.js +++ b/shared-libs/contact-types-utils/src/index.js @@ -1,11 +1,11 @@ const { CONTACT_TYPES } = require('@medic/constants'); -const HARDCODED_PERSON_TYPE = 'person'; +const HARDCODED_PERSON_TYPE = CONTACT_TYPES.PERSON; const HARDCODED_TYPES = [ CONTACT_TYPES.DISTRICT_HOSPITAL, CONTACT_TYPES.HEALTH_CENTER, CONTACT_TYPES.CLINIC, - 'person' + CONTACT_TYPES.PERSON ]; const getContactTypes = config => { diff --git a/shared-libs/contacts/src/people.js b/shared-libs/contacts/src/people.js index a9194205acc..abb6bba90dc 100644 --- a/shared-libs/contacts/src/people.js +++ b/shared-libs/contacts/src/people.js @@ -7,6 +7,7 @@ const places = require('./places'); const lineage = require('./libs/lineage'); const { Person, Qualifier } = require('@medic/cht-datasource'); const contactTypeUtils = require('@medic/contact-types-utils'); +const { CONTACT_TYPES } = require('@medic/constants'); const getPerson = id => dataContext .bind(Person.v1.getWithLineage)(Qualifier.byUuid(id)) @@ -20,7 +21,7 @@ const getPerson = id => dataContext const isAPerson = person => contactTypeUtils.isPerson(config.get(), person); const getDefaultPersonType = () => { - const type = contactTypeUtils.getTypeById(config.get(), 'person'); + const type = contactTypeUtils.getTypeById(config.get(), CONTACT_TYPES.PERSON); return type && type.id; }; diff --git a/shared-libs/transitions/src/transitions/registration.js b/shared-libs/transitions/src/transitions/registration.js index 1eabd7d56c6..3d1a8fefd52 100644 --- a/shared-libs/transitions/src/transitions/registration.js +++ b/shared-libs/transitions/src/transitions/registration.js @@ -20,7 +20,7 @@ const NAME = 'registration'; const PARENT_NOT_FOUND = 'parent_not_found'; const PARENT_FIELD_NOT_PROVIDED = 'parent_field_not_provided'; const PARENT_INVALID = 'parent_invalid'; -const { DOC_TYPES } = require('@medic/constants'); +const { CONTACT_TYPES, DOC_TYPES } = require('@medic/constants'); const findFirstDefinedValue = (doc, fields) => { const definedField = fields.find(field => doc.fields[field] !== undefined && doc.fields[field] !== null); @@ -489,7 +489,7 @@ const addPatient = (options) => { patient.type = 'contact'; patient.contact_type = options.params.contact_type; } else { - patient.type = 'person'; + patient.type = CONTACT_TYPES.PERSON; } @@ -631,7 +631,7 @@ module.exports = { `patient_id_field cannot be set to patient_id` ); } - const typeId = params.contact_type || 'person'; + const typeId = params.contact_type || CONTACT_TYPES.PERSON; const contactType = contactTypesUtils.getTypeById(config.getAll(), typeId); if (!contactType) { throw new Error( diff --git a/webapp/src/ts/services/contact-save.service.ts b/webapp/src/ts/services/contact-save.service.ts index 8d72dabd892..7f464d307a8 100644 --- a/webapp/src/ts/services/contact-save.service.ts +++ b/webapp/src/ts/services/contact-save.service.ts @@ -7,6 +7,7 @@ import { EnketoTranslationService } from '@mm-services/enketo-translation.servic import { ExtractLineageService } from '@mm-services/extract-lineage.service'; import { AttachmentService } from '@mm-services/attachment.service'; import { CHTDatasourceService } from '@mm-services/cht-datasource.service'; +import { CONTACT_TYPES } from '@medic/constants'; import { Contact, Qualifier } from '@medic/cht-datasource'; import { Xpath } from '@mm-providers/xpath-element-path.provider'; import FileManager from '../../js/enketo/file-manager'; @@ -267,7 +268,7 @@ export class ContactSaveService { // by default all siblings are "person" types but can be overridden // by specifying the type and contact_type in the form if (!preparedSibling.type) { - preparedSibling.type = 'person'; + preparedSibling.type = CONTACT_TYPES.PERSON; } if (preparedSibling.parent === 'PARENT') { diff --git a/webapp/web-components/cht-form/src/app.component.ts b/webapp/web-components/cht-form/src/app.component.ts index 20315879169..43cdbd51c6a 100644 --- a/webapp/web-components/cht-form/src/app.component.ts +++ b/webapp/web-components/cht-form/src/app.component.ts @@ -26,7 +26,7 @@ export class AppComponent { CONTACT_TYPES.DISTRICT_HOSPITAL, CONTACT_TYPES.HEALTH_CENTER, 'clinic', - 'person' + CONTACT_TYPES.PERSON ]; private readonly chtDataSourceService: CHTDatasourceServiceStub;