本文整理汇总了Java中ca.uhn.fhir.parser.IParser.parseResource方法的典型用法代码示例。如果您正苦于以下问题:Java IParser.parseResource方法的具体用法?Java IParser.parseResource怎么用?Java IParser.parseResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca.uhn.fhir.parser.IParser
的用法示例。
在下文中一共展示了IParser.parseResource方法的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: 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;
}
示例5: 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");
}
示例6: invokeClient
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public T invokeClient(String theResponseMimeType, Reader theResponseReader, int theResponseStatusCode, Map<String, List<String>> theHeaders) throws BaseServerResponseException {
EncodingEnum respType = EncodingEnum.forContentType(theResponseMimeType);
if (respType == null) {
throw NonFhirResponseException.newInstance(theResponseStatusCode, theResponseMimeType, theResponseReader);
}
IParser parser = respType.newParser(myContext);
RuntimeResourceDefinition type = myContext.getResourceDefinition("Parameters");
IBaseResource retVal = parser.parseResource(type.getImplementingClass(), theResponseReader);
BaseRuntimeChildDefinition paramChild = type.getChildByName("parameter");
BaseRuntimeElementCompositeDefinition<?> paramChildElem = (BaseRuntimeElementCompositeDefinition<?>) paramChild.getChildByName("parameter");
List<IBase> parameter = paramChild.getAccessor().getValues(retVal);
if (parameter == null || parameter.isEmpty()) {
return (T) myContext.getElementDefinition(myType).newInstance();
}
IBase param = parameter.get(0);
List<IBase> meta = paramChildElem.getChildByName("value[x]").getAccessor().getValues(param);
if (meta.isEmpty()) {
return (T) myContext.getElementDefinition(myType).newInstance();
}
return (T) meta.get(0);
}
示例7: create
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Override
public Object create(String modelId, Map<String, Object> valueMap) throws ClassNotFoundException {
Gson gson = new GsonBuilder().
registerTypeAdapter(Double.class, (JsonSerializer<Double>) (src, typeOfSrc, context) -> {
if (src == src.longValue())
return new JsonPrimitive(src.longValue());
return new JsonPrimitive(src);
}).create();
String json = gson.toJson(valueMap);
Class modelClass = Class.forName(modelId);
IParser fhirContextParser = FhirContext.forDstu3().newJsonParser();
return fhirContextParser.parseResource(modelClass, json);
}
示例8: convertResponseContents
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
private Contents convertResponseContents(String clientAccept, Contents responseContents) {
log.info("[" + openhimTrxID + "] Converting response body to " + clientAccept);
IParser inParser = newParser(responseContents.contentType);
IBaseResource resource = inParser.parseResource(responseContents.content);
IParser outParser = newParser(clientAccept);
String converted = outParser.setPrettyPrint(true).encodeResourceToString(resource);
return new Contents(clientAccept, converted);
}
示例9: main
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public static void main(String[] args) {
String input = "<Encounter xmlns=\"http://hl7.org/fhir\"><AAAA value=\"foo\"/></Encounter>";
IParser p = FhirContext.forDstu3().newXmlParser();
// Parse with (default) lenient error handler
p.setParserErrorHandler(new LenientErrorHandler());
p.parseResource(input);
// Parse with strict error handler
p.setParserErrorHandler(new StrictErrorHandler());
p.parseResource(input);
}
示例10: provideReferenceDefinition
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Override
public StructureDefinition provideReferenceDefinition(ElementDefinitionDt element) throws IOException {
String fileStr = element.getTypeFirstRep().getProfileFirstRep().getValue().substring(element.getTypeFirstRep().getProfileFirstRep().getValue().lastIndexOf('/') + 1) + ".xml";
File file = new File(structureFile.getParent(), fileStr);
if (!file.isFile()) {
return null;
}
IParser parser = context.newXmlParser();
return parser.parseResource(StructureDefinition.class, fileToContentString(file));
}
开发者ID:botunge,项目名称:hapi-fhir-forge-profile-converter,代码行数:11,代码来源:FileStructureDefinitionProvider.java
示例11: provideReferenceDefinition
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Override
public StructureDefinition provideReferenceDefinition(ElementDefinitionDt element) throws IOException {
String urlStr = element.getTypeFirstRep().getProfileFirstRep().getValue();
URL url = new URL(urlStr);
IParser parser = context.newXmlParser();
return parser.parseResource(StructureDefinition.class, urlToContentString(url));
}
开发者ID:botunge,项目名称:hapi-fhir-forge-profile-converter,代码行数:8,代码来源:UrlStructureDefinitionProvider.java
示例12: 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()));
}
}
示例13: parseMsg
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
public static void parseMsg() {
FhirContext ctx = FhirContext.forDstu1();
//START SNIPPET: parseMsg
// The following is an example Patient resource
String msgString = "<Patient xmlns=\"http://hl7.org/fhir\">"
+ "<text><status value=\"generated\" /><div xmlns=\"http://www.w3.org/1999/xhtml\">John Cardinal</div></text>"
+ "<identifier><system value=\"http://orionhealth.com/mrn\" /><value value=\"PRP1660\" /></identifier>"
+ "<name><use value=\"official\" /><family value=\"Cardinal\" /><given value=\"John\" /></name>"
+ "<gender><coding><system value=\"http://hl7.org/fhir/v3/AdministrativeGender\" /><code value=\"M\" /></coding></gender>"
+ "<address><use value=\"home\" /><line value=\"2222 Home Street\" /></address><active value=\"true\" />"
+ "</Patient>";
// The hapi context object is used to create a new XML parser
// instance. The parser can then be used to parse (or unmarshall) the
// string message into a Patient object
IParser parser = ctx.newXmlParser();
Patient patient = parser.parseResource(Patient.class, msgString);
// The patient object has accessor methods to retrieve all of the
// data which has been parsed into the instance.
String patientId = patient.getIdentifier().get(0).getValue();
String familyName = patient.getName().get(0).getFamily().get(0).getValue();
String gender = patient.getGender();
System.out.println(patientId); // PRP1660
System.out.println(familyName); // Cardinal
System.out.println(gender); // M
//END SNIPPET: parseMsg
}
示例14: loadResource
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
/**
* Returns the referenced resource, fetching it <b>if it has not already been loaded</b>. This method invokes the HTTP client to retrieve the resource unless it has already been loaded, or was a
* contained resource in which case it is simply returned.
*/
public IResource loadResource(IRestfulClient theClient) throws IOException {
if (myResource != null) {
return myResource;
}
IdDt resourceId = getReference();
if (resourceId == null) {
throw new IllegalStateException("Reference has no resource ID defined");
}
String resourceUrl = resourceId.getValue();
ourLog.debug("Loading resource at URL: {}", resourceUrl);
HttpClient httpClient = theClient.getHttpClient();
FhirContext context = theClient.getFhirContext();
if (!resourceUrl.startsWith("http")) {
resourceUrl = theClient.getServerBase() + resourceUrl;
}
HttpGet get = new HttpGet(resourceUrl);
HttpResponse response = httpClient.execute(get);
try {
// TODO: choose appropriate parser based on response CT
IParser parser = context.newXmlParser();
Reader responseReader = BaseClient.createReaderFromResponse(response);
myResource = parser.parseResource(responseReader);
} finally {
if (response instanceof CloseableHttpResponse) {
((CloseableHttpResponse) response).close();
}
}
return myResource;
}
示例15: parseRequestObject
import ca.uhn.fhir.parser.IParser; //导入方法依赖的package包/类
@Override
protected Object parseRequestObject(Request theRequest) throws IOException {
EncodingEnum encoding = RestfulServerUtils.determineRequestEncoding(theRequest);
IParser parser = encoding.newParser(getContext());
BufferedReader requestReader = theRequest.getServletRequest().getReader();
if (theRequest.getRequestType() == RequestTypeEnum.GET) {
return null;
}
Class<? extends IBaseResource> wantedResourceType = getContext().getResourceDefinition("Parameters").getImplementingClass();
return parser.parseResource(wantedResourceType, requestReader);
}