public async Task <List <ValidationResult> > ValidateUpdateRequest(UpdateGlossaryTermRequest request, int termId) { var result = new List <ValidationResult>(); if (request == null) { result.Add(new ValidationResult("Bad request.")); return(result); } if (string.IsNullOrEmpty(request.Definition)) { result.Add(new ValidationResult("Bad request.")); return(result); } GlossaryTerm glossaryTerm = await _dataRepository.Get(termId); if (glossaryTerm == null) { result.Add(new ValidationResult("The term record couldn't be found.")); } return(result); }
protected void Save_OnClick(object sender, EventArgs e) { if (selectedItem == null) { selectedItem = GlossaryTermsMapper.CreateObject(); } else { selectedItem = BaseMapper.GetObjectFromContext <GlossaryTerm>(selectedItem); } UpdateObjectFromFields(); Return returnObj; if (selectedItem.ID == 0) { returnObj = GlossaryTermsMapper.Insert(selectedItem); } else { returnObj = GlossaryTermsMapper.Update(selectedItem); } if (returnObj.IsError) { DisplayErrorMessage("Error Saving Item", returnObj.Error); } else { UpdateFieldsFromObject(); DisplaySuccessMessage("Successfully Saved Item"); } }
public async Task <List <ValidationResult> > ValidateCreateRequest(CreateGlossaryTermRequest request) { var result = new List <ValidationResult>(); if (request == null) { result.Add(new ValidationResult("Bad request.")); return(result); } if (string.IsNullOrEmpty(request.Term)) { result.Add(new ValidationResult("Term can not be empty.")); return(result); } GlossaryTerm glossaryTerm = await _dataRepository.FindByIdTerm(request.Term); if (glossaryTerm != null) { result.Add(new ValidationResult("The term already exists.")); } return(result); }
public async Task CreateGlossaryTerm(CreateGlossaryTermRequest request) { var term = new GlossaryTerm { Term = request.Term, Definition = request.Definition }; await _dataRepository.Add(term); }
public async Task <IActionResult> Get(string term) { GlossaryTerm glossaryTerm = await _termService.FindByIdTerm(term); if (glossaryTerm == null) { return(NotFound("The glossary term record couldn't be found.")); } return(Ok(glossaryTerm)); }
public async void GetByNameTerms() { Mock <ITermsQueryService> termsQueryService = new Mock <ITermsQueryService>(); TermsController controller = new TermsController(NullLogger <TermsController> .Instance, termsQueryService.Object); GlossaryTerm glossaryTerm = new GlossaryTerm() { TermId = 44771, Language = "en", Dictionary = "Cancer.gov", Audience = AudienceType.Patient, TermName = "S-phase fraction", FirstLetter = "s", PrettyUrlName = "s-phase-fraction", Definition = new Definition() { Text = "A measure of the percentage of cells in a tumor that are in the phase of the cell cycle during which DNA is synthesized. The S-phase fraction may be used with the proliferative index to give a more complete understanding of how fast a tumor is growing.", Html = "A measure of the percentage of cells in a tumor that are in the phase of the cell cycle during which DNA is synthesized. The S-phase fraction may be used with the proliferative index to give a more complete understanding of how fast a tumor is growing." }, Pronunciation = new Pronunciation() { Key = "(... fayz FRAK-shun)", Audio = "https://nci-media-dev.cancer.gov/audio/pdq/705947.mp3" }, Media = new IMedia[] {}, RelatedResources = new IRelatedResource[] { } }; termsQueryService.Setup( termQSvc => termQSvc.GetByName( It.IsAny <string>(), It.IsAny <AudienceType>(), It.IsAny <string>(), It.IsAny <string>() ) ) .Returns(Task.FromResult(glossaryTerm)); GlossaryTerm term = await controller.GetByName("Cancer.gov", AudienceType.Patient, "en", "s-phase-fraction"); JObject actual = JObject.Parse(JsonConvert.SerializeObject(term)); JObject expected = JObject.Parse(File.ReadAllText(TestingTools.GetPathToTestFile("TermsControllerData/TestData_GetByName.json"))); // Verify that the service layer is called: // a) with the expected values. // b) exactly once. termsQueryService.Verify( svc => svc.GetByName("cancer.gov", AudienceType.Patient, "en", "s-phase-fraction"), Times.Once ); Assert.Equal(glossaryTerm, term, new GlossaryTermComparer()); Assert.Equal(expected, actual, new JTokenEqualityComparer()); }
public async Task <int> Create(GlossaryTerm glossaryTerm) { var newEnitity = _glossaryDBContext.GlossaryTerms.Add(new GlossaryTerm() { Term = glossaryTerm.Term, Definition = glossaryTerm.Definition }); await _glossaryDBContext.SaveChangesAsync(); return(newEnitity.Entity.Id); }
public async Task DeleteGlossaryTerm(int id) { GlossaryTerm glossaryTerm = await _dataRepository.Get(id); if (glossaryTerm == null) { throw new Exception("The term record couldn't be found."); } await _dataRepository.Delete(glossaryTerm); }
public async Task UpdateGlossaryTerm(UpdateGlossaryTermRequest request, int termId) { GlossaryTerm glossaryTermToUpdate = await _dataRepository.Get(termId); var glossaryTerm = new GlossaryTerm { Definition = request.Definition }; await _dataRepository.Update(glossaryTermToUpdate, glossaryTerm); }
public async Task <int> Save(GlossaryTerm glossaryTerm) { if (glossaryTerm.Id == 0) { return(await _glossaryTermDataManager.Create(glossaryTerm)); } else { await _glossaryTermDataManager.Update(glossaryTerm); } return(glossaryTerm.Id); }
public async void GetByName_WithFallback_TermsPatient_NotTitleCase() { Mock <ITermsQueryService> termQueryService = new Mock <ITermsQueryService>(); GlossaryTerm glossaryTerm = new GlossaryTerm() { TermId = 44771, Language = "en", Dictionary = "Cancer.gov", Audience = AudienceType.Patient, TermName = "S-phase fraction", FirstLetter = "s", PrettyUrlName = "s-phase-fraction", Definition = new Definition() { Text = "A measure of the percentage of cells in a tumor that are in the phase of the cell cycle during which DNA is synthesized. The S-phase fraction may be used with the proliferative index to give a more complete understanding of how fast a tumor is growing.", Html = "A measure of the percentage of cells in a tumor that are in the phase of the cell cycle during which DNA is synthesized. The S-phase fraction may be used with the proliferative index to give a more complete understanding of how fast a tumor is growing." }, Pronunciation = new Pronunciation() { Key = "(... fayz FRAK-shun)", Audio = "https://nci-media-dev.cancer.gov/audio/pdq/705947.mp3" }, Media = new IMedia[] { }, RelatedResources = new IRelatedResource[] { } }; // "cancer.gov" (not the requested "Cancer.gov") and Patient would be the only call to the terms query service, returning the term. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "cancer.gov"), It.Is <AudienceType>(audience => audience == AudienceType.Patient), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction") ) ) .Returns(Task.FromResult(glossaryTerm)); TermsController controller = new TermsController(NullLogger <TermsController> .Instance, termQueryService.Object); GlossaryTerm gsTerm = await controller.GetByName("Cancer.gov", AudienceType.Patient, "en", "s-phase-fraction", true); // Verify that the expected and actual Term are the same. JObject actual = JObject.Parse(JsonConvert.SerializeObject(gsTerm)); JObject expected = JObject.Parse(File.ReadAllText(TestingTools.GetPathToTestFile("TermsControllerData/TestData_GetWithFallback_TermsPatient.json"))); Assert.Equal(expected, actual, new JTokenEqualityComparer()); // Verify that the service layer is called correctly with the lowercased-dictionary fallback combination: termQueryService.Verify( svc => svc.GetByName("cancer.gov", AudienceType.Patient, "en", "s-phase-fraction"), Times.Once ); }
public async void GetBestBetForDisplay_DataLoading(BaseTermQueryTestData data) { IElasticClient client = GetElasticClientWithData(data); // Setup the mocked Options IOptions <GlossaryAPIOptions> gTermClientOptions = GetMockOptions(); ESTermQueryService termClient = new ESTermQueryService(client, gTermClientOptions, new NullLogger <ESTermQueryService>()); GlossaryTerm glossaryTerm = await termClient.GetById("cancer.gov", AudienceType.Patient, "en", 43966L, new string[] {}); Assert.Equal(data.ExpectedData, glossaryTerm, new GlossaryTermComparer()); }
public async void GetByName_DataLoading(GetByNameTermsQueryTestData data) { IElasticClient client = GetByName_GetElasticClientWithData(data.PrettyUrlName); // Setup the mocked Options IOptions <GlossaryAPIOptions> gTermsClientOptions = GetMockOptions(); ESTermsQueryService termsClient = new ESTermsQueryService(client, gTermsClientOptions, new NullLogger <ESTermsQueryService>()); GlossaryTerm glossaryTerm = await termsClient.GetByName("Cancer.gov", AudienceType.Patient, "en", "s-1"); Assert.Equal(data.ExpectedData, glossaryTerm, new GlossaryTermComparer()); }
public void Test_CanDeleteGlossaryTerm() { //Arrange var term = new GlossaryTerm { TermId = 1, Term = "term 1", Definition = "Definition here" }; _termRepository.Setup(t => t.Get(It.IsAny <int>())).ReturnsAsync(term); // Act var result = _glossaryTermService.DeleteGlossaryTerm(1); // Assert _termRepository.Verify(r => r.Get(It.Is <int>(t => t == 1)), Times.Once); _termRepository.Verify(r => r.Delete(It.IsAny <GlossaryTerm>()), Times.Once); }
protected void Page_Load(object sender, EventArgs e) { long id; if (long.TryParse(Request["id"], out id)) { selectedItem = GlossaryTermsMapper.GetByID(id); if (!IsPostBack) { UpdateFieldsFromObject(); } } this.Page.Title = this.SectionTitle.Text = GetSectionTitle(); }
public async void GetByIdForGlossaryTerm(BaseTermQueryTestData data) { Uri esURI = null; ElasticsearchInterceptingConnection conn = new ElasticsearchInterceptingConnection(); conn.RegisterRequestHandlerForType <Nest.GetResponse <GlossaryTerm> >((req, res) => { //Get the file name for this round res.Stream = TestingTools.GetTestFileAsStream("ESTermQueryData/" + data.ESTermID + ".json"); res.StatusCode = 200; esURI = req.Uri; }); //While this has a URI, it does not matter, an InMemoryConnection never requests //from the server. var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); var connectionSettings = new ConnectionSettings(pool, conn); IElasticClient client = new ElasticClient(connectionSettings); // Setup the mocked Options IOptions <GlossaryAPIOptions> gTermClientOptions = GetMockOptions(); ESTermQueryService termClient = new ESTermQueryService(client, gTermClientOptions, new NullLogger <ESTermQueryService>()); // We don't actually care that this returns anything - only that the intercepting connection // sets up the request URI correctly. GlossaryTerm actDisplay = await termClient.GetById( data.DictionaryName, data.Audience, data.Language, data.TermID, new string[] {} ); Assert.Equal( esURI.Segments, new string[] { "/", "glossaryv1/", "terms/", data.ESTermID }, new ArrayComparer() ); }
/// <summary> /// Handles requests to view glossary term popup links when JS is turned off in the browser - mainly /// occurs when the site is being indexed, and we want to reduce the number of 404s that occur from this. /// If the term exists in a dictionary we have on Cancer.gov, we redirect to that term definition page. /// If it does not, we display the term and definition. /// <summary> public void ProcessRequest(HttpContext context) { HttpRequest request = context.Request; // Parse search params for API call ParseSearchParams(request); GlossaryAPIClient client = new GlossaryAPIClient(); // Perform API request for glossary term GlossaryTerm term = client.GetById(_dictionary, _audience, _language, _id, _useFallback); // If glossary term for given CDRID does not exist, return a 404. if (term == null) { throw new HttpException(404, String.Format("Term with CDRID {0} does not exist", _id)); } // If glossary term does exist, determine whether to redirect or draw the term and definition. else { string termForRedirect = String.IsNullOrEmpty(term.PrettyUrlName) ? term.TermId : term.PrettyUrlName; string dictionaryPath = GetDictionaryPath(term.Dictionary, term.Audience.ToString(), term.Language); // If the term's dictionary exists on Cancer.gov AND the requested dictionary, audience, and language match the returned term's // dictionary, audience, and language, redirect to the term definition page with that dictionary path. if ( !string.IsNullOrWhiteSpace(dictionaryPath) && _dictionary.ToLower() == term.Dictionary.ToLower() && _audience.ToLower() == term.Audience.ToString().ToLower() && _language.ToLower() == term.Language.ToLower() ) { context.Response.RedirectPermanent($"{dictionaryPath}/def/{termForRedirect}"); } // If the term's dictionary does not exist on Cancer.gov or the requesed dictionary, audience, and language do not match the // returned term's dictionary, audience, and language, draw the term and definition. else { context.Response.Write(GetTermDefinitionHTML(term)); } } }
public string DeleteItemPermanently(long id) { GlossaryTerm item = BaseMapper.GetObjectFromContext(GlossaryTermsMapper.GetByID(id)); if (item != null) { Return returnObj = GlossaryTermsMapper.DeletePermanently(item); if (returnObj.IsError) { return(jGrowlHelper.GenerateCode(new jGrowlMessage("Error", "Error deleting item permanently", jGrowlMessage.jGrowlMessageType.Error, returnObj.Error), true)); } else { return(jGrowlHelper.GenerateCode(new jGrowlMessage("Success", "Item was successfully deleted permanently", jGrowlMessage.jGrowlMessageType.Success), false)); } } return(""); }
public async Task <ListResult> Delete(GlossaryTerm glossaryTerm) { try { await _glossaryTermDomainManager.Delete(glossaryTerm); return(await Task.FromResult(new ListResult() { Message = "Term deleted successfully", Success = true })); } catch (Exception ex) { return(new ListResult() { Message = ex.Message, Success = false }); } }
public async void GetByName_WithFallback_GeneticsHP() { Mock <ITermsQueryService> termQueryService = new Mock <ITermsQueryService>(); GlossaryTerm glossaryTerm = new GlossaryTerm { TermId = 556486, Language = "en", Dictionary = "Genetics", Audience = AudienceType.HealthProfessional, TermName = "deleterious mutation", FirstLetter = "d", PrettyUrlName = "deleterious-mutation", Pronunciation = new Pronunciation() { Key = "(DEH-leh-TEER-ee-us myoo-TAY-shun)", Audio = "https://nci-media-dev.cancer.gov/pdq/media/audio/736913.mp3" }, Definition = new Definition() { Html = "A genetic alteration that increases an individual’s susceptibility or predisposition to a certain disease or disorder. When such a variant (or mutation) is inherited, development of symptoms is more likely, but not certain. Also called disease-causing mutation, pathogenic variant, predisposing mutation, and susceptibility gene mutation.", Text = "A genetic alteration that increases an individual’s susceptibility or predisposition to a certain disease or disorder. When such a variant (or mutation) is inherited, development of symptoms is more likely, but not certain. Also called disease-causing mutation, pathogenic variant, predisposing mutation, and susceptibility gene mutation." }, RelatedResources = new IRelatedResource[] {}, Media = new IMedia[] {} }; int callOrder = 0; // Cancer.gov and HealthProfessional would be the first call to the terms query service, returning nothing. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "cancer.gov"), It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation") ) ) .Callback(() => Assert.Equal(1, callOrder++)) .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'cancer.gov', audience 'HealthProfessional', language 'en', pretty URL name 'deleterious-mutation'.")); // Cancer.gov and Patient would be the second call to the terms query service, returning nothing. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "cancer.gov"), It.Is <AudienceType>(audience => audience == AudienceType.Patient), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation") ) ) .Callback(() => Assert.Equal(2, callOrder++)) .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'cancer.gov', audience 'Patient', language 'en', pretty URL name 'deleterious-mutation'.")); // NotSet and HealthProfessional would be the third call to the terms query service, returning nothing. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "notset"), It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation") ) ) .Callback(() => Assert.Equal(3, callOrder++)) .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'notset', audience 'HealthProfessional', language 'en', pretty URL name 'deleterious-mutation'.")); // NotSet and Patient would be the fourth call to the terms query service, returning nothing. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "notset"), It.Is <AudienceType>(audience => audience == AudienceType.Patient), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation") ) ) .Callback(() => Assert.Equal(4, callOrder++)) .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'notset', audience 'Patient', language 'en', pretty URL name 'deleterious-mutation'.")); // Genetics and HealthProfessional would be the last call to the terms query service, returning the term. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "genetics"), It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "deleterious-mutation") ) ) .Returns(Task.FromResult(glossaryTerm)); TermsController controller = new TermsController(NullLogger <TermsController> .Instance, termQueryService.Object); GlossaryTerm gsTerm = await controller.GetByName("Cancer.gov", AudienceType.HealthProfessional, "en", "deleterious-mutation", true); // Verify that the expected and actual Term are the same. JObject actual = JObject.Parse(JsonConvert.SerializeObject(gsTerm)); JObject expected = JObject.Parse(File.ReadAllText(TestingTools.GetPathToTestFile("TermsControllerData/TestData_GetWithFallback_GeneticsHP.json"))); Assert.Equal(expected, actual, new JTokenEqualityComparer()); // Verify that the service layer is called correctly with the fallback logic: // 1) Cancer.gov, HealthProfessional termQueryService.Verify( svc => svc.GetByName("cancer.gov", AudienceType.HealthProfessional, "en", "deleterious-mutation"), Times.Once ); // 2) Cancer.gov, Patient termQueryService.Verify( svc => svc.GetByName("cancer.gov", AudienceType.Patient, "en", "deleterious-mutation"), Times.Once ); // 3) Empty dictionary, HealthProfessional termQueryService.Verify( svc => svc.GetByName("notset", AudienceType.HealthProfessional, "en", "deleterious-mutation"), Times.Once ); // 4) Empty dictionary, Patient termQueryService.Verify( svc => svc.GetByName("notset", AudienceType.Patient, "en", "deleterious-mutation"), Times.Once ); // 5) Genetics, HealthProfessional termQueryService.Verify( svc => svc.GetByName("genetics", AudienceType.HealthProfessional, "en", "deleterious-mutation"), Times.Once ); }
/// <summary> /// This temporary method will create a GlossaryTerm /// object to testing purpose. /// </summary> /// <returns>The GlossaryTerm</returns> private GlossaryTerm GenerateSampleTerm(string[] requestedFields) { GlossaryTerm _GlossaryTerm = new GlossaryTerm(); Pronunciation pronunciation = new Pronunciation("Pronunciation Key", "pronunciation"); Definition definition = new Definition("<html><h1>Definition</h1></html>", "Sample definition"); _GlossaryTerm.TermId = 7890L; _GlossaryTerm.Language = "EN"; _GlossaryTerm.Dictionary = "Dictionary"; _GlossaryTerm.Audience = AudienceType.Patient; _GlossaryTerm.TermName = "TermName"; _GlossaryTerm.PrettyUrlName = "www.glossary-api.com"; _GlossaryTerm.Pronunciation = pronunciation; _GlossaryTerm.Definition = definition; foreach (string field in requestedFields) { if (field.Equals("Id")) { _GlossaryTerm.TermId = 1234L; } else if (field.Equals("Language", StringComparison.InvariantCultureIgnoreCase)) { _GlossaryTerm.Language = "EN"; } else if (field.Equals("Dictionary", StringComparison.InvariantCultureIgnoreCase)) { _GlossaryTerm.Dictionary = "Dictionary"; } else if (field.Equals("Audience", StringComparison.InvariantCultureIgnoreCase)) { _GlossaryTerm.Audience = AudienceType.Patient; } else if (field.Equals("TermName", StringComparison.InvariantCultureIgnoreCase)) { _GlossaryTerm.TermName = "TermName"; } else if (field.Equals("PrettyUrlName", StringComparison.InvariantCultureIgnoreCase)) { _GlossaryTerm.PrettyUrlName = "www.glossary-api.com"; } else if (field.Equals("Pronunciation", StringComparison.InvariantCultureIgnoreCase)) { _GlossaryTerm.Pronunciation = pronunciation; } else if (field.Equals("Definition", StringComparison.InvariantCultureIgnoreCase)) { _GlossaryTerm.Definition = definition; } } _GlossaryTerm.RelatedResources = new IRelatedResource[] { new LinkResource() { Type = RelatedResourceType.External, Text = "Link to Google", Url = new System.Uri("https://www.google.com") }, new LinkResource() { Type = RelatedResourceType.DrugSummary, Text = "Bevacizumab", Url = new System.Uri("https://www.cancer.gov/about-cancer/treatment/drugs/bevacizumab") }, new LinkResource() { Type = RelatedResourceType.Summary, Text = "Lung cancer treatment", Url = new System.Uri("https://www.cancer.gov/types/lung/patient/small-cell-lung-treatment-pdq") }, new GlossaryResource() { Type = RelatedResourceType.GlossaryTerm, Text = "stage II cutaneous T-cell lymphoma", TermId = 43966, Audience = AudienceType.Patient, PrettyUrlName = "stage-ii-cutaneous-t-cell-lymphoma" } }; return(_GlossaryTerm); }
public async void GetById() { Mock <ITermQueryService> termQueryService = new Mock <ITermQueryService>(); string[] requestedFields = { "TermName", "Pronunciation", "Definition" }; Pronunciation pronunciation = new Pronunciation("Pronunciation Key", "pronunciation"); Definition definition = new Definition("<html><h1>Definition</h1></html>", "Sample definition"); GlossaryTerm glossaryTerm = new GlossaryTerm { TermId = 1234L, Language = "EN", Dictionary = "Dictionary", Audience = AudienceType.Patient, TermName = "TermName", FirstLetter = "t", PrettyUrlName = "www.glossary-api.com", Pronunciation = pronunciation, Definition = definition, RelatedResources = new IRelatedResource[] { new LinkResource() { Type = RelatedResourceType.External, Text = "Link to Google", Url = new System.Uri("https://www.google.com") }, new LinkResource() { Type = RelatedResourceType.DrugSummary, Text = "Bevacizumab", Url = new System.Uri("https://www.cancer.gov/about-cancer/treatment/drugs/bevacizumab") }, new LinkResource() { Type = RelatedResourceType.Summary, Text = "Lung cancer treatment", Url = new System.Uri("https://www.cancer.gov/types/lung/patient/small-cell-lung-treatment-pdq") }, new GlossaryResource() { Type = RelatedResourceType.GlossaryTerm, Text = "stage II cutaneous T-cell lymphoma", TermId = 43966, Audience = AudienceType.Patient, PrettyUrlName = "stage-ii-cutaneous-t-cell-lymphoma" } } }; termQueryService.Setup( termQSvc => termQSvc.GetById( It.IsAny <String>(), It.IsAny <AudienceType>(), It.IsAny <string>(), It.IsAny <long>(), It.IsAny <string[]>() ) ) .Returns(Task.FromResult(glossaryTerm)); TermController controller = new TermController(termQueryService.Object); GlossaryTerm gsTerm = await controller.GetById("Dictionary", AudienceType.Patient, "EN", 1234L, requestedFields); string actualJsonValue = JsonConvert.SerializeObject(gsTerm); string expectedJsonValue = File.ReadAllText(TestingTools.GetPathToTestFile("TestData.json")); // Verify that the service layer is called: // a) with the expected values. // b) exactly once. termQueryService.Verify( svc => svc.GetById("Dictionary", AudienceType.Patient, "EN", 1234L, new string[] { "TermName", "Pronunciation", "Definition" }), Times.Once ); Assert.Equal(expectedJsonValue, actualJsonValue); }
private string GetTermDefinitionHTML(GlossaryTerm term) { string html = @" <!DOCTYPE html> <html lang=""" + term.Language + @"""> <head> <title>Definition of " + term.TermName + @"</title> <meta name=""robots"" content=""noindex, nofollow"" /> <style> @import url(""https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap""); .definition { font-family: ""Noto Sans""; margin: 30px 15px; } .definition__header { margin-bottom: 15px; } .definition h1 { font-size: 16px; font-weight: 700; display: inline-block; } .definition dd { margin: 0; } .definition dd +* { margin - top: 15px; } </style> </head>"; html += @" <body> <div class=""definition""> <dl> <div class=""definition__header""> <a href=""/"" id=""logoAnchor""> <img src=""https://www.cancer.gov/publishedcontent/images/images/design-elements/logos/nci-logo-full.svg"" id=""logoImage"" alt=""National Cancer Institute"" width=""300"" /> </a> </div> <dt> <h1>" + term.TermName + @"</h1>"; if (term.Pronunciation != null && term.Pronunciation.Key != null) { html += @" <span class=""pronunciation"">" + term.Pronunciation.Key + @"</span>"; } html += @" </dt>"; if (term.Definition != null && term.Definition.Text != null) { html += @" <dd>" + term.Definition.Text + @"</dd>"; } html += @" </dl> </div> </body>"; html += @" </html>"; return(html); }
private void SetGlossaryTerm(GlossaryTerm value) { glossaryTerm = value; }
public async Task Delete(GlossaryTerm glossaryTerm) { _glossaryDBContext.GlossaryTerms.Remove(glossaryTerm); await _glossaryDBContext.SaveChangesAsync(); }
public async Task Update(GlossaryTerm glossaryTerm) { _glossaryDBContext.GlossaryTerms.Update(glossaryTerm); await _glossaryDBContext.SaveChangesAsync(); }
public async void GetByName_WithFallback_TermsPatient() { Mock <ITermsQueryService> termQueryService = new Mock <ITermsQueryService>(); GlossaryTerm glossaryTerm = new GlossaryTerm() { TermId = 44771, Language = "en", Dictionary = "Cancer.gov", Audience = AudienceType.Patient, TermName = "S-phase fraction", FirstLetter = "s", PrettyUrlName = "s-phase-fraction", Definition = new Definition() { Text = "A measure of the percentage of cells in a tumor that are in the phase of the cell cycle during which DNA is synthesized. The S-phase fraction may be used with the proliferative index to give a more complete understanding of how fast a tumor is growing.", Html = "A measure of the percentage of cells in a tumor that are in the phase of the cell cycle during which DNA is synthesized. The S-phase fraction may be used with the proliferative index to give a more complete understanding of how fast a tumor is growing." }, Pronunciation = new Pronunciation() { Key = "(... fayz FRAK-shun)", Audio = "https://nci-media-dev.cancer.gov/audio/pdq/705947.mp3" }, Media = new IMedia[] {}, RelatedResources = new IRelatedResource[] { } }; int callOrder = 0; // NotSet and Patient would be the first call to the terms query service, returning nothing. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "notset"), It.Is <AudienceType>(audience => audience == AudienceType.Patient), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction") ) ) .Callback(() => Assert.Equal(1, callOrder++)) .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'notset', audience 'Patient', language 'en', pretty URL name 's-phase-fraction'.")); // NotSet and HealthProfessional would be the second call to the terms query service, returning nothing. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "notset"), It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction") ) ) .Callback(() => Assert.Equal(2, callOrder++)) .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'notset', audience 'HealthProfessional', language 'en', pretty URL name 's-phase-fraction'.")); // Genetics and Patient would be the third call to the terms query service, returning nothing. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "genetics"), It.Is <AudienceType>(audience => audience == AudienceType.Patient), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction") ) ) .Callback(() => Assert.Equal(3, callOrder++)) .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'genetics', audience 'Patient', language 'en', pretty URL name 's-phase-fraction'.")); // Genetics and HealthProfessional would be the fourth call to the terms query service, returning nothing. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "genetics"), It.Is <AudienceType>(audience => audience == AudienceType.HealthProfessional), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction") ) ) .Callback(() => Assert.Equal(4, callOrder++)) .Throws(new APIErrorException(200, "Empty response when searching for dictionary 'genetics', audience 'HealthProfessional', language 'en', pretty URL name 's-phase-fraction'.")); // Cancer.gov and Patient would be the last call to the terms query service, returning the term. termQueryService.Setup( termQSvc => termQSvc.GetByName( It.Is <String>(dictionary => dictionary == "cancer.gov"), It.Is <AudienceType>(audience => audience == AudienceType.Patient), It.Is <string>(language => language == "en"), It.Is <string>(prettyUrlName => prettyUrlName == "s-phase-fraction") ) ) .Returns(Task.FromResult(glossaryTerm)); TermsController controller = new TermsController(NullLogger <TermsController> .Instance, termQueryService.Object); GlossaryTerm gsTerm = await controller.GetByName("NotSet", AudienceType.Patient, "en", "s-phase-fraction", true); // Verify that the expected and actual Term are the same. JObject actual = JObject.Parse(JsonConvert.SerializeObject(gsTerm)); JObject expected = JObject.Parse(File.ReadAllText(TestingTools.GetPathToTestFile("TermsControllerData/TestData_GetWithFallback_TermsPatient.json"))); Assert.Equal(expected, actual, new JTokenEqualityComparer()); // Verify that the service layer is called correctly with the fallback logic: // 1) Empty dictionary, Patient termQueryService.Verify( svc => svc.GetByName("notset", AudienceType.Patient, "en", "s-phase-fraction"), Times.Once ); // 2) Empty dictionary, HealthProfessional termQueryService.Verify( svc => svc.GetByName("notset", AudienceType.HealthProfessional, "en", "s-phase-fraction"), Times.Once ); // 3) Genetics, Patient termQueryService.Verify( svc => svc.GetByName("genetics", AudienceType.Patient, "en", "s-phase-fraction"), Times.Once ); // 4) Genetics, HealthProfessional termQueryService.Verify( svc => svc.GetByName("genetics", AudienceType.HealthProfessional, "en", "s-phase-fraction"), Times.Once ); // 5) Cancer.gov, Patient termQueryService.Verify( svc => svc.GetByName("cancer.gov", AudienceType.Patient, "en", "s-phase-fraction"), Times.Once ); }
/// <summary> /// Search for Term based on the pretty URL name passed. /// <param name="dictionary">The value for dictionary.</param> /// <param name="audience">Patient or Healthcare provider</param> /// <param name="language">The language in which the details needs to be fetched</param> /// <param name="prettyUrlName">The pretty url name to search for</param> /// <returns>An object of GlossaryTerm</returns> /// </summary> public async Task <GlossaryTerm> GetByName(string dictionary, AudienceType audience, string language, string prettyUrlName) { // Set up the SearchRequest to send to elasticsearch. Indices index = Indices.Index(new string[] { this._apiOptions.AliasName }); Types types = Types.Type(new string[] { "terms" }); SearchRequest request = new SearchRequest(index, types) { Query = new TermQuery { Field = "language", Value = language.ToString() } && new TermQuery { Field = "audience", Value = audience.ToString() } && new TermQuery { Field = "dictionary", Value = dictionary.ToString() } && new TermQuery { Field = "pretty_url_name", Value = prettyUrlName.ToString() } , Sort = new List <ISort> { new SortField { Field = "term_name" } } }; ISearchResponse <GlossaryTerm> response = null; try { response = await _elasticClient.SearchAsync <GlossaryTerm>(request); } catch (Exception ex) { String msg = $"Could not search dictionary '{dictionary}', audience '{audience}', language '{language}', pretty URL name '{prettyUrlName}'."; _logger.LogError($"Error searching index: '{this._apiOptions.AliasName}'."); _logger.LogError(ex, msg); throw new APIErrorException(500, msg); } if (!response.IsValid) { String msg = $"Invalid response when searching for dictionary '{dictionary}', audience '{audience}', language '{language}', pretty URL name '{prettyUrlName}'."; _logger.LogError(msg); throw new APIErrorException(500, "errors occured"); } GlossaryTerm glossaryTerm = new GlossaryTerm(); // If there is only one term in the response, then the search by pretty URL name was successful. if (response.Total == 1) { glossaryTerm = response.Documents.First(); } else if (response.Total == 0) { string msg = $"No match for dictionary '{dictionary}', audience '{audience}', language '{language}', pretty URL name '{prettyUrlName}'."; _logger.LogDebug(msg); throw new APIErrorException(404, msg); } else { string msg = $"Incorrect response when searching for dictionary '{dictionary}', audience '{audience}', language '{language}', pretty URL name '{prettyUrlName}'."; _logger.LogError(msg); throw new APIErrorException(500, "Errors have occured."); } return(glossaryTerm); }
public async Task Delete(GlossaryTerm glossaryTerm) { await _glossaryTermDataManager.Delete(glossaryTerm); }
public async Task Update(GlossaryTerm dbEntity, GlossaryTerm entity) { dbEntity.Definition = entity.Definition; await _flexRuleContext.SaveChangesAsync(); }