Skip to content
Open
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
7 changes: 4 additions & 3 deletions admin/src/js/services/import-contacts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const constants = require('@medic/constants');
angular.module('services').factory('ImportContacts',
function(
$http,
Expand All @@ -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}"`));
});
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion shared-libs/cht-datasource/src/local/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions shared-libs/constants/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const CONTACT_TYPES = {
HEALTH_CENTER: 'health_center',
CLINIC: 'clinic',
DISTRICT_HOSPITAL: 'district_hospital',
PERSON: 'person',
};

// Document Types
Expand Down
4 changes: 2 additions & 2 deletions shared-libs/contact-types-utils/src/index.js
Original file line number Diff line number Diff line change
@@ -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 => {
Expand Down
3 changes: 2 additions & 1 deletion shared-libs/contacts/src/people.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
};

Expand Down
6 changes: 3 additions & 3 deletions shared-libs/transitions/src/transitions/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/ts/services/contact-save.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion webapp/web-components/cht-form/src/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class AppComponent {
CONTACT_TYPES.DISTRICT_HOSPITAL,
CONTACT_TYPES.HEALTH_CENTER,
'clinic',
'person'
CONTACT_TYPES.PERSON
];

private readonly chtDataSourceService: CHTDatasourceServiceStub;
Expand Down