use of org.hl7.fhir.dstu2016may.model.StructureMap in project Gravity-SDOH-Exchange-RI by FHIR.
the class TaskPollingService method demoRunQRThroughStructureMap.
/*
A TEST polling service, implemented during January 2022 Connectathon, that automatically runs questionnaireResponse
resources through a StructureMap. If any exception occurs - just ignore it.
*/
public void demoRunQRThroughStructureMap() {
log.info("Looking for TOP 3 Patient QuestionnaireResponse resources without derived Observations...");
// TODO use repository instead
Bundle tasksBundle = openEhrClient.search().forResource(QuestionnaireResponse.class).where(new StringClientParam(Constants.PARAM_PROFILE).matches().value(SDOHProfiles.QUESTIONNAIRE_RESPONSE)).revInclude(Observation.INCLUDE_DERIVED_FROM.setRecurse(false)).sort().descending(QuestionnaireResponse.AUTHORED).count(3).returnBundle(Bundle.class).execute();
List<QuestionnaireResponse> responses = FhirUtil.getFromBundle(tasksBundle, QuestionnaireResponse.class, Bundle.SearchEntryMode.MATCH);
Set<String> derivedFrom = FhirUtil.getFromBundle(tasksBundle, Observation.class, Bundle.SearchEntryMode.INCLUDE).stream().map(o -> o.getDerivedFromFirstRep().getReferenceElement().getIdPart()).collect(Collectors.toSet());
if (responses.size() != derivedFrom.size()) {
log.info("Found " + (responses.size() - derivedFrom.size()) + " QuestionnaireResponse resources without observations.");
List<QuestionnaireResponse> newResponses = responses.stream().filter(qr -> !derivedFrom.contains(qr.getIdElement().getIdPart())).collect(Collectors.toList());
for (QuestionnaireResponse nr : newResponses) {
log.info("Converting QuestionnaireResponse with id: " + nr.getIdElement().getIdPart());
try {
// TODO move parser logic within the convert service. Use resources instead
JSONParser parser = new JSONParser(JSONParser.MODE_JSON_SIMPLE);
Map<String, Object> result = convertService.convert((JSONObject) parser.parse(fhirContext.newJsonParser().encodeResourceToString(nr)));
Bundle bundle = (Bundle) fhirContext.newJsonParser().parseResource(new JSONObject(result).toJSONString());
bundle.getEntry().forEach(e -> e.setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.POST).setUrl(e.getResource().getClass().getSimpleName())));
openEhrClient.transaction().withBundle(bundle).execute();
} catch (Exception exc) {
// Just ignore this specific resource and go to the next one
log.warn(exc.getMessage(), exc);
}
}
}
log.info("QuestionnaireResponse update process finished.");
}
use of org.hl7.fhir.dstu2016may.model.StructureMap in project Gravity-SDOH-Exchange-RI by FHIR.
the class ConvertService method loadMapIg.
private void loadMapIg(String mapUri) throws IOException {
Path mapIg = Files.createTempDirectory("mapIg");
Optional<StructureMap> foundStructureMap = structureMapRepository.findByUrl(mapUri);
if (!foundStructureMap.isPresent()) {
throw new ResourceNotFoundException(String.format("StructureMap was not found by URL '%s'.", mapUri));
}
StructureMap structureMap = foundStructureMap.get();
File jsonMap = new File(mapIg.toString() + "/map.json");
jsonMap.createNewFile();
try (FileWriter fileWriter = new FileWriter(jsonMap)) {
fileWriter.write(fhirContext.newJsonParser().encodeResourceToString(structureMap));
fileWriter.flush();
}
validationEngine.loadIg(mapIg.toString(), false);
Files.delete(jsonMap.toPath());
Files.delete(mapIg);
}
use of org.hl7.fhir.dstu2016may.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class R2R3ConversionManager method convertToR3.
private void convertToR3(InputStream source, OutputStream dest, FhirFormat format) throws FHIRException, IOException {
org.hl7.fhir.dstu3.elementmodel.Element r2 = new org.hl7.fhir.dstu3.elementmodel.XmlParser(contextR2).parse(source);
StructureMap map = library.get("http://hl7.org/fhir/StructureMap/" + r2.fhirType() + "2to3");
if (map == null)
throw new FHIRException("No Map Found from R2 to R3 for " + r2.fhirType());
String tn = smu3.getTargetType(map).getType();
Resource r3 = ResourceFactory.createResource(tn);
smu3.transform(new TransformContextR2R3(contextR3, r2.getChildValue("id")), r2, map, r3);
FormatUtilities.makeParser(format).setOutputStyle(style).compose(dest, r3);
}
use of org.hl7.fhir.dstu2016may.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class R2R3ConversionManager method setMappingLibrary.
public void setMappingLibrary(InputStream stream) throws IOException, FHIRException {
needPrepare = true;
Map<String, InputStream> files = readInputStream(stream);
for (InputStream s : files.values()) {
StructureMap sm = new StructureMapUtilities(contextR3).parse(TextFile.streamToString(s));
library.put(sm.getUrl(), sm);
}
}
use of org.hl7.fhir.dstu2016may.model.StructureMap in project org.hl7.fhir.core by hapifhir.
the class PackageMaintainer method check.
private void check(String ver) throws IOException {
System.out.println("Check " + ver);
List<String> allIds = listResources(Utilities.path(PATH, "hl7.fhir." + ver + ".examples", "package"));
List<String> coreIds = listResources(Utilities.path(PATH, "hl7.fhir." + ver + ".core", "package"));
for (String s : coreIds) {
if (!allIds.contains(s)) {
System.out.println("Core contains " + s + " but allIds doesn't");
}
}
for (String s : allIds) {
if (!coreIds.contains(s)) {
String c = s.substring(0, s.indexOf("-"));
if (Utilities.existsInList(c, "CodeSystem", "ValueSet", "ConceptMap", "StructureDefinition", "StructureMap", "NamingSystem", "SearchParameter", "OperationDefinition", "CapabilityStatement", "Conformance"))
System.out.println("Examples contains " + s + " but core doesn't");
}
}
strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".core", "package")));
strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".expansions", "package")));
if (!ver.equals("r2b"))
strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".elements", "package")));
}
Aggregations