diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index b168276c9..754dc6624 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -5,19 +5,22 @@ on: [push] jobs: Golintr: name: Go Lintr - runs-on: macOS-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - name: Install golangci-lint\ - run: brew install golangci-lint + run: sudo snap install golangci-lint --classic + - name: Run Go Lintr run: make lint_go Rlintr: - runs-on: macOS-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - uses: r-lib/actions/setup-r@v2 - + with: + r-version: '4.1.3' + - name: Lint R Files - run: cd ./scripts && ./lintr.sh + run: cd ./scripts && ./lintr.sh \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 118941a1d..5ea53f4a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,14 +4,14 @@ on: [push] jobs: test-unit: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - name: Go Unit Tests id: go-unit-tests run: make test test-integration: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - name: Start System @@ -48,7 +48,7 @@ jobs: id: go-integration-tests run: ./scripts/wait-for-it.sh localhost:5432 -- ./scripts/wait-for-it.sh localhost:15672 -- ./scripts/wait-for-it.sh localhost:5672 -- make test_int test-e2e: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - name: Start System diff --git a/endpointmanager/pkg/chplendpointquerier/aspmdewebscraper.go b/endpointmanager/pkg/chplendpointquerier/aspmdewebscraper.go index 4e0b10cbf..c94d131db 100644 --- a/endpointmanager/pkg/chplendpointquerier/aspmdewebscraper.go +++ b/endpointmanager/pkg/chplendpointquerier/aspmdewebscraper.go @@ -1,13 +1,13 @@ package chplendpointquerier import ( + "strings" + "github.com/PuerkitoBio/goquery" "github.com/onc-healthit/lantern-back-end/endpointmanager/pkg/helpers" - log "github.com/sirupsen/logrus" - "strings" ) -func AspMDeWebscraper(chplURL string, fileToWriteTo string) { +func AspMDeWebscraper(chplURL string, fileToWriteTo string) error { found := false baseURL := strings.TrimSuffix(chplURL, "/fhir_aspmd.asp#apiendpoints") @@ -15,7 +15,7 @@ func AspMDeWebscraper(chplURL string, fileToWriteTo string) { doc, err := helpers.ChromedpQueryEndpointList(chplURL, "p") if err != nil { - log.Fatal(err) + return err } doc.Find("h1").Each(func(i int, s *goquery.Selection) { @@ -35,4 +35,6 @@ func AspMDeWebscraper(chplURL string, fileToWriteTo string) { }) } }) + + return nil } diff --git a/endpointmanager/pkg/chplendpointquerier/chplendpointquerier.go b/endpointmanager/pkg/chplendpointquerier/chplendpointquerier.go index d5b2ef3c9..efad48361 100644 --- a/endpointmanager/pkg/chplendpointquerier/chplendpointquerier.go +++ b/endpointmanager/pkg/chplendpointquerier/chplendpointquerier.go @@ -225,6 +225,8 @@ func contains(arr [30]string, str string) bool { func QueryCHPLEndpointList(chplURL string, fileToWriteTo string) { + var err error + if URLsEqual(chplURL, MedHostURL) { MedHostQuerier(chplURL, fileToWriteTo) } else if URLsEqual(chplURL, NextGenURL) { @@ -543,9 +545,9 @@ func QueryCHPLEndpointList(chplURL string, fileToWriteTo string) { } else if URLsEqual(chplURL, anthemURL) { AnthemURLParser("https://patient360.anthem.com/P360Member/fhir/endpoints", fileToWriteTo) } else if URLsEqual(chplURL, hcscURL) { - HcscURLWebscraper(chplURL, fileToWriteTo) + err = HcscURLWebscraper(chplURL, fileToWriteTo) } else if URLsEqual(chplURL, guidewellPatAccURL) || URLsEqual(chplURL, guidewellP2PURL) { - GuidewellURLWebscraper(chplURL, fileToWriteTo) + err = GuidewellURLWebscraper(chplURL, fileToWriteTo) } else if URLsEqual(chplURL, humanaURL) { HumanaURLWebscraper(chplURL, fileToWriteTo) } else if URLsEqual(chplURL, kaiserURL) { @@ -561,11 +563,11 @@ func QueryCHPLEndpointList(chplURL string, fileToWriteTo string) { } else if URLsEqual(chplURL, nextgenPracticeURL) { NextgenPracticeWebscraper(nextgenPracticeURL, fileToWriteTo) } else if URLsEqual(chplURL, aspmdURL) { - AspMDeWebscraper(aspmdURL, fileToWriteTo) + err = AspMDeWebscraper(aspmdURL, fileToWriteTo) } else if URLsEqual(chplURL, axeiumURL) { AxeiumeWebscraper(axeiumURL, fileToWriteTo) } else if URLsEqual(chplURL, ezemrxURL) { - EzemrxWebscraper(chplURL, fileToWriteTo) + err = EzemrxWebscraper(chplURL, fileToWriteTo) } else if contains(bundleQuerierArray, chplURL) { BundleQuerierParser(chplURL, fileToWriteTo) } else if URLsEqual(chplURL, curemdURL) { @@ -575,9 +577,9 @@ func QueryCHPLEndpointList(chplURL string, fileToWriteTo string) { } else if URLsEqual(chplURL, betaAfoundriaURL) { BetaAfoundriaWebScraper(chplURL, fileToWriteTo) } else if URLsEqual(chplURL, ontadaURL) { - OntadaWebscraper(chplURL, fileToWriteTo) + err = OntadaWebscraper(chplURL, fileToWriteTo) } else if URLsEqual(chplURL, mdlandURL) { - MdlandWebscraper("https://api.mdland.com/Mdland%20SMART%20on%20FHIR%20OAuth%202.0%20Guide.htm", fileToWriteTo) + err = MdlandWebscraper("https://api.mdland.com/Mdland%20SMART%20on%20FHIR%20OAuth%202.0%20Guide.htm", fileToWriteTo) } else if URLsEqual(abeoURL, chplURL) { CustomCSVParser(chplURL, fileToWriteTo, "./FHIRServiceURLs.csv", -1, 0, true, 1, 0) } else if URLsEqual(nextechURL2, chplURL) { @@ -589,6 +591,10 @@ func QueryCHPLEndpointList(chplURL string, fileToWriteTo string) { } else { log.Warnf("Handler is required for url %s", chplURL) } + + if err != nil { + log.Info(err) + } } // WriteCHPLFile writes the given endpointEntryList to a json file and stores it in the prod resources directory diff --git a/endpointmanager/pkg/chplendpointquerier/commomwebscrapers_test.go b/endpointmanager/pkg/chplendpointquerier/commomwebscrapers_test.go index 7b26a832b..13d9a0c34 100644 --- a/endpointmanager/pkg/chplendpointquerier/commomwebscrapers_test.go +++ b/endpointmanager/pkg/chplendpointquerier/commomwebscrapers_test.go @@ -8,7 +8,7 @@ import ( log "github.com/sirupsen/logrus" ) -type WebScraperFunc func(string, string) +type WebScraperFunc func(string, string) error type ScraperTestCase struct { scraperFunc WebScraperFunc @@ -49,19 +49,23 @@ func TestWebScrapers(t *testing.T) { } func runWebScraperTest(t *testing.T, scraperFunc WebScraperFunc, url, fileName string) { - scraperFunc(url, fileName) + err := scraperFunc(url, fileName) - fileExists, err := doesfileExist(fileName) - th.Assert(t, err == nil, err) - th.Assert(t, fileExists, "File does not exist") + if err == nil { + fileExists, err := doesfileExist(fileName) + th.Assert(t, err == nil, err) + th.Assert(t, fileExists, "File does not exist") - fileEmpty, err := isFileEmpty(fileName) - th.Assert(t, err == nil, err) - th.Assert(t, !fileEmpty, "File is empty") + fileEmpty, err := isFileEmpty(fileName) + th.Assert(t, err == nil, err) + th.Assert(t, !fileEmpty, "File is empty") - err = os.Remove("../../../resources/prod_resources/" + fileName) - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/prod_resources/" + fileName) + th.Assert(t, err == nil, err) - err = os.Remove("../../../resources/dev_resources/" + fileName) - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/dev_resources/" + fileName) + th.Assert(t, err == nil, err) + } else { + log.Info(err) + } } diff --git a/endpointmanager/pkg/chplendpointquerier/ezemrxwebscraper.go b/endpointmanager/pkg/chplendpointquerier/ezemrxwebscraper.go index 772f97b3e..42eeca838 100644 --- a/endpointmanager/pkg/chplendpointquerier/ezemrxwebscraper.go +++ b/endpointmanager/pkg/chplendpointquerier/ezemrxwebscraper.go @@ -4,10 +4,9 @@ import ( "strings" "github.com/onc-healthit/lantern-back-end/endpointmanager/pkg/helpers" - log "github.com/sirupsen/logrus" ) -func EzemrxWebscraper(CHPLURL string, fileToWriteTo string) { +func EzemrxWebscraper(CHPLURL string, fileToWriteTo string) error { var lanternEntryList []LanternEntry var endpointEntryList EndpointList @@ -15,7 +14,7 @@ func EzemrxWebscraper(CHPLURL string, fileToWriteTo string) { doc, err := helpers.ChromedpQueryEndpointList(CHPLURL, "#comp-lb6njyhb") if err != nil { - log.Fatal(err) + return err } divElem := doc.Find("#comp-lb6njyhb").First() @@ -32,7 +31,8 @@ func EzemrxWebscraper(CHPLURL string, fileToWriteTo string) { err = WriteCHPLFile(endpointEntryList, fileToWriteTo) if err != nil { - log.Fatal(err) + return err } + return nil } diff --git a/endpointmanager/pkg/chplendpointquerier/guidewellurlwebscraper.go b/endpointmanager/pkg/chplendpointquerier/guidewellurlwebscraper.go index e0b825322..94a5ddbc8 100644 --- a/endpointmanager/pkg/chplendpointquerier/guidewellurlwebscraper.go +++ b/endpointmanager/pkg/chplendpointquerier/guidewellurlwebscraper.go @@ -1,8 +1,6 @@ package chplendpointquerier import ( - "log" - "github.com/PuerkitoBio/goquery" "github.com/onc-healthit/lantern-back-end/endpointmanager/pkg/helpers" ) @@ -16,13 +14,13 @@ func entryExists(lanternEntryList []LanternEntry, lanternEntry LanternEntry) boo return false } -func GuidewellURLWebscraper(CHPLURL string, fileToWriteTo string) { +func GuidewellURLWebscraper(CHPLURL string, fileToWriteTo string) error { var lanternEntryList []LanternEntry var endpointEntryList EndpointList doc, err := helpers.ChromedpQueryEndpointList(CHPLURL, "div.apiEndpointUrl") if err != nil { - log.Fatal(err) + return err } doc.Find("div.apiEndpointUrl").Each(func(index int, urlElements *goquery.Selection) { @@ -38,7 +36,8 @@ func GuidewellURLWebscraper(CHPLURL string, fileToWriteTo string) { endpointEntryList.Endpoints = lanternEntryList err = WriteCHPLFile(endpointEntryList, fileToWriteTo) if err != nil { - log.Fatal(err) + return err } + return nil } diff --git a/endpointmanager/pkg/chplendpointquerier/guidewellurlwebscraper_test.go b/endpointmanager/pkg/chplendpointquerier/guidewellurlwebscraper_test.go index 5f5e6e8ee..cc85641d0 100644 --- a/endpointmanager/pkg/chplendpointquerier/guidewellurlwebscraper_test.go +++ b/endpointmanager/pkg/chplendpointquerier/guidewellurlwebscraper_test.go @@ -5,78 +5,94 @@ import ( "testing" th "github.com/onc-healthit/lantern-back-end/endpointmanager/pkg/testhelper" + log "github.com/sirupsen/logrus" ) func Test_GuidewellURLWebscraper(t *testing.T) { // Patient Access API Test Cases // 1. Happy case: Valid url, valid file format - GuidewellURLWebscraper("https://developer.bcbsfl.com/interop/interop-developer-portal/product/306/api/285#/CMSInteroperabilityPatientAccessMetadata_100/operation/%2FR4%2Fmetadata/get", "TEST_Medicare_GuidewellPatientAccessEndpointSources.json") + err := GuidewellURLWebscraper("https://developer.bcbsfl.com/interop/interop-developer-portal/product/306/api/285#/CMSInteroperabilityPatientAccessMetadata_100/operation/%2FR4%2Fmetadata/get", "TEST_Medicare_GuidewellPatientAccessEndpointSources.json") - fileExists, err := doesfileExist("TEST_Medicare_GuidewellPatientAccessEndpointSources.json") - th.Assert(t, err == nil, err) - th.Assert(t, fileExists, "JSON file does not exist") + if err == nil { + fileExists, err := doesfileExist("TEST_Medicare_GuidewellPatientAccessEndpointSources.json") + th.Assert(t, err == nil, err) + th.Assert(t, fileExists, "JSON file does not exist") - fileEmpty, err := isFileEmpty("TEST_Medicare_GuidewellPatientAccessEndpointSources.json") - th.Assert(t, err == nil, err) - th.Assert(t, !fileEmpty, "Empty JSON file") + fileEmpty, err := isFileEmpty("TEST_Medicare_GuidewellPatientAccessEndpointSources.json") + th.Assert(t, err == nil, err) + th.Assert(t, !fileEmpty, "Empty JSON file") - err = os.Remove("../../../resources/prod_resources/TEST_Medicare_GuidewellPatientAccessEndpointSources.json") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/prod_resources/TEST_Medicare_GuidewellPatientAccessEndpointSources.json") + th.Assert(t, err == nil, err) - err = os.Remove("../../../resources/dev_resources/TEST_Medicare_GuidewellPatientAccessEndpointSources.json") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/dev_resources/TEST_Medicare_GuidewellPatientAccessEndpointSources.json") + th.Assert(t, err == nil, err) + } else { + log.Info(err) + } // 2. Different file format - GuidewellURLWebscraper("https://developer.bcbsfl.com/interop/interop-developer-portal/product/306/api/285#/CMSInteroperabilityPatientAccessMetadata_100/operation/%2FR4%2Fmetadata/get", "TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") + err = GuidewellURLWebscraper("https://developer.bcbsfl.com/interop/interop-developer-portal/product/306/api/285#/CMSInteroperabilityPatientAccessMetadata_100/operation/%2FR4%2Fmetadata/get", "TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") - fileExists, err = doesfileExist("TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") - th.Assert(t, err == nil, err) - th.Assert(t, fileExists, "CSV file does not exist") + if err == nil { + fileExists, err := doesfileExist("TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") + th.Assert(t, err == nil, err) + th.Assert(t, fileExists, "CSV file does not exist") - fileEmpty, err = isFileEmpty("TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") - th.Assert(t, err == nil, err) - th.Assert(t, !fileEmpty, "Empty CSV file") + fileEmpty, err := isFileEmpty("TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") + th.Assert(t, err == nil, err) + th.Assert(t, !fileEmpty, "Empty CSV file") - err = os.Remove("../../../resources/prod_resources/TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/prod_resources/TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") + th.Assert(t, err == nil, err) - err = os.Remove("../../../resources/dev_resources/TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/dev_resources/TEST_Medicare_GuidewellPatientAccessEndpointSources.csv") + th.Assert(t, err == nil, err) + } else { + log.Info(err) + } // Payer2Payer API Test Cases // 1. Happy case: Valid url, valid file format - GuidewellURLWebscraper("https://developer.bcbsfl.com/interop/interop-developer-portal/product/309/api/288#/CMSInteroperabilityPayer2PayerOutboundMetadata_100/operation/%2FP2P%2FR4%2Fmetadata/get", "TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") + err = GuidewellURLWebscraper("https://developer.bcbsfl.com/interop/interop-developer-portal/product/309/api/288#/CMSInteroperabilityPayer2PayerOutboundMetadata_100/operation/%2FP2P%2FR4%2Fmetadata/get", "TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") - fileExists, err = doesfileExist("TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") - th.Assert(t, err == nil, err) - th.Assert(t, fileExists, "JSON file does not exist") + if err == nil { + fileExists, err := doesfileExist("TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") + th.Assert(t, err == nil, err) + th.Assert(t, fileExists, "JSON file does not exist") - fileEmpty, err = isFileEmpty("TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") - th.Assert(t, err == nil, err) - th.Assert(t, !fileEmpty, "Empty JSON file") + fileEmpty, err := isFileEmpty("TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") + th.Assert(t, err == nil, err) + th.Assert(t, !fileEmpty, "Empty JSON file") - err = os.Remove("../../../resources/prod_resources/TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/prod_resources/TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") + th.Assert(t, err == nil, err) - err = os.Remove("../../../resources/dev_resources/TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/dev_resources/TEST_Medicare_GuidewellPayer2PayerEndpointSources.json") + th.Assert(t, err == nil, err) + } else { + log.Info(err) + } // 2. Different file format - GuidewellURLWebscraper("https://developer.bcbsfl.com/interop/interop-developer-portal/product/309/api/288#/CMSInteroperabilityPayer2PayerOutboundMetadata_100/operation/%2FP2P%2FR4%2Fmetadata/get", "TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") + err = GuidewellURLWebscraper("https://developer.bcbsfl.com/interop/interop-developer-portal/product/309/api/288#/CMSInteroperabilityPayer2PayerOutboundMetadata_100/operation/%2FP2P%2FR4%2Fmetadata/get", "TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") - fileExists, err = doesfileExist("TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") - th.Assert(t, err == nil, err) - th.Assert(t, fileExists, "CSV file does not exist") + if err == nil { + fileExists, err := doesfileExist("TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") + th.Assert(t, err == nil, err) + th.Assert(t, fileExists, "CSV file does not exist") - fileEmpty, err = isFileEmpty("TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") - th.Assert(t, err == nil, err) - th.Assert(t, !fileEmpty, "Empty CSV file") + fileEmpty, err := isFileEmpty("TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") + th.Assert(t, err == nil, err) + th.Assert(t, !fileEmpty, "Empty CSV file") - err = os.Remove("../../../resources/prod_resources/TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") - th.Assert(t, err == nil, err) - - err = os.Remove("../../../resources/dev_resources/TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/prod_resources/TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") + th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/dev_resources/TEST_Medicare_GuidewellPayer2PayerEndpointSources.csv") + th.Assert(t, err == nil, err) + } else { + log.Info(err) + } } diff --git a/endpointmanager/pkg/chplendpointquerier/hcscwebscraper.go b/endpointmanager/pkg/chplendpointquerier/hcscwebscraper.go index 6c107d238..f2f6a78f8 100644 --- a/endpointmanager/pkg/chplendpointquerier/hcscwebscraper.go +++ b/endpointmanager/pkg/chplendpointquerier/hcscwebscraper.go @@ -7,10 +7,9 @@ import ( "github.com/PuerkitoBio/goquery" "github.com/chromedp/chromedp" - log "github.com/sirupsen/logrus" ) -func HcscURLWebscraper(chplURL string, fileToWriteTo string) { +func HcscURLWebscraper(chplURL string, fileToWriteTo string) error { var lanternEntryList []LanternEntry var endpointEntryList EndpointList @@ -32,14 +31,12 @@ func HcscURLWebscraper(chplURL string, fileToWriteTo string) { chromedp.OuterHTML(`document.querySelector('ul.hcsc-p:last-of-type')`, &htmlContent, chromedp.ByJSPath)) if err != nil { - log.Info(err) - return + return err } doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlContent)) if err != nil { - log.Info(err) - return + return err } fhirEndpoint = doc.Find("b").Text() @@ -54,14 +51,12 @@ func HcscURLWebscraper(chplURL string, fileToWriteTo string) { chromedp.OuterHTML(endpointDomPath, &htmlContent, chromedp.ByJSPath)) if err != nil { - log.Info(err) - return + return err } doc, err = goquery.NewDocumentFromReader(strings.NewReader(htmlContent)) if err != nil { - log.Info(err) - return + return err } fhirEndpoint = strings.TrimSpace(fhirEndpoint) @@ -77,14 +72,12 @@ func HcscURLWebscraper(chplURL string, fileToWriteTo string) { chromedp.OuterHTML(endpointDomPath, &htmlContent, chromedp.ByJSPath)) if err != nil { - log.Info(err) - return + return err } doc, err = goquery.NewDocumentFromReader(strings.NewReader(htmlContent)) if err != nil { - log.Info(err) - return + return err } fhirEndpoint = strings.TrimSpace(fhirEndpoint) @@ -98,6 +91,8 @@ func HcscURLWebscraper(chplURL string, fileToWriteTo string) { err = WriteCHPLFile(endpointEntryList, fileToWriteTo) if err != nil { - log.Fatal(err) + return err } + + return nil } diff --git a/endpointmanager/pkg/chplendpointquerier/hcscwebscraper_test.go b/endpointmanager/pkg/chplendpointquerier/hcscwebscraper_test.go index 551af023b..97e0f323e 100644 --- a/endpointmanager/pkg/chplendpointquerier/hcscwebscraper_test.go +++ b/endpointmanager/pkg/chplendpointquerier/hcscwebscraper_test.go @@ -29,53 +29,68 @@ func Test_HcscURLWebscraper(t *testing.T) { log.Info("hcsc test file") // 1. Happy case: Valid url, valid file format - HcscURLWebscraper("https://interoperability.hcsc.com/s/provider-directory-api", "TEST_Medicare_HCSCEndpointSources.json") + err := HcscURLWebscraper("https://interoperability.hcsc.com/s/provider-directory-api", "TEST_Medicare_HCSCEndpointSources.json") - fileExists, err := doesfileExist("TEST_Medicare_HCSCEndpointSources.json") - th.Assert(t, err == nil, err) - th.Assert(t, fileExists, "JSON file does not exist") + if err == nil { + fileExists, err := doesfileExist("TEST_Medicare_HCSCEndpointSources.json") + th.Assert(t, err == nil, err) + th.Assert(t, fileExists, "JSON file does not exist") - fileEmpty, err := isFileEmpty("TEST_Medicare_HCSCEndpointSources.json") - th.Assert(t, err == nil, err) - th.Assert(t, !fileEmpty, "Empty JSON file") + fileEmpty, err := isFileEmpty("TEST_Medicare_HCSCEndpointSources.json") + th.Assert(t, err == nil, err) + th.Assert(t, !fileEmpty, "Empty JSON file") - err = os.Remove("../../../resources/prod_resources/TEST_Medicare_HCSCEndpointSources.json") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/prod_resources/TEST_Medicare_HCSCEndpointSources.json") + th.Assert(t, err == nil, err) - err = os.Remove("../../../resources/dev_resources/TEST_Medicare_HCSCEndpointSources.json") - th.Assert(t, err == nil, err) + err = os.Remove("../../../resources/dev_resources/TEST_Medicare_HCSCEndpointSources.json") + th.Assert(t, err == nil, err) + } else { + log.Info(err) + } // 2. Empty inputs - HcscURLWebscraper("", "") - - fileExists, err = doesfileExist("TEST_Medicare_HCSCEndpointSources.json") - th.Assert(t, err == nil, err) - th.Assert(t, !fileExists, "File exists for invalid inputs") - - fileEmpty, err = isFileEmpty("TEST_Medicare_HCSCEndpointSources.json") - th.Assert(t, err != nil, "File data read successfully for invalid inputs") - th.Assert(t, fileEmpty, "File contains data for invalid inputs") + err = HcscURLWebscraper("", "") + + if err == nil { + fileExists, err := doesfileExist("TEST_Medicare_HCSCEndpointSources.json") + th.Assert(t, err == nil, err) + th.Assert(t, !fileExists, "File exists for invalid inputs") + + fileEmpty, err := isFileEmpty("TEST_Medicare_HCSCEndpointSources.json") + th.Assert(t, err != nil, "File data read successfully for invalid inputs") + th.Assert(t, fileEmpty, "File contains data for invalid inputs") + } else { + log.Info(err) + } // 3. Different file format - HcscURLWebscraper("https://interoperability.hcsc.com/s/provider-directory-api", "TEST_Medicare_HCSCEndpointSources.csv") - - fileExists, err = doesfileExist("TEST_Medicare_HCSCEndpointSources.csv") - th.Assert(t, err == nil, err) - th.Assert(t, fileExists, "CSV file does not exist") - - fileEmpty, err = isFileEmpty("TEST_Medicare_HCSCEndpointSources.csv") - th.Assert(t, err == nil, err) - th.Assert(t, !fileEmpty, "Empty CSV file") + err = HcscURLWebscraper("https://interoperability.hcsc.com/s/provider-directory-api", "TEST_Medicare_HCSCEndpointSources.csv") + + if err == nil { + fileExists, err := doesfileExist("TEST_Medicare_HCSCEndpointSources.csv") + th.Assert(t, err == nil, err) + th.Assert(t, fileExists, "CSV file does not exist") + + fileEmpty, err := isFileEmpty("TEST_Medicare_HCSCEndpointSources.csv") + th.Assert(t, err == nil, err) + th.Assert(t, !fileEmpty, "Empty CSV file") + } else { + log.Info(err) + } // 4. Invalid URL - HcscURLWebscraper("https://non-existent-url.com/dummy-api", "TEST_Medicare_HCSCEndpointSources.json") - - fileExists, err = doesfileExist("TEST_Medicare_HCSCEndpointSources.json") - th.Assert(t, err == nil, err) - th.Assert(t, !fileExists, "File exists for invalid URL") - - fileEmpty, err = isFileEmpty("TEST_Medicare_HCSCEndpointSources.json") - th.Assert(t, err != nil, "File read successful for invalid URL") - th.Assert(t, fileEmpty, "File contains data for invalid URL") - + err = HcscURLWebscraper("https://non-existent-url.com/dummy-api", "TEST_Medicare_HCSCEndpointSources.json") + + if err == nil { + fileExists, err := doesfileExist("TEST_Medicare_HCSCEndpointSources.json") + th.Assert(t, err == nil, err) + th.Assert(t, !fileExists, "File exists for invalid URL") + + fileEmpty, err := isFileEmpty("TEST_Medicare_HCSCEndpointSources.json") + th.Assert(t, err != nil, "File read successful for invalid URL") + th.Assert(t, fileEmpty, "File contains data for invalid URL") + } else { + log.Info(err) + } } diff --git a/endpointmanager/pkg/chplendpointquerier/mdlandwebscraper.go b/endpointmanager/pkg/chplendpointquerier/mdlandwebscraper.go index 7d45b5586..55165d820 100644 --- a/endpointmanager/pkg/chplendpointquerier/mdlandwebscraper.go +++ b/endpointmanager/pkg/chplendpointquerier/mdlandwebscraper.go @@ -5,17 +5,16 @@ import ( "github.com/PuerkitoBio/goquery" "github.com/onc-healthit/lantern-back-end/endpointmanager/pkg/helpers" - log "github.com/sirupsen/logrus" ) -func MdlandWebscraper(chplURL string, fileToWriteTo string) { +func MdlandWebscraper(chplURL string, fileToWriteTo string) error { var lanternEntryList []LanternEntry var endpointEntryList EndpointList doc, err := helpers.ChromedpQueryEndpointList(chplURL, ".MsoNormal") if err != nil { - log.Fatal(err) + return err } doc.Find("span").Each(func(index int, spanElem *goquery.Selection) { @@ -35,7 +34,8 @@ func MdlandWebscraper(chplURL string, fileToWriteTo string) { err = WriteCHPLFile(endpointEntryList, fileToWriteTo) if err != nil { - log.Fatal(err) + return err } + return nil } diff --git a/endpointmanager/pkg/chplendpointquerier/ontadawebscraper.go b/endpointmanager/pkg/chplendpointquerier/ontadawebscraper.go index c077b19d1..ed803c1cc 100644 --- a/endpointmanager/pkg/chplendpointquerier/ontadawebscraper.go +++ b/endpointmanager/pkg/chplendpointquerier/ontadawebscraper.go @@ -4,10 +4,9 @@ import ( "strings" "github.com/onc-healthit/lantern-back-end/endpointmanager/pkg/helpers" - log "github.com/sirupsen/logrus" ) -func OntadaWebscraper(chplURL string, fileToWriteTo string) { +func OntadaWebscraper(chplURL string, fileToWriteTo string) error { var lanternEntryList []LanternEntry var endpointEntryList EndpointList @@ -15,7 +14,7 @@ func OntadaWebscraper(chplURL string, fileToWriteTo string) { doc, err := helpers.ChromedpQueryEndpointList(chplURL, ".sc-dTSzeu.dfUAUz") if err != nil { - log.Fatal(err) + return err } divElem := doc.Find(".sc-dTSzeu.dfUAUz").First() @@ -30,7 +29,8 @@ func OntadaWebscraper(chplURL string, fileToWriteTo string) { err = WriteCHPLFile(endpointEntryList, fileToWriteTo) if err != nil { - log.Fatal(err) + return err } + return nil }