Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Requirements

See BRIDGE-2485, BRIDGE-647, BRIDGE-769, BRIDGE-453, BRIDGE-2382, BRIDGE-2383

...

  • Custom template implementation (just ensure the design can accommodate it);
  • Additional document implementation (just ensure the design can accommodate it);
  • Document inclusions or attachments (e.g. images for HTML documents... unless we really want this);
  • Variable resolution (that's part of using the template);
  • Publishing documents (that's part of the consent system).

Template Model

Image RemovedImage Added

You can now add any number of templates for a specific type of template, differentiated by their guids, and selectable using Criteria.

...

CREATE TABLE `Template` (
  `guid` VARCHAR(60) NOT NULL,
  `studyId` VARCHAR(255) NOT NULL,
  `type` ENUM('EMAIL_ACCOUNT_EXISTS', 'ACCOUNT_EXISTS_SMS', 'EMAIL_APP_INSTALL_LINK', 'APPEMAIL_INSTALLRESET_LINK_SMSPASSWORD',
'EMAIL_SIGN_IN',
    'PHONE_SIGN_IN_SMS', 'RESET_PASSWORD', 'RESET_PASSWORD_SMS', 'SIGNED_CONSENT', 'SIGNED_CONSENT_SMS',
    'VERIFY_EMAIL', 'VERIFY_PHONE_SMS'EMAIL_SIGNED_CONSENT', 'EMAIL_VERIFY_EMAIL', 'SMS_ACCOUNT_EXISTS',
'SMS_APP_INSTALL_LINK', 'SMS_PHONE_SIGN_IN', 'SMS_RESET_PASSWORD', 'SMS_SIGNED_CONSENT',
'SMS_VERIFY_PHONE'
) NOT NULL,
  `name` VARCHAR(255) NULL,
  `criteriaKey` VARCHAR(255) NULL`description` TEXT,
  `createdOn` BIGINT UNSIGNED NULL,
  `modifiedOn` BIGINT UNSIGNED NULL,
  `publishedCreatedOn` BIGINT UNSIGNED NULL,
  `deleted` BOOLEAN NOT NULL DEFAULT FALSE,
  `version` INT UNSIGNED NOT NULL, /* optimistic locking */
  PRIMARY KEY (`guid`),
  INDEX `type_set_idx` (`studyId`, `type`)
) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

CREATE TABLE `TemplateRevision` (
  `templateGuid` VARCHAR(60) NOT NULL,
  `createdOn` BIGINT UNSIGNED NULL,
  `createdBy` VARCHAR(255) NOT NULL,
  `storagePath` VARCHAR(255) NOT NULL,
  `subject` VARCHAR(255) NULL,
  `mimeType` ENUM('HTML', 'TEXT') NULL,
  PRIMARY_KEY (`guid``templateGuid`, `createdOn`)
  CONSTRAINT `Templates-Guid-Constraint`
    FOREIGN KEY (`templateGuid`) REFERENCES `Templates` (`guid`) ON DELETE CASCADE

) CHARACTER SET utf8 COLLATE utf8_unicode_ci;

...

GET    /v3/templates?type=<type>
    get documents of type (type parameter is probably required)
POST   /v3/templates
    create new document with a single default revision with default content. As we do now, we should have default content to prePre-fill the first revision , just to help people get started. 
GET    /v3/templates/<guid>
    get specific documenttemplate
POST   /v3/templates/<guid>
    update specific document template (not revisioned, but optimistically locked)
DELETE /v3/templates/<guid>?physical=true
    delete specific document template (logical or physical); probably just leaves revisions TemplateRevision content on S3
GET    /v3/templates/<guid>/revisions
    get the revisions for a document template (createdOn DESC) for history of edits
POST   /v3/templates/<guid>/revisions
    create a new revision of the given document template (cannot update an existing revision)
GET    /v3/templates/<guid>/revisions/<createdOn>
    get a specific revision of a documenttemplate
POST   /v3/templates/<guid>/revisions/<createdOn>/publish
    publish this revision as the revision to use when the document template is selected

Notes

Selection

...

Sorry the formatting here is difficult to read, due to Jira.

public interface TemplateService {

    /**

     * Given a criteria context and a template type, return all the templates that match. If one is found through a

...

    Template getTemplateForUser(CriteriaContext context, TemplateType type);


    /** Get all the templates for a given type. (I am assuming this will not need to be paged). */

    List<Template> getTemplatesForType(StudyIdentifier studyId, TemplateType type, boolean includeDeleted);


    /** Get a specific template. */

    Template getTemplate(StudyIdentifier studyId, String guid);


    /** Create a new template. */

    GuidVersionHolder createTemplate(StudyIdentifier studyId, TemplateService template);


    /**

     * Update a template. You can delete it logically, and change the published revision of the associated document with this call as well.

...

    GuidVersionHolder updateTemplate(StudyIdentifier studyId, TemplateService template);


    /** Mark a template as deleted. */

    void deleteTemplate(StudyIdentifier studyId, String guid);


    /** Physically delete the template and all its revisions. */

    void deleteTemplatePermanently(StudyIdentifier studyId, String guid);


    /** Get a page of revisions from a SQL-type data store. These would not load the document contents from S3 or would not load the

     * relevant column if we end up storing the body content in SQL.

     */

    PagedResourceList<TemplateRevision> getTemplateRevisions(StudyIdentifier studyId, String guid,

            int offsetBy, int pageSize);


    /** Get a specific revision. */

    TemplateRevision getTemplateRevision(StudyIdentifier studyId, String guid, long createdOn);


    /** Create a new revision (this should fail if the createdOn timestamp for a given studyId and GUID already exists). */

    CreatedOnHolder createTemplateRevision(StudyIdentifier studyId, TemplateRevision templateRevision);

}

Migration

Can be done in three four deployments:

1) Switch over to Add the new template system (server, SDK, BSM), but when in parallel. When reading a template from the existing study object, if there's no default template, have TemplateService read from defer first to the existing template system and use that if a template exists, falling back to the study object . Writes go forward as usual and are used thereafter. The *history* of revisions at this point will not be 100% accurate but all data and changes will be used correctly.

2) Go back and create default templates for each study, deleting the study object templates (we can have this script ready and do it shortly after #1);

3template. When writing templates to the study, write to both places, setting up a default template in the templates system if necessary.

2) Create templates for each study from the study object templates.

3) Remove migration bridges to the study object and use only the template system.

4) Delete the fields in the study object itself and remove the bridge back to fields in the study object schema.