@Test public void testServerReturnsWrongVersionForDstu2() throws Exception { Conformance conf = new Conformance(); conf.setFhirVersion("0.80"); String msg = myCtx.newXmlParser().encodeResourceToString(conf); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); when(myHttpResponse.getEntity().getContentType()) .thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()) .thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); myCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); try { myCtx.newRestfulGenericClient("http://foo").read(new UriDt("http://foo/Patient/123")); fail(); } catch (FhirClientInappropriateForServerException e) { String out = e.toString(); String want = "The server at base URL \"http://foo/metadata\" returned a conformance statement indicating that it supports FHIR version \"0.80\" which corresponds to DSTU1, but this client is configured to use DSTU2 (via the FhirContext)"; ourLog.info(out); ourLog.info(want); assertThat(out, containsString(want)); } }
@Test public void testServerReturnsAnHttp401() throws Exception { ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 401, "Unauthorized")); when(myHttpResponse.getEntity().getContentType()) .thenReturn(new BasicHeader("content-type", Constants.CT_TEXT)); when(myHttpResponse.getEntity().getContent()) .thenAnswer( new Answer<InputStream>() { @Override public InputStream answer(InvocationOnMock theInvocation) throws Throwable { return new ReaderInputStream( new StringReader("Unauthorized"), Charset.forName("UTF-8")); } }); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); IGenericClient client = myCtx.newRestfulGenericClient("http://foo"); try { client.read().resource(Patient.class).withId("123").execute(); fail(); } catch (AuthenticationException e) { // good } }
@Test public void testTransaction() throws Exception { String retVal = ourCtx.newXmlParser().encodeBundleToString(new Bundle()); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(ourHttpClient.execute(capt.capture())).thenReturn(ourHttpResponse); when(ourHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); when(ourHttpResponse.getEntity().getContentType()) .thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8")); when(ourHttpResponse.getEntity().getContent()) .thenReturn(new ReaderInputStream(new StringReader(retVal), Charset.forName("UTF-8"))); Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("value"); IGenericClient client = ourCtx.newRestfulGenericClient("http://foo"); client.transaction().withResources(Arrays.asList((IBaseResource) p1)).execute(); HttpUriRequest value = capt.getValue(); assertTrue("Expected request of type POST on long params list", value instanceof HttpPost); HttpPost post = (HttpPost) value; String body = IOUtils.toString(post.getEntity().getContent()); IOUtils.closeQuietly(post.getEntity().getContent()); ourLog.info(body); assertThat( body, Matchers.containsString("<type value=\"" + BundleTypeEnum.TRANSACTION.getCode())); }
@Test public void testServerReturnsAppropriateVersionForDstu2_050() throws Exception { Conformance conf = new Conformance(); conf.setFhirVersion("0.5.0"); final String confResource = myCtx.newXmlParser().encodeResourceToString(conf); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); when(myHttpResponse.getEntity().getContentType()) .thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()) .thenAnswer( new Answer<InputStream>() { @Override public InputStream answer(InvocationOnMock theInvocation) throws Throwable { if (myFirstResponse) { myFirstResponse = false; return new ReaderInputStream( new StringReader(confResource), Charset.forName("UTF-8")); } else { return new ReaderInputStream( new StringReader(myCtx.newXmlParser().encodeResourceToString(new Patient())), Charset.forName("UTF-8")); } } }); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); myCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); IGenericClient client = myCtx.newRestfulGenericClient("http://foo"); // don't load the conformance until the first time the client is actually used assertTrue(myFirstResponse); client.read(new UriDt("http://foo/Patient/123")); assertFalse(myFirstResponse); myCtx.newRestfulGenericClient("http://foo").read(new UriDt("http://foo/Patient/123")); myCtx.newRestfulGenericClient("http://foo").read(new UriDt("http://foo/Patient/123")); // Conformance only loaded once, then 3 reads verify(myHttpClient, times(4)).execute(Matchers.any(HttpUriRequest.class)); }
@Test public void testForceConformanceCheck() throws Exception { Conformance conf = new Conformance(); conf.setFhirVersion("0.5.0"); final String confResource = myCtx.newXmlParser().encodeResourceToString(conf); ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK")); when(myHttpResponse.getEntity().getContentType()) .thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(myHttpResponse.getEntity().getContent()) .thenAnswer( new Answer<InputStream>() { @Override public InputStream answer(InvocationOnMock theInvocation) throws Throwable { if (myFirstResponse) { myFirstResponse = false; return new ReaderInputStream( new StringReader(confResource), Charset.forName("UTF-8")); } else { Patient resource = new Patient(); resource.addName().addFamily().setValue("FAM"); return new ReaderInputStream( new StringReader(myCtx.newXmlParser().encodeResourceToString(resource)), Charset.forName("UTF-8")); } } }); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); myCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); IGenericClient client = myCtx.newRestfulGenericClient("http://foo"); client.registerInterceptor(new BasicAuthInterceptor("USER", "PASS")); client.forceConformanceCheck(); assertEquals(1, capt.getAllValues().size()); Patient pt = (Patient) client.read(new UriDt("http://foo/Patient/123")); assertEquals("FAM", pt.getNameFirstRep().getFamilyAsSingleString()); assertEquals(2, capt.getAllValues().size()); Header auth = capt.getAllValues().get(0).getFirstHeader("Authorization"); assertNotNull(auth); assertEquals("Basic VVNFUjpQQVNT", auth.getValue()); auth = capt.getAllValues().get(1).getFirstHeader("Authorization"); assertNotNull(auth); assertEquals("Basic VVNFUjpQQVNT", auth.getValue()); }
public FHIRService( String url, Context context, DeviceInformation deviceInfo, no.nordicsemi.android.nrftoolbox.gls.Patient p) { this.context = context; this.deviceInfo = deviceInfo; this.patient = p; // initialize context and client ctx = FhirContext.forDstu2(); ctx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); client = ctx.newRestfulGenericClient(url); }
@Test public void testSearchByIdUsingClient() throws Exception { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort); Bundle bundle = client .search() .forResource("Patient") .where(BaseResource.RES_ID.matches().value("aaa")) .execute(); assertEquals(1, bundle.getEntries().size()); Patient p = bundle.getResources(Patient.class).get(0); assertEquals("idaaa", p.getNameFirstRep().getFamilyAsSingleString()); assertEquals("IDAAA (identifier123)", bundle.getEntries().get(0).getTitle().getValue()); }
public static void establishScene() { initScrollData(); Main.hLeft = new VBox(20); Main.hLeft.setEffect(new DropShadow()); Main.hLeft.setAlignment(Pos.CENTER); Main.hLeft.setBackground(new Background(Main.myBG)); Main.hLeft.setMinHeight(Main.height); Main.hLeft.setMinWidth(Main.width / 2 - 100); Main.hRight = new VBox(18); Main.hRight.setAlignment(Pos.TOP_CENTER); Main.hRight.setMinHeight(Main.height); Main.hRight.setMinWidth(Main.width / 2 + 100); Main.hRight.setPadding(new Insets(20, 0, 0, 20)); // Create Dividers VBox stats = new VBox(10); stats.setAlignment(Pos.CENTER); // Patient Portal Image pp = new Image("file:src/docketdoc/res/PD_Logo.png"); ImageView pap = new ImageView(pp); VBox patientPortal = new VBox(); patientPortal.setAlignment(Pos.CENTER); patientPortal.setPadding(new Insets(10, 10, 10, 10)); // Label Label lp = new Label("Patient Portal"); lp.setStyle("-fx-font: 25px Futura;" + "-fx-text-fill: #66CDAA;"); patientPortal.getChildren().addAll(pap, lp); // Search Patient TextField searchTF = new TextField(); searchTF.setStyle( "-fx-max-height: 50px;" + "-fx-max-width: 200px;" + "-fx-text-fill: #505050;" + "-fx-font: 12px Futura;" + "-fx-prompt-text-fill: #505050;"); searchTF.setPromptText("First Name"); TextField searchTFlast = new TextField(); searchTFlast.setStyle( "-fx-max-height: 50px;" + "-fx-max-width: 200px;" + "-fx-text-fill: #505050;" + "-fx-font: 12px Futura;" + "-fx-prompt-text-fill: #505050;"); searchTFlast.setPromptText("Last Name"); // Interact Button Button searchName = new Button("Search Name"); searchName.setStyle( "-fx-background-radius: 0;" + "-fx-font: 16px Futura;" + "-fx-font-weight: bold;" + "-fx-text-fill: white;" + "-fx-background-color: #FF7F50;"); // Hover animation. searchName.setOnMouseEntered( e -> { searchName.setOpacity(.5); }); searchName.setOnMouseExited( e -> { searchName.setOpacity(2); }); // Button Search for Name searchName.setOnAction( e -> { /* ------------------------------------ */ /* Search patiend directory by FHIR API */ /* ------------------------------------ */ new FhirContext(); // Create a client (only needed once) FhirContext ctx = FhirContext.forDstu2(); IGenericClient client = ctx.newRestfulGenericClient("http://fhir2.healthintersections.com.au/open"); String search = new String(searchTF.getText() + " " + searchTFlast.getText()); // Invoke the client Bundle bundle = client .search() .forResource(Patient.class) .where(Patient.NAME.matchesExactly().value(search)) .encodedJson() .execute(); System.out.println("patients count=" + bundle.size()); List<Patient> list = bundle.getResources(Patient.class); for (Patient p : list) { namess = p.getNameFirstRep().getText(); agess = p.getBirthDateElement().toHumanDisplay(); sexess = p.getGender(); } // Add to grid then display // Update Name nameShow = new Label(namess.toUpperCase()); namePat.getChildren().remove(nameShow); patientData.getChildren().remove(namePat); nameShow.setStyle("-fx-font: 15px Futura;" + "-fx-text-fill: #ff0080;"); namePat.getChildren().addAll(nameShow); patientData.getChildren().add(namePat); // Update Age ageShow = new Label(agess.toUpperCase()); agePat.getChildren().remove(ageShow); patientData.getChildren().remove(agePat); ageShow.setStyle("-fx-font: 15px Futura;" + "-fx-text-fill: #ff0080;"); agePat.getChildren().addAll(ageShow); patientData.getChildren().add(agePat); // Update Sex sexShow = new Label(sexess.toUpperCase()); sexPat.getChildren().remove(sexShow); patientData.getChildren().remove(sexPat); sexShow.setStyle("-fx-font: 15px Futura;" + "-fx-text-fill: #ff0080;"); sexPat.getChildren().addAll(sexShow); patientData.getChildren().add(sexPat); addScrollData(); searchTF.setText(null); searchTFlast.setText(null); }); /* ----------------------------------------- */ /* Right Side contained within a scroll Pane */ /* ----------------------------------------- */ patientData = new VBox(10); // Name Divisors pname = new Label("NAME:\t"); pname.setStyle("-fx-font: 15px Futura;" + "-fx-text-fill: #66CDAA;" + "-fx-font-weight: bold;"); namePat = new HBox(10); namePat.getChildren().addAll(pname, nameShow); // Age Divisors page = new Label("DOB:\t"); page.setStyle("-fx-font: 15px Futura;" + "-fx-text-fill: #66CDAA;" + "-fx-font-weight: bold;"); agePat = new HBox(10); agePat.getChildren().addAll(page, ageShow); // Gender Divisors psex = new Label("SEX:\t\t"); psex.setStyle("-fx-font: 15px Futura;" + "-fx-text-fill: #66CDAA;" + "-fx-font-weight: bold;"); sexPat = new HBox(10); sexPat.getChildren().addAll(psex, sexShow); patientData.getChildren().addAll(namePat, agePat, sexPat); // Scrolls scrollSocial.setContent(soScroll); scrollMedical.setContent(medScroll); scrollHistory.setContent(hisScroll); // Add search results to right side Main.hRight.getChildren().addAll(patientData, scrollMedical, scrollSocial, hisScroll); // Add elements to Left Side stats.getChildren().addAll(patientPortal, searchTF, searchTFlast, searchName); // Set Main stage to home scene Main.hLeft.getChildren().addAll(stats); Main.containHome = new HBox(); Main.containHome.getChildren().addAll(Main.hLeft, Main.hRight); Main.homeScene = new Scene(Main.containHome); }