本文整理汇总了Java中ca.uhn.fhir.parser.IParser类的典型用法代码示例。如果您正苦于以下问题:Java IParser类的具体用法?Java IParser怎么用?Java IParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
IParser类属于ca.uhn.fhir.parser包,在下文中一共展示了IParser类的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());
}
}
示例2: validateFhirRequest
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
private FhirValidationResult validateFhirRequest(Contents contents) {
FhirValidationResult result = new FhirValidationResult();
FhirValidator validator = fhirContext.newValidator();
IParser parser = newParser(contents.contentType);
IBaseResource resource = parser.parseResource(contents.content);
ValidationResult vr = validator.validateWithResult(resource);
if (vr.isSuccessful()) {
result.passed = true;
} else {
result.passed = false;
result.operationOutcome = vr.toOperationOutcome();
}
return result;
}
示例3: convertBodyForUpstream
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
private Contents convertBodyForUpstream(Contents contents) {
String targetContentType = determineTargetContentType(contents.contentType);
if ("Client".equalsIgnoreCase(upstreamFormat) || isUpstreamAndClientFormatsEqual(contents.contentType)) {
return new Contents(targetContentType, contents.content);
}
log.info("[" + openhimTrxID + "] Converting request body to " + targetContentType);
IParser inParser = newParser(contents.contentType);
IBaseResource resource = inParser.parseResource(contents.content);
if ("JSON".equalsIgnoreCase(upstreamFormat) || "XML".equalsIgnoreCase(upstreamFormat)) {
IParser outParser = newParser(targetContentType);
String converted = outParser.setPrettyPrint(true).encodeResourceToString(resource);
return new Contents(targetContentType, converted);
} else {
requestHandler.tell(new ExceptError(new RuntimeException("Unknown upstream format specified " + upstreamFormat)), getSelf());
return null;
}
}
示例4: main
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
public static void main(String[] theArgs) {
Patient pat = new Patient();
pat.addName().setFamily("Simpson").addGiven("Homer").addGiven("J");
// Add an extension on the resource
pat.addExtension()
.setUrl("http://hl7.org/fhir/StructureDefinition/patient-importance")
.setValue(new CodeableConcept().setText("Patient is a VIP"));
// Add an extension on a primitive
pat.getBirthDateElement().setValueAsString("1955-02-22");
pat.getBirthDateElement().addExtension()
.setUrl("http://hl7.org/fhir/StructureDefinition/patient-birthTime")
.setValue(new TimeType("23:30"));
IParser parser = FhirContext.forDstu3().newJsonParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(pat));
}
示例5: main
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
public static void main(String[] args) {
String input = "<Encounter xmlns=\"http://hl7.org/fhir\"></Encounter>";
// Create a new validator
FhirContext ctx = FhirContext.forDstu3();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(input);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
示例6: main
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
public static void main(String[] args) {
// Create an incomplete encounter (status is required)
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345");
// Create a new validator
FhirContext ctx = FhirContext.forDstu3();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(enc);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
示例7: main
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
public static void main(String[] args) {
// Create an incomplete encounter (status is required)
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345");
// Create a new validator
FhirValidator validator = FhirContext.forDstu3().newValidator();
// Cache this object! Supplies structure definitions
DefaultProfileValidationSupport support = new DefaultProfileValidationSupport();
// Create the validator
FhirInstanceValidator module = new FhirInstanceValidator(support);
validator.registerValidatorModule(module);
// Did we succeed?
IParser parser = FhirContext.forDstu3().newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(validator.validateWithResult(enc).toOperationOutcome()));
}
示例8: 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);
}
示例9: invokeClient
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
@Override
public BaseOperationOutcome invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws IOException,
BaseServerResponseException {
EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType);
if (respType == null) {
return null;
}
IParser parser = respType.newParser(myContext);
BaseOperationOutcome retVal;
try {
// TODO: handle if something else than OO comes back
retVal = (BaseOperationOutcome) parser.parseResource(theResponseReader);
} catch (DataFormatException e) {
ourLog.warn("Failed to parse OperationOutcome response", e);
return null;
}
MethodUtil.parseClientRequestResourceHeaders(null, theHeaders, retVal);
return retVal;
}
示例10: createAppropriateParserForParsingServerRequest
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
protected IParser createAppropriateParserForParsingServerRequest(Request theRequest) {
String contentTypeHeader = theRequest.getServletRequest().getHeader("content-type");
EncodingEnum encoding;
if (isBlank(contentTypeHeader)) {
encoding = EncodingEnum.XML;
} else {
int semicolon = contentTypeHeader.indexOf(';');
if (semicolon != -1) {
contentTypeHeader = contentTypeHeader.substring(0, semicolon);
}
encoding = EncodingEnum.forContentType(contentTypeHeader);
}
if (encoding == null) {
throw new InvalidRequestException("Request contins non-FHIR conent-type header value: " + contentTypeHeader);
}
IParser parser = encoding.newParser(getContext());
return parser;
}
示例11: 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());
}
示例12: main
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
IParser parser = new FhirContext(Profile.class).newXmlParser();
ProfileParser pp = new ProfileParser("dev",".");
String str = IOUtils.toString(new FileReader("../hapi-tinder-test/src/test/resources/profile/organization.xml"));
Profile prof = parser.parseResource(Profile.class, str);
pp.parseSingleProfile(prof, "http://foo");
str = IOUtils.toString(new FileReader("../hapi-tinder-test/src/test/resources/profile/patient.xml"));
prof = parser.parseResource(Profile.class, str);
pp.parseSingleProfile(prof, "http://foo");
pp.markResourcesForImports();
pp.writeAll(new File("target/gen/test/resource"), null,"test");
}
示例13: 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);
}
示例14: main
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
public static void main(String[] args) {
// Create an encounter with an invalid status and no class
Encounter enc = new Encounter();
enc.getStatus().setValueAsString("invalid_status");
// Create a new validator
FhirContext ctx = new FhirContext();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(enc);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = result.getOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
示例15: testConformance
import ca.uhn.fhir.parser.IParser; //导入依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void testConformance() throws Exception {
IParser p = ourCtx.newXmlParser();
Conformance conf = new Conformance();
conf.setCopyright("COPY");
final String respString = p.encodeResourceToString(conf);
ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8";
ourResponseBody = respString;
IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir");
Conformance resp = (Conformance) client.capabilities().ofType(Conformance.class).execute();
assertEquals("http://localhost:" + ourPort + "/fhir/metadata", ourRequestUri);
assertEquals("COPY", resp.getCopyright());
assertEquals("GET", ourRequestMethod);
}