diff --git a/cms/models/Item.js b/cms/models/Item.js
index da6cbf90..45ab5672 100644
--- a/cms/models/Item.js
+++ b/cms/models/Item.js
@@ -156,6 +156,7 @@ Item.schema.post("save", async function(doc, next) {
.model.findById(doc._id)
.populate("source")
.populate("evidenceType")
+ .populate("speciality")
.exec();
} catch (err) {
logger.error("An error occurred finding item: ", err.message);
diff --git a/cms/routes/api/items.js b/cms/routes/api/items.js
index a6a3536a..989ce2e9 100644
--- a/cms/routes/api/items.js
+++ b/cms/routes/api/items.js
@@ -7,6 +7,7 @@ exports.single = function(req, res) {
.findById(req.params.itemId)
.populate("source")
.populate("evidenceType")
+ .populate("speciality")
.exec(function(err, item) {
if (err) return res.err(err);
@@ -25,6 +26,7 @@ exports.list = function(req, res) {
.find()
.populate("source")
.populate("evidenceType")
+ .populate("speciality")
.exec(function(err, items) {
if (err) return res.json({ err: err });
diff --git a/lambda/MAS.Tests/Feeds/multiple-items.json b/lambda/MAS.Tests/Feeds/multiple-items.json
index 7a9de604..b3c79e84 100644
--- a/lambda/MAS.Tests/Feeds/multiple-items.json
+++ b/lambda/MAS.Tests/Feeds/multiple-items.json
@@ -16,7 +16,18 @@
"publicationDate": "2019-11-25T13:48:36.000Z",
"createdDate": "2019-10-22T15:05:05.927Z",
"speciality": [
- "5daf1a5c8a34d485cb05b5ba"
+ {
+ "_id": "5e0e4331200a585f718e1ee5",
+ "key": "be1c2e2f-745e-4a82-b5aa-d4cef4d31a1b",
+ "title": "Anaesthesia and pain",
+ "__v": 0
+ },
+ {
+ _id: "5e0e4331200a58dead8e1ee8",
+ key: "53fc67a4-46d8-4171-9447-7fcf216c8749",
+ title: "Complementary and alternative therapies",
+ __v: 0
+ }
],
"evidenceType": {
"_id": "5df7abf383138898ee1f67ef",
@@ -44,7 +55,18 @@
"publicationDate": "2019-11-23T13:48:36.000Z",
"createdDate": "2019-10-23T10:38:43.000Z",
"speciality": [
- "5daf1a5c8a34d478fd05b5d4"
+ {
+ "_id": "5e0e4331200a585f718e1ee5",
+ "key": "be1c2e2f-745e-4a82-b5aa-d4cef4d31a1b",
+ "title": "Anaesthesia and pain",
+ "__v": 0
+ },
+ {
+ _id: "5e0e4331200a58dead8e1ee8",
+ key: "53fc67a4-46d8-4171-9447-7fcf216c8749",
+ title: "Complementary and alternative therapies",
+ __v: 0
+ }
],
"evidenceType": {
"_id": "5df7abf383138898ee1f67ef",
@@ -72,7 +94,18 @@
"publicationDate": "2019-10-23T00:00:00.000Z",
"createdDate": "2019-10-23T10:56:40.000Z",
"speciality": [
- "5daf1a5c8a34d4d6e505b5b9"
+ {
+ "_id": "5e0e4331200a585f718e1ee5",
+ "key": "be1c2e2f-745e-4a82-b5aa-d4cef4d31a1b",
+ "title": "Anaesthesia and pain",
+ "__v": 0
+ },
+ {
+ _id: "5e0e4331200a58dead8e1ee8",
+ key: "53fc67a4-46d8-4171-9447-7fcf216c8749",
+ title: "Complementary and alternative therapies",
+ __v: 0
+ }
],
"evidenceType": {
"_id": "5df7abf383138898ee1f67ef",
@@ -100,7 +133,18 @@
"publicationDate": "2019-10-28T00:00:00.000Z",
"createdDate": "2019-10-28T11:07:11.000Z",
"speciality": [
- "5daf1a5c8a34d485cb05b5ba"
+ {
+ "_id": "5e0e4331200a585f718e1ee5",
+ "key": "be1c2e2f-745e-4a82-b5aa-d4cef4d31a1b",
+ "title": "Anaesthesia and pain",
+ "__v": 0
+ },
+ {
+ _id: "5e0e4331200a58dead8e1ee8",
+ key: "53fc67a4-46d8-4171-9447-7fcf216c8749",
+ title: "Complementary and alternative therapies",
+ __v: 0
+ }
],
"evidenceType": {
"_id": "5df7abf383138898ee1f67ef",
diff --git a/lambda/MAS.Tests/IntergrationTests/ContentControllerTests.PutCMSItemSavesItemIntoS3.approved.txt b/lambda/MAS.Tests/IntergrationTests/ContentControllerTests.PutCMSItemSavesItemIntoS3.approved.txt
index 09046c0a..d9851094 100644
--- a/lambda/MAS.Tests/IntergrationTests/ContentControllerTests.PutCMSItemSavesItemIntoS3.approved.txt
+++ b/lambda/MAS.Tests/IntergrationTests/ContentControllerTests.PutCMSItemSavesItemIntoS3.approved.txt
@@ -2,6 +2,6 @@ Title: Some title
Short Summary: Wonder drug
Source: The Journal of Medicine
Evidence Type: Safety alerts
-UKMI Comment: UKMI Comment
+UKMI Comment: SPS Comment
Resource Links:
Link 1
Link 2
\ No newline at end of file
diff --git a/lambda/MAS.Tests/IntergrationTests/ContentControllerTests.cs b/lambda/MAS.Tests/IntergrationTests/ContentControllerTests.cs
index 9a9bd3d2..102363b9 100644
--- a/lambda/MAS.Tests/IntergrationTests/ContentControllerTests.cs
+++ b/lambda/MAS.Tests/IntergrationTests/ContentControllerTests.cs
@@ -43,7 +43,7 @@ public async Task PutCMSItemSavesItemIntoS3()
Key = "mas_evidence_types:Safety%20alerts",
Title = "Safety alerts"
},
- UKMiComment = "UKMI Comment",
+ Comment = "SPS Comment",
ResourceLinks = "Link 1
\r\nLink 2
"
};
diff --git a/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateEmailWithTwoItemsDifferentEvidenceType.approved.txt b/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateEmailWithTwoItemsDifferentEvidenceType.approved.txt
new file mode 100644
index 00000000..9e1af1a5
--- /dev/null
+++ b/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateEmailWithTwoItemsDifferentEvidenceType.approved.txt
@@ -0,0 +1 @@
+Some evidence typeSome Title
Some source
Some speciality
Some short summary
SPS Comment Some evidence type 2Some Title
Some source
Some speciality 2
Some short summary
SPS Comment
\ No newline at end of file
diff --git a/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateEmailWithTwoItemsSharingEvidenceType.approved.txt b/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateEmailWithTwoItemsSharingEvidenceType.approved.txt
new file mode 100644
index 00000000..16005a8a
--- /dev/null
+++ b/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateEmailWithTwoItemsSharingEvidenceType.approved.txt
@@ -0,0 +1 @@
+Some evidence typeSome Title
Some source
Some speciality
Some short summary
SPS CommentSome Title
Some source
Some speciality
Some short summary
SPS Comment
\ No newline at end of file
diff --git a/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateSingleItemEmail.approved.txt b/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateSingleItemEmail.approved.txt
new file mode 100644
index 00000000..fd61b616
--- /dev/null
+++ b/lambda/MAS.Tests/UnitTests/DailyEmailTests.CanCreateSingleItemEmail.approved.txt
@@ -0,0 +1 @@
+Some evidence typeSome Title
Some source
Some speciality
Some short summary
SPS Comment
\ No newline at end of file
diff --git a/lambda/MAS.Tests/UnitTests/DailyEmailTests.ItemsWithManySpecialitiesRenderCorrectly.approved.txt b/lambda/MAS.Tests/UnitTests/DailyEmailTests.ItemsWithManySpecialitiesRenderCorrectly.approved.txt
new file mode 100644
index 00000000..bbb5efda
--- /dev/null
+++ b/lambda/MAS.Tests/UnitTests/DailyEmailTests.ItemsWithManySpecialitiesRenderCorrectly.approved.txt
@@ -0,0 +1 @@
+Some evidence typeSome Title
Some source
Some speciality | Another speciality
Some short summary
SPS Comment
\ No newline at end of file
diff --git a/lambda/MAS.Tests/UnitTests/DailyEmailTests.cs b/lambda/MAS.Tests/UnitTests/DailyEmailTests.cs
new file mode 100644
index 00000000..1bb42492
--- /dev/null
+++ b/lambda/MAS.Tests/UnitTests/DailyEmailTests.cs
@@ -0,0 +1,139 @@
+using MAS.Models;
+using MAS.Tests.Infrastructure;
+using Shouldly;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace MAS.Tests.UnitTests
+{
+ public class DailyEmailTests : TestBase
+ {
+ Item exampleItem = new Item()
+ {
+ Id = "123",
+ Title = "Some Title",
+ Slug = "abc",
+ ShortSummary = "Some short summary",
+ ResourceLinks = "",
+ Comment = "",
+ Speciality = new List
+ {
+ new Speciality()
+ {
+ Key = "1a",
+ Title = "Some speciality",
+
+ }
+ },
+ EvidenceType = new EvidenceType()
+ {
+ Key = "1b",
+ Title = "Some evidence type"
+ },
+ Source = new Source()
+ {
+ Id = "1c",
+ Title = "Some source"
+ }
+ };
+ Item exampleItem2 = new Item()
+ {
+ Id = "123",
+ Title = "Some Title",
+ Slug = "abc",
+ ShortSummary = "Some short summary",
+ ResourceLinks = "",
+ Comment = "",
+ Speciality = new List
+ {
+ new Speciality()
+ {
+ Key = "1a",
+ Title = "Some speciality 2",
+
+ }
+ },
+ EvidenceType = new EvidenceType()
+ {
+ Key = "1c",
+ Title = "Some evidence type 2"
+ },
+ Source = new Source()
+ {
+ Id = "1c",
+ Title = "Some source"
+ }
+ };
+
+ [Fact]
+ public void CanCreateSingleItemEmail()
+ {
+ var email = new DailyEmail()
+ {
+ Items = new List- ()
+ {
+ exampleItem
+ }
+ };
+
+ var expectedHtml = "
Some evidence typeSome Title
Some source
Some speciality
Some short summary
SPS Comment ";
+
+ expectedHtml.ShouldMatchApproved(email.HTML);
+
+ }
+
+ [Fact]
+ public void CanCreateEmailWithTwoItemsSharingEvidenceType()
+ {
+ var email = new DailyEmail()
+ {
+ Items = new List- ()
+ {
+ exampleItem,
+ exampleItem
+ }
+ };
+
+ var expectedHtml = "
Some evidence typeSome Title
Some source
Some speciality
Some short summary
SPS CommentSome Title
Some source
Some speciality
Some short summary
SPS Comment ";
+ expectedHtml.ShouldMatchApproved(email.HTML);
+
+ }
+
+ [Fact]
+ public void CanCreateEmailWithTwoItemsDifferentEvidenceType()
+ {
+ var email = new DailyEmail()
+ {
+ Items = new List- ()
+ {
+ exampleItem,
+ exampleItem2
+ }
+ };
+
+ var expectedHtml = "
Some evidence typeSome Title
Some source
Some speciality
Some short summary
SPS Comment Some evidence type 2Some Title
Some source
Some speciality 2
Some short summary
SPS Comment ";
+ expectedHtml.ShouldMatchApproved(email.HTML);
+
+ }
+
+ [Fact]
+ public void ItemsWithManySpecialitiesRenderCorrectly()
+ {
+ exampleItem.Speciality.Add(new Speciality() { Key = "abcd", Title = "Another speciality" });
+ var email = new DailyEmail()
+ {
+ Items = new List- ()
+ {
+ exampleItem
+ }
+ };
+
+ var expectedHtml = "
Some evidence typeSome Title
Some source
Some speciality | Another speciality
Some short summary
SPS Comment ";
+ expectedHtml.ShouldMatchApproved(email.HTML);
+
+ }
+ }
+}
diff --git a/lambda/MAS/Controllers/MailController.cs b/lambda/MAS/Controllers/MailController.cs
index d9ea13a4..5521597e 100644
--- a/lambda/MAS/Controllers/MailController.cs
+++ b/lambda/MAS/Controllers/MailController.cs
@@ -25,7 +25,7 @@ public async Task PutMailAsync()
{
var items = await _contentService.GetItemsAsync();
- var body = _mailService.CreateEmailBody(items);
+ var body = _mailService.CreateDailyEmailBody(items);
var subject = "MAS Email";
var previewText = "This MAS email was created " + DateTime.Now.ToShortDateString();
diff --git a/lambda/MAS/Models/DailyEmail.cs b/lambda/MAS/Models/DailyEmail.cs
new file mode 100644
index 00000000..1eb8d1eb
--- /dev/null
+++ b/lambda/MAS/Models/DailyEmail.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MAS.Models
+{
+ public class DailyEmail
+ {
+ public List- Items { get; set; }
+
+ public List> GroupedItems
+ {
+ get
+ {
+ return Items.GroupBy(x => x.EvidenceType.Title).ToList();
+ }
+ }
+
+
+ public string HTML
+ {
+ get
+ {
+ var body = new StringBuilder();
+
+ foreach (var group in GroupedItems)
+ {
+ var evidenceType = group.Key;
+
+ body.Append("
");
+ body.Append("
" + evidenceType + "");
+
+ foreach(var item in group)
+ {
+ body.Append("
");
+ body.Append(item.Title);
+ body.Append("
");
+ body.Append(item.Source.Title);
+ body.Append("
");
+ body.Append(String.Join(" | ", item.Speciality.Select(x => x.Title)));
+ body.Append("
");
+ body.Append(item.ShortSummary);
+ body.Append("
");
+ body.Append("
SPS Comment");
+ body.Append("
");
+ }
+
+ body.Append("
");
+ }
+
+ return body.ToString();
+ }
+ }
+ }
+}
diff --git a/lambda/MAS/Models/Item.cs b/lambda/MAS/Models/Item.cs
index a0d21231..3a938465 100644
--- a/lambda/MAS/Models/Item.cs
+++ b/lambda/MAS/Models/Item.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
+using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
namespace MAS.Models
@@ -7,14 +8,18 @@ public class Item
{
[JsonProperty("_id"), Required, JsonRequired]
public string Id { get; set; }
+ [JsonProperty("slug")]
+ public string Slug { get; set; }
[Required, JsonRequired]
public string Title { get; set; }
[Required, JsonRequired]
public Source Source { get; set; }
[Required, JsonRequired]
public EvidenceType EvidenceType { get; set; }
+ [JsonProperty("speciality")]
+ public List Speciality { get; set; }
public string ShortSummary { get; set; }
- public string UKMiComment { get; set; }
+ public string Comment { get; set; }
public string ResourceLinks { get; set; }
}
}
diff --git a/lambda/MAS/Models/Speciality.cs b/lambda/MAS/Models/Speciality.cs
new file mode 100644
index 00000000..37b04f15
--- /dev/null
+++ b/lambda/MAS/Models/Speciality.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace MAS.Models
+{
+ public class Speciality
+ {
+ public string Title { get; set; }
+
+ public string Key { get; set; }
+ }
+}
diff --git a/lambda/MAS/Services/MailService.cs b/lambda/MAS/Services/MailService.cs
index e495acf0..3ae0b1c1 100644
--- a/lambda/MAS/Services/MailService.cs
+++ b/lambda/MAS/Services/MailService.cs
@@ -9,13 +9,14 @@
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
+using System.Linq;
namespace MAS.Services
{
public interface IMailService
{
Task CreateAndSendCampaignAsync(string subject, string previewText, string body);
- string CreateEmailBody(IEnumerable- item);
+ string CreateDailyEmailBody(IEnumerable
- item);
}
public class MailService: IMailService
@@ -74,21 +75,10 @@ public async Task CreateAndSendCampaignAsync(string subject, string prev
}
- public string CreateEmailBody(IEnumerable
- items)
+ public string CreateDailyEmailBody(IEnumerable
- items)
{
- var body = new StringBuilder();
-
- foreach (var item in items)
- {
- body.Append(item.Source.Title);
- body.Append("
");
- body.Append(item.Title);
- body.Append("
");
- body.Append(item.ShortSummary);
- body.Append("
");
- }
-
- return body.ToString();
+ var dailyEmail = new DailyEmail() { Items = items.ToList() };
+ return dailyEmail.HTML;
}
}
}
diff --git a/lambda/MAS/Services/S3Service.cs b/lambda/MAS/Services/S3Service.cs
index 6459eeb3..110314f7 100644
--- a/lambda/MAS/Services/S3Service.cs
+++ b/lambda/MAS/Services/S3Service.cs
@@ -67,7 +67,7 @@ private string CreateContentBody(Item item)
contentBody.Append(Environment.NewLine);
contentBody.Append("UKMI Comment: ");
- contentBody.Append(item.UKMiComment);
+ contentBody.Append(item.Comment);
contentBody.Append(Environment.NewLine);
if (item.ResourceLinks != null)