Search in sources :

Example 1 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project beneficiary-fhir-data by CMSgov.

the class ExplanationOfBenefitResourceProvider method compareByClaimIdThenClaimType.

/*
   * @param eob1 an {@link ExplanationOfBenefit} to be compared
   *
   * @param eob2 an {@link ExplanationOfBenefit} to be compared
   */
private static int compareByClaimIdThenClaimType(IBaseResource res1, IBaseResource res2) {
    /*
     * In order for paging to be meaningful (and stable), the claims have to be
     * consistently sorted across different app server instances (in case page 1
     * comes from Server A but page 2 comes from Server B). Right now, we don't have
     * anything "useful" to sort by, so we just sort by claim ID (subsorted by claim
     * type). TODO once we have metadata from BLUEBUTTON-XXX on when each claim was
     * first loaded into our DB, we should sort by that.
     */
    ExplanationOfBenefit eob1 = (ExplanationOfBenefit) res1;
    ExplanationOfBenefit eob2 = (ExplanationOfBenefit) res2;
    if (TransformerUtils.getUnprefixedClaimId(eob1) == TransformerUtils.getUnprefixedClaimId(eob2)) {
        return TransformerUtils.getClaimType(eob1).compareTo(TransformerUtils.getClaimType(eob2));
    } else {
        return TransformerUtils.getUnprefixedClaimId(eob1).compareTo(TransformerUtils.getUnprefixedClaimId(eob2));
    }
}
Also used : ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit)

Example 2 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project beneficiary-fhir-data by CMSgov.

the class R4ExplanationOfBenefitResourceProvider method compareByClaimIdThenClaimType.

/*
   * @param eob1 an {@link ExplanationOfBenefit} to be compared
   *
   * @param eob2 an {@link ExplanationOfBenefit} to be compared
   */
private static int compareByClaimIdThenClaimType(IBaseResource res1, IBaseResource res2) {
    /*
     * In order for paging to be meaningful (and stable), the claims have to be
     * consistently sorted across different app server instances (in case page 1
     * comes from Server A but page 2 comes from Server B). Right now, we don't have
     * anything "useful" to sort by, so we just sort by claim ID (subsorted by claim
     * type). TODO once we have metadata from BLUEBUTTON-XXX on when each claim was
     * first loaded into our DB, we should sort by that.
     */
    ExplanationOfBenefit eob1 = (ExplanationOfBenefit) res1;
    ExplanationOfBenefit eob2 = (ExplanationOfBenefit) res2;
    if (TransformerUtilsV2.getUnprefixedClaimId(eob1).equals(TransformerUtilsV2.getUnprefixedClaimId(eob2))) {
        return TransformerUtilsV2.getClaimType(eob1).compareTo(TransformerUtilsV2.getClaimType(eob2));
    } else {
        return TransformerUtilsV2.getUnprefixedClaimId(eob1).compareTo(TransformerUtilsV2.getUnprefixedClaimId(eob2));
    }
}
Also used : ExplanationOfBenefit(org.hl7.fhir.r4.model.ExplanationOfBenefit)

Example 3 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project kindling by HL7.

the class BuildWorkerContext method queryForTerm.

private SnomedServerResponse queryForTerm(String code) throws Exception {
    if (!triedServer || serverOk) {
        triedServer = true;
        HttpClient httpclient = new DefaultHttpClient();
        HttpGet httpget = new HttpGet("http://tx.fhir.org/snomed/tool/" + SNOMED_EDITION + "/" + URLEncoder.encode(code, "UTF-8").replace("+", "%20"));
        // HttpGet httpget = new HttpGet("http://local.fhir.org:960/r4/snomed/tool/"+SNOMED_EDITION+"/"+URLEncoder.encode(code, "UTF-8").replace("+", "%20")); // don't like the url encoded this way
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        InputStream instream = entity.getContent();
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            Document xdoc = builder.parse(instream);
            // we always get back a version, and a type. What we do depends on the type
            String t = xdoc.getDocumentElement().getAttribute("type");
            serverOk = true;
            if (t.equals("error"))
                throw new Exception(xdoc.getDocumentElement().getAttribute("message"));
            if (t.equals("description"))
                throw new Exception("The Snomed code (\"" + code + "\") is a description id not a concept id which is not valid");
            if (t.equals("concept")) {
                Concept c = new Concept();
                c.display = xdoc.getDocumentElement().getAttribute("display");
                Element child = XMLUtil.getFirstChild(xdoc.getDocumentElement());
                while (child != null) {
                    c.displays.add(child.getAttribute("value"));
                    child = XMLUtil.getNextSibling(child);
                }
                snomedCodes.put(code, c);
                return null;
            }
            if (t.equals("expression")) {
                SnomedServerResponse resp = new SnomedServerResponse();
                resp.correctExpression = xdoc.getDocumentElement().getAttribute("expressionMinimal");
                resp.display = xdoc.getDocumentElement().getAttribute("display");
                if (!snomedCodes.containsKey(resp.correctExpression)) {
                    Concept c = new Concept();
                    c.display = resp.display;
                    snomedCodes.put(resp.correctExpression, c);
                }
                return resp;
            }
            throw new Exception("Unrecognised response from server");
        } finally {
            instream.close();
        }
    } else
        return null;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) HttpEntity(org.apache.http.HttpEntity) CSFileInputStream(org.hl7.fhir.utilities.CSFileInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) Element(org.w3c.dom.Element) HttpResponse(org.apache.http.HttpResponse) Document(org.w3c.dom.Document) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) UcumException(org.fhir.ucum.UcumException) TerminologyServiceException(org.hl7.fhir.exceptions.TerminologyServiceException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) EFhirClientException(org.hl7.fhir.r5.utils.client.EFhirClientException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) FHIRException(org.hl7.fhir.exceptions.FHIRException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient)

Example 4 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project kindling by HL7.

the class SourceParser method ftpFetch.

private byte[] ftpFetch(String n) throws Exception {
    URI url = new URI(n);
    String server = url.getHost();
    int port = 21;
    FTPClient ftpClient = new FTPClient();
    ftpClient.connect(server, port);
    ftpClient.login("anonymous", "anonymous");
    ftpClient.enterLocalPassiveMode();
    ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
    // APPROACH #1: using retrieveFile(String, OutputStream)
    String remoteFile1 = url.getPath();
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    boolean success = ftpClient.retrieveFile(remoteFile1, bytes);
    bytes.close();
    if (!success)
        throw new Exception("Unable to retrieve " + n);
    return bytes.toByteArray();
}
Also used : ByteArrayOutputStream(org.apache.commons.io.output.ByteArrayOutputStream) URI(java.net.URI) FTPClient(org.apache.commons.net.ftp.FTPClient) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileNotFoundException(java.io.FileNotFoundException) SAXException(org.xml.sax.SAXException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 5 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project hl7v2-fhir-converter by LinuxForHealth.

the class JvmTimeZoneIdTest method testEmptyDefaultTimeZoneYieldsJVMZoneId.

@Test
void testEmptyDefaultTimeZoneYieldsJVMZoneId() throws IOException {
    // Create our own properties file
    File configFile = new File(folder, "config.properties");
    writeSimpleProperties(configFile);
    System.setProperty(CONF_PROP_HOME, configFile.getParent());
    ConverterConfiguration.reset();
    // Prove that we're using our custom properties file with no ZoneId
    ConverterConfiguration theConvConfig = ConverterConfiguration.getInstance();
    // Four messages supported.  (Proves we're using our created file, not the default.)
    assertThat(theConvConfig.getSupportedMessageTemplates()).hasSize(13);
    // Purposely empty
    assertThat(theConvConfig.getZoneId()).isNull();
    // IMPORTANT: TimeZoneId's are different than an offset.  TimeZoneId's are a location.
    // The offset of the location changes depending on whether Daylight savings time is in effect.
    // Because we compare after processing, we can't compare locations, only offsets.
    // It is critical that when we compare offsets, we start with the same date, so the same daylight savings rules apply!
    // Otherwise a test might work only half of the year.
    // Calculate the local server zone offset
    // 20020202020000
    LocalDateTime localDateTime = LocalDateTime.of(2002, Month.FEBRUARY, 2, 2, 0, 0);
    String defaultLocalZone = TimeZone.getDefault().getID();
    ZoneId localZoneId = ZoneId.of(defaultLocalZone);
    ZonedDateTime localZonedDateTime = localDateTime.atZone(localZoneId);
    ZoneOffset localOffset = localZonedDateTime.getOffset();
    // PART 1
    // Test the format utility (which will fallback to local server time and zone offset)
    String testDateTime = DateUtil.formatToDateTimeWithDefaultZone("20020202020000");
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
    ZonedDateTime testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
    ZoneOffset testOffset = testZonedDateTime.getOffset();
    // Offset from our function call test should equal offset of the local time
    assertThat(testOffset).isEqualTo(localOffset);
    // PART 2
    // Do the same for a date going through the entire conversion
    String hl7message = "MSH|^~\\&|||||20020202020000|1|PPR^PC1|331|P|2.3.1||\r" + "PID||||||||||||||||||||||||||||||\r" + "PV1||I||||||||||||||||||||||||||||||||||||||||||\r" + // PRB.2 to recordedDateTime (check time ZoneId)
    "PRB|AD|20020202020000|K80.00^Cholelithiasis^I10|53956||||||||||||\r";
    ConverterOptions customOptionsWithTenant = new Builder().withValidateResource().withPrettyPrint().build();
    List<BundleEntryComponent> e = ResourceUtils.createFHIRBundleFromHL7MessageReturnEntryList(ftv, hl7message, customOptionsWithTenant);
    // Find the condition from the FHIR bundle.
    List<Resource> conditionResource = ResourceUtils.getResourceList(e, ResourceType.Condition);
    assertThat(conditionResource).hasSize(1);
    Condition condition = (Condition) conditionResource.get(0);
    // Get the recordedDate value; convert it back to a zoned time; get the offset for comparison
    // PRB.2
    testDateTime = condition.getRecordedDateElement().getValueAsString();
    testZonedDateTime = ZonedDateTime.parse(testDateTime, dateTimeFormatter);
    testOffset = testZonedDateTime.getOffset();
    // Offset from our test should equal offset of the local time
    assertThat(testOffset).isEqualTo(localOffset);
// After the test, the properties file resets.
}
Also used : LocalDateTime(java.time.LocalDateTime) Condition(org.hl7.fhir.r4.model.Condition) ZoneId(java.time.ZoneId) ConverterOptions(io.github.linuxforhealth.hl7.ConverterOptions) Builder(io.github.linuxforhealth.hl7.ConverterOptions.Builder) Resource(org.hl7.fhir.r4.model.Resource) ConverterConfiguration(io.github.linuxforhealth.core.config.ConverterConfiguration) ZoneOffset(java.time.ZoneOffset) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ZonedDateTime(java.time.ZonedDateTime) File(java.io.File) DateTimeFormatter(java.time.format.DateTimeFormatter) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.Test)107 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)100 IOException (java.io.IOException)47 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)42 FHIRException (org.hl7.fhir.exceptions.FHIRException)39 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)38 ArrayList (java.util.ArrayList)25 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)24 FileNotFoundException (java.io.FileNotFoundException)21 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)19 Date (java.util.Date)18 Bundle (org.hl7.fhir.r4.model.Bundle)17 URISyntaxException (java.net.URISyntaxException)16 HashMap (java.util.HashMap)16 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 FhirContext (ca.uhn.fhir.context.FhirContext)14 LocalDate (java.time.LocalDate)14 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)13 File (java.io.File)12 Header (org.apache.http.Header)11