@Test public void testTwoInclude() throws Exception { HttpGet httpGet = new HttpGet( "http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=bar&_pretty=true"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info(responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); assertEquals(2, p.getName().size()); assertEquals("Hello", p.getId().getIdPart()); Set<String> values = new HashSet<String>(); values.add(p.getName().get(0).getFamilyFirstRep().getValue()); values.add(p.getName().get(1).getFamilyFirstRep().getValue()); assertThat(values, containsInAnyOrder("foo", "bar")); }
@Test public void testIIncludedResourcesNonContainedInExtensionJson() throws Exception { HttpGet httpGet = new HttpGet( "http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true&_format=json"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent); ourLog.info(responseContent); assertEquals(3, bundle.size()); assertEquals( new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless()); assertEquals( new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless()); assertEquals( new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless()); assertEquals( BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum()); Patient p1 = (Patient) bundle.toListOfResources().get(0); assertEquals(0, p1.getContained().getContainedResources().size()); Patient p2 = (Patient) bundle.toListOfResources().get(1); assertEquals(0, p2.getContained().getContainedResources().size()); }
@Test public void testSchematronResourceValidator() throws IOException { String res = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("patient-example-dicom.json")); Patient p = ourCtx.newJsonParser().parseResource(Patient.class, res); FhirValidator val = ourCtx.newValidator(); val.setValidateAgainstStandardSchema(false); val.setValidateAgainstStandardSchematron(true); ValidationResult validationResult = val.validateWithResult(p); assertTrue(validationResult.isSuccessful()); p.getTelecomFirstRep().setValue("123-4567"); validationResult = val.validateWithResult(p); assertFalse(validationResult.isSuccessful()); OperationOutcome operationOutcome = (OperationOutcome) validationResult.toOperationOutcome(); ourLog.info( ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome)); assertEquals(1, operationOutcome.getIssue().size()); assertThat(operationOutcome.getIssueFirstRep().getDiagnostics(), containsString("cpt-2:")); p.getTelecomFirstRep().setSystem(ContactPointSystemEnum.EMAIL); validationResult = val.validateWithResult(p); assertTrue(validationResult.isSuccessful()); }
@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())); }
/** * gets Patient from the server if existing. else creates a new one. * * @return */ private Patient getPatient() { Log.d(TAG, "looking for patient"); Patient p = this.newPatient(patient.getLastname(), patient.getFirstName(), patient.getDateOfBirth()); p.setText(getNarrative(p)); p.setIdentifier( Arrays.asList( new IdentifierDt() .setSystem(SYSTEM_URL.concat("/patients/")) .setValue( patient .getLastname() .concat(patient.getFirstName()) .concat( SimpleDateFormat.getDateInstance(DateFormat.SHORT) .format(patient.getDateOfBirth()))))); IdDt patientId = (IdDt) client .create() .resource(p) .conditionalByUrl(getConditionalUrl(p, p.getIdentifierFirstRep())) .execute() .getId(); p.setId(patientId); return p; }
@SuppressWarnings("deprecation") @Test public void testSchemaResourceValidator() throws IOException { String res = IOUtils.toString( getClass().getClassLoader().getResourceAsStream("patient-example-dicom.json")); Patient p = ourCtx.newJsonParser().parseResource(Patient.class, res); ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p)); FhirValidator val = ourCtx.newValidator(); val.setValidateAgainstStandardSchema(true); val.setValidateAgainstStandardSchematron(false); val.validate(p); p.getAnimal().getBreed().setText("The Breed"); try { val.validate(p); fail(); } catch (ValidationFailureException e) { OperationOutcome operationOutcome = (OperationOutcome) e.getOperationOutcome(); ourLog.info( ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(operationOutcome)); assertEquals(1, operationOutcome.getIssue().size()); assertThat( operationOutcome.getIssueFirstRep().getDetailsElement().getValue(), containsString("cvc-complex-type")); } }
/** See issue #50 */ @Test public void testOutOfBoundsDate() { Patient p = new Patient(); p.setBirthDate(new DateDt("2000-15-31")); String encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(p); ourLog.info(encoded); assertThat(encoded, StringContains.containsString("2000-15-31")); p = ourCtx.newXmlParser().parseResource(Patient.class, encoded); assertEquals("2000-15-31", p.getBirthDateElement().getValueAsString()); assertEquals("2001-03-31", new SimpleDateFormat("yyyy-MM-dd").format(p.getBirthDate())); ValidationResult result = ourCtx.newValidator().validateWithResult(p); String resultString = ourCtx .newXmlParser() .setPrettyPrint(true) .encodeResourceToString(result.toOperationOutcome()); ourLog.info(resultString); assertEquals(2, ((OperationOutcome) result.toOperationOutcome()).getIssue().size()); assertThat(resultString, StringContains.containsString("2000-15-31")); }
private Patient newPatient(String familyName, String givenName, Date date) { Log.d(TAG, "creating new patient"); Patient p = new Patient(); p.addName().addFamily(familyName).addGiven(givenName); p.setBirthDate(new DateDt(date)); return p; }
@Search() public Patient search(@Elements Set<String> theElements) { ourLastElements = theElements; Patient patient = new Patient(); patient.setId("Patient/1/_history/1"); patient.getText().setDiv("<div>THE DIV</div>"); patient.addName().addFamily("FAMILY"); patient.setMaritalStatus(MaritalStatusCodesEnum.D); return patient; }
@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()); }
@Test public void testNoIncludes() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); assertEquals(0, p.getName().size()); assertEquals("Hello", p.getId().getIdPart()); }
private Device initializeDevice(Patient p) { log("Initializing device"); Device d = newDevice(); d.setManufacturer(deviceInfo.getManufacturerName()); d.setModel(deviceInfo.getModelNumber()); d.setVersion(deviceInfo.getFirmwareRevision()); NarrativeDt n = getNarrative(d); n.setDiv( n.getDiv() .getValueAsString() .substring(5, n.getDiv().getValueAsString().length() - 6) .concat("<strong>Serial Number: </strong>") .concat(deviceInfo.getSerialNumber()) .concat("<br /><strong>Name: </strong>") .concat(deviceInfo.getName()) .concat("<br /><strong>MAC Address: </strong>") .concat(deviceInfo.getAddress())); d.setText(n); CodeableConceptDt type = new CodeableConceptDt(); // TODO find valid url type.addCoding() .setCode("15-102") .setDisplay("Glukose-Analysegerät") .setSystem("http://umdns.org"); d.setType(type); d.setPatient(newResourceReference(p.getId())); d.setIdentifier(Arrays.asList(getIdentifier("/devices/", "" + deviceInfo.getSysID()))); log("Initializing device done"); return d; }
/** * @notice In Fhir model, {@link Patient} has a collection of names, while in this extension * table, {@link PersonComplement}, there is only one name for each {@link Person}. */ @Override public IResourceEntity constructEntityFromResource(IResource resource) { super.constructEntityFromResource(resource); if (resource instanceof Patient) { Patient patient = (Patient) resource; Iterator<HumanNameDt> iterator = patient.getName().iterator(); // while(iterator.hasNext()){ if (iterator.hasNext()) { HumanNameDt next = iterator.next(); this.givenName1 = next.getGiven() .get(0) .getValue(); // the next method was not advancing to the next element, then the need // to use the get(index) method if (next.getGiven().size() > 1) // TODO add unit tests, to assure this won't be changed to hasNext this.givenName2 = next.getGiven().get(1).getValue(); Iterator<StringDt> family = next.getFamily().iterator(); this.familyName = ""; while (family.hasNext()) { this.familyName = this.familyName.concat(family.next().getValue() + " "); } if (next.getSuffix().iterator().hasNext()) this.suffixName = next.getSuffix().iterator().next().getValue(); if (next.getPrefix().iterator().hasNext()) this.prefixName = next.getPrefix().iterator().next().getValue(); } // } this.active = patient.getActive(); // MARITAL STATUS // // this.maritalStatus.setId(OmopConceptMapping.getInstance().get(OmopConceptMapping.MARITAL_STATUS, patient.getMaritalStatus().getText())); } else { ourLog.error( "There was not possible to construct the entity ? using the resource ?. It should be used the resource ?.", this.getClass().getSimpleName(), resource.getResourceName(), getResourceType()); } return this; }
@Override public Patient getRelatedResource() { Patient patient = (Patient) super.getRelatedResource(); patient.addName().addFamily(this.familyName).addGiven(this.givenName1); if (this.givenName2 != null) patient.getName().get(0).addGiven(this.givenName2); boolean active = this.active != null ? this.active : false; patient.setActive(active); // MARITAL STATUS // MaritalStatusCodesEnum[] values = MaritalStatusCodesEnum.values(); // for (int i = 0; i < values.length; i++) { // if(values[i].equals(this.maritalStatus.getName())){ // patient.setMaritalStatus(values[i]); // break; // } // } // or patient.setMaritalStatus(MaritalStatusCodesEnum.valueOf("")); return patient; }
@Search public List<Patient> findPatient( @RequiredParam(name = Patient.SP_NAME) StringDt theName, @IncludeParam(allow = {"foo", "bar"}) Set<Include> theIncludes) { ArrayList<Patient> retVal = new ArrayList<Patient>(); Patient p = new Patient(); p.addIdentifier().setSystem("foo").setValue("bar"); p.setId(theName.getValue()); if (theIncludes != null) { for (Include next : theIncludes) { p.addName().addFamily().setValue(next.getValue()); } } retVal.add(p); return retVal; }
@Test public void testOneIncludeJson() throws Exception { HttpGet httpGet = new HttpGet( "http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_format=json"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); ourLog.info(responseContent); Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); assertEquals(1, p.getName().size()); assertEquals("Hello", p.getId().getIdPart()); assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); }
@Search(queryName = "containedInclude") public List<Patient> containedInclude() { Organization o1 = new Organization(); o1.getNameElement().setValue("o1"); Patient p1 = new Patient(); p1.setId("p1"); p1.addIdentifier().setValue("p1"); p1.getManagingOrganization().setResource(o1); Patient p2 = new Patient(); p2.setId("p2"); p2.addIdentifier().setValue("p2"); p2.getManagingOrganization().setResource(o1); return Arrays.asList(p1, p2); }
@Search(queryName = "extInclude") public List<Patient> extInclude() { Organization o1 = new Organization(); o1.getNameElement().setValue("o1"); o1.setId("o1"); Patient p1 = new Patient(); p1.setId("p1"); p1.addIdentifier().setValue("p1"); p1.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); Patient p2 = new Patient(); p2.setId("p2"); p2.addIdentifier().setValue("p2"); p2.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); return Arrays.asList(p1, p2); }
private Observation initializeObservation( Patient p, DeviceMetric metric, GlucoseRecord r, QuantityDt qdt) { log("Initializing observation"); Observation o = newObservation(qdt); o.setCode(createCode(r.unit)); o.setSubject(newResourceReference(p.getId())); o.setDevice(newResourceReference(metric.getId())); // set date and time for observation DateTimeDt dt = new DateTimeDt(); dt.setValue(r.time.getTime()); o.setEffective(dt); o.setIdentifier( Arrays.asList( getIdentifier( "/devices/".concat("" + deviceInfo.getSysID()), "" + r.getSequenceNumber()))); // set narrative o.setText(getNarrative(o)); log("Initializing observation done"); return o; }
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); }