Skip to content

Commit

Permalink
[Closes #169] Generate patient fields from metadata shared between se…
Browse files Browse the repository at this point in the history
…rver and client (#185)

* Create Metadata class to store field metadata

Move patient field setup into metadata/patient.js.

* Move metadata into src/metadata

CRA annoyingly refuses to import anything from outside that folder.

* Add getters/setters to Ringdown based on field metadata from patient

Also generate PropTypes from field metadata.
Use a shared DeliveryStatus in Ringdown.js instead of defining a copy.
Move deliveryStatus.js to src/constants/DeliveryStatus.js.
Rename Metadata.js to ModelMetadata.js.
Add FieldMetadata.js and convertToSequelizeField.js.

* Prettier nonsense

* Add new fields to patient metadata

Add PatientFields and Ringdown changes from 169-ems-update-form branch.
Fix default value for status indicator.

* Add migration for new fields in patient database

Pass table and model names to ModelMetadata constructor.

* Tweak names in migration

Pass the type instead of the whole field object.
Prettier and eslint nonsense.

* Refactor ModelMetadata

Use getFieldHash() for getting the prop types as well, passing in convertToPropType.

* Fix server tests to handle new fields

* Add ranges to fields in metadata/patient.js

* Create Form component to provide context to fields

Provide ringdown data and onChange handler to form fields via the Form context.
Create Field component to generate checkboxes, numeric inputs, and text areas based on the metadata type.
Add label and unit strings to the patient metadata.
Tweak restraint label.

* Move Field component into FormField.js

Add form to wrap children and receive props in Form component.
Remove unnecessary fragment wrapper on PatientFields.
Fix degree symbol on temp.

* Add propTypes to Form.js

Update prettier to 2.7.1.
Force Prettier to ignore parts of some files and allow it uglify others.

* Clean up after rebasing on master

* Fix wrapping in O2 label and field

Make "optional" align right in the Header elemens by removing an extra div.

* Move Urgency field up into Incident info section

Refactor and simplify creation of validationData in Ringdown.js.
Update section labels in ringdown form.
Fix Form.children prop type.

* Add patientDelivery metadata

In ModelMetadata, always add the created and updated fields to the model, so they don't have to get included over and over.

* Add metadata for ambulance, emergencyMedicalServiceCall, and emergencyMedicalServiceCallAmbulance

* Make sure defaultValue included in Sequelize attributes, fix tests for new defaultValue default for booleans

* Add metadata for hospital

* Add metadata for hospitalUser

* Add metadata for organization and patientDeliveryUpdate

* Add metadata for user

Add support in convertToSequelizeField() for sequelize getters/setters, validate key and virtual type fields.

* Add defaultValue for timezone in organization to fix tests

Simplify convertToSequelizeField.

* Unify enumValues and virtualArgs as typeArgs

* Refactor ands simplify ModelMetadata

Add toString method to FieldMetadata.

* Move metadata and constants into /src/shared

* Move shared classes and utils to /src/shared

* Create payload sub-objects and defaults programmatically

Add metadata/index.js.
Change createValidationData() to setValidationData(),.
Get rid of ambulance and emsCall getters defined in class.

* Set defaultValue to '' for fields used in comboboxes

* Add the field getters/setters to the Ringdown prototype

Don't add them to every instance individually.

* Make migration a static standalone script

* Include treatmentNotes and glasgowComaScale fields in ringdown details

Co-authored-by: Francis Li <[email protected]>
  • Loading branch information
fwextensions and francisli authored Sep 8, 2022
1 parent 808062e commit 684de07
Show file tree
Hide file tree
Showing 47 changed files with 1,421 additions and 1,436 deletions.
31 changes: 0 additions & 31 deletions constants/deliveryStatus.js

This file was deleted.

1 change: 0 additions & 1 deletion constants/index.js

This file was deleted.

15 changes: 15 additions & 0 deletions migrations/20220721055200-add-gcs-treatments-to-patient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.addColumn('patient', 'treatmentnotes', Sequelize.TEXT, { transaction });
await queryInterface.addColumn('patient', 'glasgowcomascale', Sequelize.INTEGER, { transaction });
});
},

async down(queryInterface) {
await queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.removeColumn('patient', 'glasgowcomascale', { transaction });
await queryInterface.removeColumn('patient', 'treatmentnotes', { transaction });
});
},
};
58 changes: 9 additions & 49 deletions models/ambulance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { Model } = require('sequelize');
const metadata = require('../src/shared/metadata/ambulance');
const convertToSequelizeField = require('../src/shared/convertToSequelizeField');

module.exports = (sequelize, DataTypes) => {
module.exports = (sequelize) => {
class Ambulance extends Model {
static associate(models) {
Ambulance.belongsTo(models.Organization);
Expand All @@ -14,53 +16,11 @@ module.exports = (sequelize, DataTypes) => {
}
}

Ambulance.init(
{
id: {
field: 'ambulance_uuid',
type: DataTypes.UUID,
primaryKey: true,
autoIncrement: true,
},
OrganizationId: {
field: 'emsorganization_uuid',
type: DataTypes.UUID,
},
ambulanceIdentifier: {
field: 'ambulanceidentifier',
type: DataTypes.STRING,
unique: true,
allowNull: false,
},
isActive: {
field: 'activeindicator',
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
},
createdAt: {
field: 'recordcreatetimestamp',
type: DataTypes.DATE,
},
CreatedById: {
field: 'recordcreateuser_uuid',
type: DataTypes.UUID,
},
updatedAt: {
field: 'recordupdatetimestamp',
type: DataTypes.DATE,
},
UpdatedById: {
field: 'recordupdateuser_uuid',
type: DataTypes.UUID,
},
},
{
sequelize,
timestamps: true,
tableName: 'ambulance',
modelName: 'Ambulance',
}
);
Ambulance.init(metadata.getFieldHash(convertToSequelizeField), {
sequelize,
timestamps: true,
tableName: metadata.tableName,
modelName: metadata.modelName,
});
return Ambulance;
};
52 changes: 9 additions & 43 deletions models/emergencyMedicalServiceCall.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { Model } = require('sequelize');
const metadata = require('../src/shared/metadata/emergencyMedicalServiceCall');
const convertToSequelizeField = require('../src/shared/convertToSequelizeField');

module.exports = (sequelize, DataTypes) => {
module.exports = (sequelize) => {
class EmergencyMedicalServiceCall extends Model {
/**
* Helper method for defining associations.
Expand All @@ -17,47 +19,11 @@ module.exports = (sequelize, DataTypes) => {
EmergencyMedicalServiceCall.belongsTo(models.User, { as: 'UpdatedBy' });
}
}
EmergencyMedicalServiceCall.init(
{
id: {
field: 'emergencymedicalservicecall_uuid',
type: DataTypes.UUID,
primaryKey: true,
autoIncrement: true,
},
dispatchCallNumber: {
field: 'dispatchcallnumber',
type: DataTypes.INTEGER,
allowNull: false,
},
startDateTimeLocal: {
field: 'startdatetimelocal',
type: DataTypes.DATE,
allowNull: false,
},
createdAt: {
field: 'recordcreatetimestamp',
type: DataTypes.DATE,
},
CreatedById: {
field: 'recordcreateuser_uuid',
type: DataTypes.UUID,
},
updatedAt: {
field: 'recordupdatetimestamp',
type: DataTypes.DATE,
},
UpdatedById: {
field: 'recordupdateuser_uuid',
type: DataTypes.UUID,
},
},
{
sequelize,
timestamps: true,
tableName: 'emergencymedicalservicecall',
modelName: 'EmergencyMedicalServiceCall',
}
);
EmergencyMedicalServiceCall.init(metadata.getFieldHash(convertToSequelizeField), {
sequelize,
timestamps: true,
tableName: metadata.tableName,
modelName: metadata.modelName,
});
return EmergencyMedicalServiceCall;
};
55 changes: 9 additions & 46 deletions models/emergencyMedicalServiceCallAmbulance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { Model } = require('sequelize');
const metadata = require('../src/shared/metadata/emergencyMedicalServiceCallAmbulance');
const convertToSequelizeField = require('../src/shared/convertToSequelizeField');

module.exports = (sequelize, DataTypes) => {
module.exports = (sequelize) => {
class EmergencyMedicalServiceCallAmbulance extends Model {
/**
* Helper method for defining associations.
Expand All @@ -15,50 +17,11 @@ module.exports = (sequelize, DataTypes) => {
EmergencyMedicalServiceCallAmbulance.belongsTo(models.User, { as: 'UpdatedBy' });
}
}
EmergencyMedicalServiceCallAmbulance.init(
{
id: {
field: 'emergencymedicalservicecallambulance_uuid',
type: DataTypes.UUID,
primaryKey: true,
autoIncrement: true,
},
EmergencyMedicalServiceCallId: {
field: 'emergencymedicalservicecall_uuid',
type: DataTypes.UUID,
},
AmbulanceId: {
field: 'ambulance_uuid',
type: DataTypes.UUID,
},
startDateTimeLocal: {
field: 'startdatetimelocal',
type: DataTypes.DATE,
allowNull: false,
},
createdAt: {
field: 'recordcreatetimestamp',
type: DataTypes.DATE,
},
CreatedById: {
field: 'recordcreateuser_uuid',
type: DataTypes.UUID,
},
updatedAt: {
field: 'recordupdatetimestamp',
type: DataTypes.DATE,
},
UpdatedById: {
field: 'recordupdateuser_uuid',
type: DataTypes.UUID,
},
},
{
sequelize,
timestamps: true,
tableName: 'emergencymedicalservicecallambulance',
modelName: 'EmergencyMedicalServiceCallAmbulance',
}
);
EmergencyMedicalServiceCallAmbulance.init(metadata.getFieldHash(convertToSequelizeField), {
sequelize,
timestamps: true,
tableName: metadata.tableName,
modelName: metadata.modelName,
});
return EmergencyMedicalServiceCallAmbulance;
};
73 changes: 10 additions & 63 deletions models/hospital.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const _ = require('lodash');
const { Model } = require('sequelize');
const { DeliveryStatus } = require('../constants');
const { DeliveryStatus } = require('../src/shared/constants');
const metadata = require('../src/shared/metadata/hospital');
const convertToSequelizeField = require('../src/shared/convertToSequelizeField');

module.exports = (sequelize, DataTypes) => {
module.exports = (sequelize) => {
class Hospital extends Model {
static associate(models) {
Hospital.belongsTo(models.Organization);
Expand Down Expand Up @@ -48,66 +50,11 @@ module.exports = (sequelize, DataTypes) => {
}
}

Hospital.init(
{
// this is the value used to determine who each nurse belongs to
id: {
field: 'hospital_uuid',
type: DataTypes.UUID,
primaryKey: true,
autoIncrement: true,
},
OrganizationId: {
field: 'healthcareorganization_uuid',
type: DataTypes.UUID,
},
name: {
field: 'hospitalname',
type: DataTypes.STRING,
unique: true,
allowNull: false,
},
state: {
field: 'hospitalstate',
type: DataTypes.STRING,
},
stateFacilityCode: {
field: 'hospitalstatefacilitycode',
type: DataTypes.STRING,
},
sortSequenceNumber: {
field: 'sortsequencenumber',
type: DataTypes.INTEGER,
},
isActive: {
field: 'activeindicator',
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: true,
},
createdAt: {
field: 'recordcreatetimestamp',
type: DataTypes.DATE,
},
CreatedById: {
field: 'recordcreateuser_uuid',
type: DataTypes.UUID,
},
updatedAt: {
field: 'recordupdatetimestamp',
type: DataTypes.DATE,
},
UpdatedById: {
field: 'recordupdateuser_uuid',
type: DataTypes.UUID,
},
},
{
sequelize,
timestamps: true,
tableName: 'hospital',
modelName: 'Hospital',
}
);
Hospital.init(metadata.getFieldHash(convertToSequelizeField), {
sequelize,
timestamps: true,
tableName: metadata.tableName,
modelName: metadata.modelName,
});
return Hospital;
};
Loading

0 comments on commit 684de07

Please sign in to comment.