const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const medical_events = sequelize.define(
    'medical_events',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

event_at: {
        type: DataTypes.DATE,
      
      

      },

provider_name: {
        type: DataTypes.TEXT,
      
      

      },

facility_name: {
        type: DataTypes.TEXT,
      
      

      },

diagnoses: {
        type: DataTypes.TEXT,
      
      

      },

icd10_codes: {
        type: DataTypes.TEXT,
      
      

      },

procedures: {
        type: DataTypes.TEXT,
      
      

      },

medications: {
        type: DataTypes.TEXT,
      
      

      },

notes: {
        type: DataTypes.TEXT,
      
      

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  medical_events.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity































//end loop



    db.medical_events.belongsTo(db.medical_chronology_reports, {
      as: 'report',
      foreignKey: {
        name: 'reportId',
      },
      constraints: false,
    });

    db.medical_events.belongsTo(db.files, {
      as: 'linked_file',
      foreignKey: {
        name: 'linked_fileId',
      },
      constraints: false,
    });




    db.medical_events.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.medical_events.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return medical_events;
};


