While expanding your server with custom logic you will need to work with resources directly.
To do so you can take advantage of built-in KeFHIR main services.
Provides possibility to read, save and delete resources.
Main methods overview:
ResourceVersion save(id, content, interaction)
ResourceVersion load(reference)
ResourceVersion load(id)
void delete(id)
This service provides api for parsing and composing resources from/to representation formats (json, xml).
ResourceContent compose(resource, format)
Resource parse(content)
Note that parse
will automatically detect format.
Simple usage example:
@Inject
private ResourceService resourceService;
@Inject
private ResourceFormatService resourceFormatService;
public void updateMedicationRequestStatus(ResourceId id) {
ResourceVersion mrVersion = resourceService.load(id);
MedicationRequest mr = resourceFormatService.parse(mrVersion.getContent().getValue());
mr.setStatus(MedicationRequestStatus.CANCELLED);
resourceService.save(id, resourceFormatService.compose(mr, "json"), InteractionType.UPDATE);
}
Ideally this service should solve all your searching requirements.
SearchResult search(resourceType, String... params)
SearchResult search(resourceType, Map params)
SearchResult search(SearchCriterion criteria)
params
arguments should be formed accordingly to FHIR search specification
Examples:
SearchResult r = resourceSearchService.search(ResourceType.Patient.name(), "_count", "30", "name", "Albert");
Map<String, List<String>> params = new HashMap<>();
params.put("target:MedicationRequest", List.of("111", "222", "333"));
params.put("end", List.of("gt" + DateUtil.format(new Date(), DateUtil.ISO_DATETIME)));
return resourceSearchService.search(ResourceType.Provenance.name(), params);
More examples:
Patient $everything operation
Conformance initializer
Conformance setup is also available statically using this class.
See ConformanceHolder.get*
You can also listen to any conformance changes to rebuild caches or notify other services if needed.
Conformance will be available using ConformanceHolder
at this point.
interface ConformanceUpdateListener {
void updated();
}