当前位置: 首页>>代码示例>>Java>>正文


Java IParser.encodeResourceToString方法代码示例

本文整理汇总了Java中ca.uhn.fhir.parser.IParser.encodeResourceToString方法的典型用法代码示例。如果您正苦于以下问题:Java IParser.encodeResourceToString方法的具体用法?Java IParser.encodeResourceToString怎么用?Java IParser.encodeResourceToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ca.uhn.fhir.parser.IParser的用法示例。


在下文中一共展示了IParser.encodeResourceToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadObservationData

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public void loadObservationData() throws Exception {
	IParser parser = ctx.newJsonParser();

	FileReader fileReader = new FileReader(
			new File(this.getClass().getClassLoader().getResource("fhir/observation_example001.json").getPath()));
	IBaseResource resource = parser.parseResource(fileReader);

	for (int i = 0; i < 1; i++) {

		resource.getIdElement().setValue("obs_" + i);
		((Observation) resource).getIdentifier().get(0).setValue("urn:uuid:187e0c12-8dd2-67e2-99b2-bf273c1111" + i);

		String json = parser.encodeResourceToString(resource);

		long timestamp = Calendar.getInstance().getTimeInMillis();
		session.execute(
				"INSERT INTO test.FHIR_RESOURCES (resource_id, version, resource_type, state, lastupdated, format, author, content)"
						+ " VALUES ('" + resource.getIdElement().getValue() + "', 1, '"
						+ resource.getClass().getSimpleName() + "', 'active', " + timestamp + ", 'json', 'dr who',"
						+ "'" + json + "')");

		System.out.println(resource.getClass().getSimpleName() + ": " + resource.getIdElement().getValue());
	}
}
 
开发者ID:jmiddleton,项目名称:cassandra-fhir-index,代码行数:25,代码来源:FhirTestDataTest.java

示例2: main

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public static void main(String[] theArgs) {

		// Create a Patient
		Patient pat = new Patient();
		pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("J");
		pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135");
		pat.addTelecom().setUse(ContactPointUse.HOME).setSystem(ContactPointSystem.PHONE).setValue("1 (416) 340-4800");
		pat.setGender(AdministrativeGender.MALE);

		// Create a context
		FhirContext ctx = FhirContext.forDstu3();

		// Create a JSON parser
		IParser parser = ctx.newJsonParser();
		parser.setPrettyPrint(true);

		String encode = parser.encodeResourceToString(pat);
		System.out.println(encode);

	}
 
开发者ID:furore-fhir,项目名称:fhirstarters,代码行数:21,代码来源:Example04_EncodeResource.java

示例3: testModelExtension

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Test
	public void testModelExtension() throws DataFormatException {
		MyOrganization org = new MyOrganization();
		org.getName().setValue("org0");

		MyPatient patient = new MyPatient();
		patient.addIdentifier("foo", "bar");
		patient.getManagingOrganization().setResource(org);

		IParser p = ourCtx.newXmlParser().setPrettyPrint(true);
		String str = p.encodeResourceToString(patient);

		ourLog.info(str);

		MyPatient parsed = ourCtx.newXmlParser().parseResource(MyPatient.class, str);
		assertEquals("foo", parsed.getIdentifierFirstRep().getSystem().getValueAsString());

//		assertEquals(MyOrganization.class, parsed.getManagingOrganization().getResource().getClass());
//		MyOrganization parsedOrg = (MyOrganization) parsed.getManagingOrganization().getResource();
//		assertEquals("arg0", parsedOrg.getName().getValue());
	}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:22,代码来源:ModelExtensionTest.java

示例4: main

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public static void main(String[] theArgs) {
	
	// Create a Patient
	Patient pat = new Patient();
	pat.addName().addFamily("Simpson").addGiven("Homer").addGiven("J");
	pat.addIdentifier().setSystem("http://acme.org/MRNs").setValue("7000135");
	pat.addIdentifier().setLabel("Library Card 12345").setValue("12345");
	pat.addTelecom().setUse(ContactUseEnum.HOME).setSystem(ContactSystemEnum.PHONE).setValue("1 (416) 340-4800");
	pat.setGender(AdministrativeGenderCodesEnum.M);
	
	// Create a context
	FhirContext ctx = new FhirContext();
	
	// Create a XML parser
	IParser parser = ctx.newXmlParser();
	parser.setPrettyPrint(true);
	
	String encode = parser.encodeResourceToString(pat);
	System.out.println(encode);
	
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:22,代码来源:Example03_EncodeResource.java

示例5: sendBadRequest

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
private void sendBadRequest(IBaseOperationOutcome outcome) {
    String responseContentType = determineClientContentType();

    IParser parser = newParser(responseContentType);
    String body = parser.encodeResourceToString(outcome);

    FinishRequest badRequest = new FinishRequest(body, responseContentType, HttpStatus.SC_BAD_REQUEST);
    requestHandler.tell(badRequest, getSelf());
}
 
开发者ID:jembi,项目名称:openhim-mediator-fhir-proxy,代码行数:10,代码来源:FhirProxyHandler.java

示例6: main

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public static void main(String[] args) {
     Example32_ExtendedPatient pat = new Example32_ExtendedPatient();
	pat.addName().setFamily("Simpson").addGiven("Homer");

	pat.setEyeColour(new CodeType("blue"));

	IParser p = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true);
	String encoded = p.encodeResourceToString(pat);
	
	System.out.println(encoded);
}
 
开发者ID:furore-fhir,项目名称:fhirstarters,代码行数:12,代码来源:Example33_UseExtendedPatient.java

示例7: main

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public static void main(String[] args) throws DataFormatException, IOException {
//START SNIPPET: patientUse
MyPatient patient = new MyPatient();
patient.setPetName(new StringDt("Fido"));
patient.getImportantDates().add(new DateTimeDt("2010-01-02"));
patient.getImportantDates().add(new DateTimeDt("2014-01-26T11:11:11"));

patient.addName().addFamily("Smith").addGiven("John").addGiven("Quincy").addSuffix("Jr");

IParser p = new FhirContext().newXmlParser().setPrettyPrint(true);
String messageString = p.encodeResourceToString(patient);

System.out.println(messageString);
//END SNIPPET: patientUse
	
//START SNIPPET: patientParse
IParser parser = new FhirContext().newXmlParser();
MyPatient newPatient = parser.parseResource(MyPatient.class, messageString);
//END SNIPPET: patientParse

{
	FhirContext ctx2 = new FhirContext();
	RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient);
	System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile()));
}
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:28,代码来源:MyPatientUse.java

示例8: encodeMsg

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public void encodeMsg() throws DataFormatException {
FhirContext ctx = new FhirContext(Patient.class, Observation.class);
//START SNIPPET: encodeMsg

/**
 * FHIR model types in HAPI are simple POJOs. To create a new
 * one, invoke the default constructor and then
 * start populating values.
 */
Patient patient = new Patient();

// Add an MRN (a patient identifier)
IdentifierDt id = patient.addIdentifier();
id.setSystem("http://example.com/fictitious-mrns");
id.setValue("MRN001");

// Add a name
HumanNameDt name = patient.addName();
name.setUse(NameUseEnum.OFFICIAL);
name.addFamily("Tester");
name.addGiven("John");
name.addGiven("Q");

// We can now use a parser to encode this resource into a string.
String encoded = ctx.newXmlParser().encodeResourceToString(patient);
System.out.println(encoded);
//END SNIPPET: encodeMsg

//START SNIPPET: encodeMsgJson
IParser jsonParser = ctx.newJsonParser();
jsonParser.setPrettyPrint(true);
encoded = jsonParser.encodeResourceToString(patient);
System.out.println(encoded);
//END SNIPPET: encodeMsgJson

		
	}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:38,代码来源:FhirContextIntro.java

示例9: main

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public static void main(String[] args) throws DataFormatException, IOException {
	// START SNIPPET: patientUse
	MyPatient patient = new MyPatient();
	patient.setPetName(new StringDt("Fido"));
	patient.getImportantDates().add(new DateTimeDt("2010-01-02"));
	patient.getImportantDates().add(new DateTimeDt("2014-01-26T11:11:11"));

	patient.addName().addFamily("Smith").addGiven("John").addGiven("Quincy").addSuffix("Jr");

	IParser p = new FhirContext().newXmlParser().setPrettyPrint(true);
	String messageString = p.encodeResourceToString(patient);

	System.out.println(messageString);
	// END SNIPPET: patientUse

	// START SNIPPET: patientParse
	IParser parser = new FhirContext().newXmlParser();
	MyPatient newPatient = parser.parseResource(MyPatient.class, messageString);
	// END SNIPPET: patientParse

	{
		FhirContext ctx2 = new FhirContext();
		RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient);
		System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile("http://foo.org/fhir")));
	}
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:28,代码来源:ExtensionTest.java

示例10: testGetMetadata

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Test
public void testGetMetadata() throws Exception {

	HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata");
	HttpResponse status = ourClient.execute(httpGet);

	String responseContent = IOUtils.toString(status.getEntity().getContent());
	IOUtils.closeQuietly(status.getEntity().getContent());

	// ourLog.info("Response was:\n{}", responseContent);

	assertEquals(200, status.getStatusLine().getStatusCode());
	IParser parser = ourCtx.newXmlParser().setPrettyPrint(true);
	Conformance bundle = parser.parseResource(Conformance.class, responseContent);

	{
		IParser p = ourCtx.newXmlParser().setPrettyPrint(true);
		String enc = p.encodeResourceToString(bundle);
		ourLog.info("Response:\n{}", enc);

		p = ourCtx.newXmlParser().setPrettyPrint(false);
		enc = p.encodeResourceToString(bundle);
		ourLog.info("Response:\n{}", enc);
		assertThat(enc, StringContains.containsString("<name value=\"quantityParam\"/><type value=\"quantity\"/>"));
	}
	// {
	// IParser p = ourCtx.newJsonParser().setPrettyPrint(true);
	//
	// p.encodeResourceToWriter(bundle, new OutputStreamWriter(System.out));
	//
	// String enc = p.encodeResourceToString(bundle);
	// ourLog.info("Response:\n{}", enc);
	// assertTrue(enc.contains(ExtensionConstants.CONF_ALSO_CHAIN));
	//
	// }
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:37,代码来源:RestfulServerMethodTest.java

示例11: main

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public static void main(String[] args) {
	Patient pat = new Patient();
	pat.addName().addFamily("Simpson").addGiven("Homer");
	
	String url = "http://acme.org#eyeColour";
	boolean isModifier = false;
	pat.addUndeclaredExtension(isModifier, url).setValue(new CodeDt("blue"));;
	
	IParser p = new FhirContext().newXmlParser().setPrettyPrint(true);
	String encoded = p.encodeResourceToString(pat);
	
	System.out.println(encoded);
}
 
开发者ID:gajen0981,项目名称:FHIR-Server,代码行数:14,代码来源:Example10_Extensions.java

示例12: testResponseHasContentTypeMissing

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Test
public void testResponseHasContentTypeMissing() throws Exception {
  IParser p = ourCtx.newXmlParser();
  Patient patient = new Patient();
  patient.addName().setFamily("FAM");
  final String respString = p.encodeResourceToString(patient);

  ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
  when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
  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().getContentType()).thenReturn(null);
  when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
    @Override
    public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
      return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
    }
  });

  IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
  try {
    client.read().resource(Patient.class).withId("1").execute();
    fail();
  } catch (NonFhirResponseException e) {
    assertEquals("Response contains no Content-Type", e.getMessage());
  }

  // Patient resp = client.read().resource(Patient.class).withId("1").execute();
  // assertEquals("FAM", resp.getNameFirstRep().getFamilyAsSingleString());
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:31,代码来源:GenericClientR4Test.java

示例13: testValidateResourceOnly

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Test
public void testValidateResourceOnly() throws Exception {
	IParser p = ourCtx.newXmlParser();

	OperationOutcome conf = new OperationOutcome();
	conf.getText().setDivAsString("OK!");

	final String respString = p.encodeResourceToString(conf);
	ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
	when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
	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<ReaderInputStream>() {
		@Override
		public ReaderInputStream answer(InvocationOnMock theInvocation) throws Throwable {
			return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
		}
	});

	IClient client = ourCtx.newRestfulClient(IClient.class, "http://example.com/fhir");

	Patient patient = new Patient();
	patient.addName().setFamily("FAM");
	
	int idx = 0;
	MethodOutcome outcome = client.validate(patient, null, null);
	String resp = ourCtx.newXmlParser().encodeResourceToString(outcome.getOperationOutcome());
	assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">OK!</div></text></OperationOutcome>", resp);
	assertEquals("http://example.com/fhir/$validate", capt.getAllValues().get(idx).getURI().toString());
	String request = extractBodyAsString(capt,idx);
	assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><family value=\"FAM\"/></name></Patient></resource></parameter></Parameters>", request);

	idx = 1;
	outcome = client.validate(patient, ValidationModeEnum.CREATE, "http://foo");
	resp = ourCtx.newXmlParser().encodeResourceToString(outcome.getOperationOutcome());
	assertEquals("<OperationOutcome xmlns=\"http://hl7.org/fhir\"><text><div xmlns=\"http://www.w3.org/1999/xhtml\">OK!</div></text></OperationOutcome>", resp);
	assertEquals("http://example.com/fhir/$validate", capt.getAllValues().get(idx).getURI().toString());
	request = extractBodyAsString(capt,idx);
	assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"resource\"/><resource><Patient xmlns=\"http://hl7.org/fhir\"><name><family value=\"FAM\"/></name></Patient></resource></parameter><parameter><name value=\"mode\"/><valueString value=\"create\"/></parameter><parameter><name value=\"profile\"/><valueString value=\"http://foo\"/></parameter></Parameters>", request);
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:41,代码来源:NonGenericClientR4Test.java

示例14: testMetaAdd

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Test
public void testMetaAdd() throws Exception {
	IParser p = ourCtx.newXmlParser();

	MetaDt inMeta = new MetaDt().addProfile("urn:profile:in");

	Parameters outParams = new Parameters();
	outParams.addParameter().setName("meta").setValue(new MetaDt().addProfile("urn:profile:out"));
	final String respString = p.encodeResourceToString(outParams);

	ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8";
	ourResponseBody = respString;

	IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir");

	MetaDt resp = client
			.meta()
			.add()
			.onResource(new IdDt("Patient/123"))
			.meta(inMeta)
			.execute();

	assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$meta-add", ourRequestUri);
	assertEquals("urn:profile:out", resp.getProfile().get(0).getValue());
	assertEquals("POST", ourRequestMethod);
	assertEquals("<Parameters xmlns=\"http://hl7.org/fhir\"><parameter><name value=\"meta\"/><valueMeta><profile value=\"urn:profile:in\"/></valueMeta></parameter></Parameters>",
			ourRequestBodyString);
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:29,代码来源:GenericOkHttpClientDstu2Test.java

示例15: validate

import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Override
protected List<ValidationMessage> validate(IValidationContext<?> theCtx) {
	Object resource = theCtx.getResource();
	if (!(theCtx.getResource() instanceof IBaseResource)) {
		ourLog.debug("Not validating object of type {}", theCtx.getResource().getClass());
		return Collections.emptyList();
	}

	if (resource instanceof QuestionnaireResponse) {
		return doValidate(theCtx, (QuestionnaireResponse) resource);
	}

	RuntimeResourceDefinition def = theCtx.getFhirContext().getResourceDefinition((IBaseResource) resource);
	if ("QuestionnaireResponse".equals(def.getName()) == false) {
		return Collections.emptyList();
	}

	/*
	 * If we have a non-RI structure, convert it
	 */

	IParser p = theCtx.getFhirContext().newJsonParser();
	String string = p.encodeResourceToString((IBaseResource) resource);
	QuestionnaireResponse qa = p.parseResource(QuestionnaireResponse.class, string);

	return doValidate(theCtx, qa);
}
 
开发者ID:jamesagnew,项目名称:hapi-fhir,代码行数:28,代码来源:FhirQuestionnaireResponseValidator.java


注:本文中的ca.uhn.fhir.parser.IParser.encodeResourceToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。