use of org.hl7.fhir.r5.formats.IParser in project kindling by HL7.
the class CodeSystemConvertor method convert.
public void convert(IParser p, ValueSet vs, String name, PackageVersion packageInfo) throws Exception {
String nname = name.replace("valueset-", "codesystem-");
if (nname.equals(name))
nname = Utilities.changeFileExt(name, "-cs.xml");
if (new File(nname).exists()) {
FileInputStream input = new FileInputStream(nname);
CodeSystem cs = CodeSystemUtilities.makeShareable((CodeSystem) p.parse(input));
if (!cs.hasTitle())
cs.setTitle(Utilities.capitalize(Utilities.unCamelCase(cs.getName())));
populate(cs, vs);
// if (codeSystems.containsKey(cs.getUrl()))
// throw new Exception("Duplicate Code System: "+cs.getUrl());
codeSystems.see(cs, packageInfo);
}
}
use of org.hl7.fhir.r5.formats.IParser in project kindling by HL7.
the class Publisher method buildLoincExample.
private String buildLoincExample(String filename) throws FileNotFoundException, Exception {
LoincToDEConvertor conv = new LoincToDEConvertor();
conv.setDefinitions(Utilities.path(page.getFolders().srcDir, "loinc", "loincS.xml"));
conv.process();
IParser xml = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
FileOutputStream s = new FileOutputStream(Utilities.path(page.getFolders().dstDir, filename + ".xml"));
xml.compose(s, conv.getBundle());
s.close();
IParser json = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
s = new FileOutputStream(Utilities.path(page.getFolders().dstDir, filename + ".json"));
json.compose(s, conv.getBundle());
s.close();
return "Loinc Narrative";
}
use of org.hl7.fhir.r5.formats.IParser in project health-patterns by LinuxForHealth.
the class DeIdentifier method postBundle.
/**
* Posts the given Bundle to the FHIR server
*
* @param fhirBundle the bundle to post
* @return the FHIR response of executing the transaction Bundle
* @throws DeIdentifierException if there is a problem posting the bundle or parsing the response
*/
private JsonNode postBundle(JsonNode fhirBundle) throws DeIdentifierException {
System.out.println("Initializing FHIR transacton with Bundle...");
IParser parser = fhirClient.getFhirContext().newJsonParser();
Bundle bundle = parser.parseResource(Bundle.class, fhirBundle.toString());
Bundle resp;
try {
resp = fhirClient.transaction().withBundle(bundle).execute();
} catch (BaseServerResponseException e) {
throw new DeIdentifierException("The FHIR transaction could not be executed: " + e.getMessage(), e);
}
String jsonResponseString = parser.setPrettyPrint(true).encodeResourceToString(resp);
JsonNode jsonResponse;
try {
jsonResponse = jsonDeserializer.readTree(jsonResponseString);
} catch (JsonProcessingException e) {
throw new DeIdentifierException("The FHIR response JSON could not be parsed: " + e.getMessage(), e);
}
System.out.println("FHIR transacton with Bundle done!");
return jsonResponse;
}
use of org.hl7.fhir.r5.formats.IParser in project BridgeServer2 by Sage-Bionetworks.
the class CRCController method postProcedureRequest.
@PutMapping("/v1/cuimc/procedurerequests")
public ResponseEntity<StatusMessage> postProcedureRequest() {
App app = httpBasicAuthentication();
IParser parser = FHIR_CONTEXT.newJsonParser();
JsonNode data = parseJson(JsonNode.class);
ProcedureRequest procedure = parser.parseResource(ProcedureRequest.class, data.toString());
String userId = findUserId(procedure.getSubject());
int status = writeReportAndUpdateState(app, userId, data, PROCEDURE_REPORT, AccountStates.TESTS_COLLECTED, true);
if (status == 200) {
return ResponseEntity.ok(new StatusMessage("ProcedureRequest updated."));
}
return ResponseEntity.created(URI.create("/v1/cuimc/procedurerequests/" + userId)).body(new StatusMessage("ProcedureRequest created."));
}
use of org.hl7.fhir.r5.formats.IParser in project cqf-ruler by DBCG.
the class R4CarePlanToCdsCard method convert.
private static List<CdsCard> convert(RequestGroup requestGroup) {
List<CdsCard> cards = new ArrayList<>();
// links
List<CdsCard.Links> links = new ArrayList<>();
if (requestGroup.hasExtension()) {
for (Extension extension : requestGroup.getExtension()) {
CdsCard.Links link = new CdsCard.Links();
if (extension.getValue() instanceof Attachment) {
Attachment attachment = (Attachment) extension.getValue();
if (attachment.hasUrl()) {
link.setUrl(attachment.getUrl());
}
if (attachment.hasTitle()) {
link.setLabel(attachment.getTitle());
}
if (attachment.hasExtension()) {
link.setType(attachment.getExtensionFirstRep().getValue().primitiveValue());
}
} else {
throw new RuntimeException("Invalid link extension type: " + extension.getValue().fhirType());
}
links.add(link);
}
}
if (requestGroup.hasAction()) {
for (RequestGroup.RequestGroupActionComponent action : requestGroup.getAction()) {
IParser jsonParser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser().setPrettyPrint(true);
CdsCard card = new CdsCard(jsonParser);
// basic
if (action.hasTitle()) {
card.setSummary(action.getTitle());
}
if (action.hasDescription()) {
card.setDetail(action.getDescription());
}
if (action.hasExtension()) {
card.setIndicator(action.getExtensionFirstRep().getValue().toString());
}
// source
if (action.hasDocumentation()) {
// Assuming first related artifact has everything
RelatedArtifact documentation = action.getDocumentationFirstRep();
CdsCard.Source source = new CdsCard.Source();
if (documentation.hasDisplay()) {
source.setLabel(documentation.getDisplay());
}
if (documentation.hasUrl()) {
source.setUrl(documentation.getUrl());
}
if (documentation.hasDocument() && documentation.getDocument().hasUrl()) {
source.setIcon(documentation.getDocument().getUrl());
}
card.setSource(source);
}
if (action.hasSelectionBehavior()) {
card.setSelectionBehavior(action.getSelectionBehavior().toCode());
}
// suggestions
// TODO - uuid
boolean hasSuggestions = false;
CdsCard.Suggestions suggestions = new CdsCard.Suggestions();
CdsCard.Suggestions.Action actions = new CdsCard.Suggestions.Action();
if (action.hasPrefix()) {
suggestions.setLabel(action.getPrefix());
hasSuggestions = true;
if (action.hasDescription()) {
actions.setDescription(action.getDescription());
}
if (action.hasType() && !action.getType().getCodingFirstRep().getCode().equals("fire-event")) {
String code = action.getType().getCodingFirstRep().getCode();
actions.setType(CdsCard.Suggestions.Action.ActionType.valueOf(code.equals("remove") ? "delete" : code));
}
if (action.hasResource()) {
if (actions.getType().name().equalsIgnoreCase("create")) {
action.getResourceTarget().setId((String) null);
}
actions.setResource(action.getResourceTarget());
}
}
if (hasSuggestions) {
suggestions.addAction(actions);
card.addSuggestion(suggestions);
}
if (!links.isEmpty()) {
card.setLinks(links);
}
cards.add(card);
}
}
return cards;
}
Aggregations