use of org.hl7.fhir.r5.model.ListResource in project gpconnect-demonstrator by nhsconnect.
the class WarningCodeExtHelper method addWarningCodeExtensions.
/**
* confidential items are per record but the other two are global values per
* patient
*
* @param warningCodes
* @param list
* @param patientRepository
* @param medicationStatementRepository
* @param structuredAllergySearch
*/
public static void addWarningCodeExtensions(Set<String> warningCodes, ListResource list, PatientRepository patientRepository, MedicationStatementRepository medicationStatementRepository, StructuredAllergySearch structuredAllergySearch) {
String NHS = list.getSubject().getIdentifier().getValue();
PatientEntity patientEntity = patientRepository.findByNhsNumber(NHS);
List<MedicationStatementEntity> medicationStatements = medicationStatementRepository.findByPatientId(patientEntity.getId());
for (MedicationStatementEntity medicationStatement : medicationStatements) {
setFlags(medicationStatement.getWarningCode());
}
List<StructuredAllergyIntoleranceEntity> allergies = structuredAllergySearch.getAllergyIntollerence(NHS);
for (StructuredAllergyIntoleranceEntity allergy : allergies) {
setFlags(allergy.getWarningCode());
}
// check medication_statements for either of the global flags
if (dataInTransit) {
warningCodes.add(DATA_IN_TRANSIT);
}
if (dataAwaitingFiling) {
warningCodes.add(DATA_AWAITING_FILING);
}
StringBuilder sb = new StringBuilder();
warningCodes.forEach(warningCode -> {
if (warningCode != null) {
String warningCodeDisplay = "";
Annotation annotation = new Annotation();
switch(warningCode) {
case CONFIDENTIAL_ITEMS:
warningCodeDisplay = "Confidential Items";
// #266
annotation.setText(CONFIDENTIAL_ITEMS_NOTE);
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
case DATA_IN_TRANSIT:
warningCodeDisplay = "Data in Transit";
Calendar cal = new GregorianCalendar();
Date now = new Date();
cal.setTime(now);
// a week before now
cal.add(Calendar.DAY_OF_YEAR, -7);
// #266
annotation.setText(String.format(DATA_IN_TRANSIT_NOTE, DATE_FORMAT.format(cal.getTime())));
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
case DATA_AWAITING_FILING:
warningCodeDisplay = "Data Awaiting Filing";
// #266
annotation.setText(DATA_AWAITING_FILING_NOTE);
// list.addNote(annotation);
sb.append("\r\n").append(annotation.getText());
break;
default:
break;
}
// #182
Extension warningExt = new Extension(SystemURL.WARNING_CODE, new CodeType(warningCode));
list.addExtension(warningExt);
}
});
// cardinality of note 0..1 #266
if (sb.length() > 0) {
Annotation annotation = null;
if (list.getNote().size() > 0) {
annotation = list.getNote().get(0);
annotation.setText(annotation.getText());
annotation.setText(annotation.getText() + sb.toString());
} else {
annotation = new Annotation();
list.addNote(annotation);
annotation.setText(sb.toString().replaceFirst("^\r\n", ""));
}
}
}
use of org.hl7.fhir.r5.model.ListResource in project kindling by HL7.
the class SpreadSheetReloader method processOperations.
private void processOperations(XSSFWorkbook excel) throws IOException {
ListResource list = (ListResource) parseXml(fnOperations());
XSSFSheet src = getSheet(excel, SN_OPERATIONS);
XSSFSheet bindings = getSheet(excel, SN_BINDINGS);
list.getEntry().clear();
XSSFRow cols = src.getRow(0);
OperationDefinition opd = null;
Map<String, OperationDefinitionParameterComponent> params = new HashMap<>();
for (int i = 1; i <= src.getLastRowNum(); i++) {
XSSFRow row = src.getRow(i);
if (row != null && hasValue(row, cols, CN_NAME)) {
String name = getValue(row, cols, CN_NAME);
if (name == null || !name.contains(".")) {
if (opd != null) {
saveXml(fnOpDef(resourceName + "-" + opd.getCode()), opd);
}
opd = processOperation(row, cols, name, list.getEntry());
moveParams(opd, params);
list.addEntry().getItem().setReference("OperationDefinition/" + resourceName + "-" + opd.getCode());
} else {
processOperationParameter(row, cols, name, opd, params, bindings);
}
}
}
if (opd != null) {
saveXml(fnOpDef(resourceName + "-" + opd.getCode()), opd);
}
saveXml(fnOperations(), list);
}
use of org.hl7.fhir.r5.model.ListResource in project kindling by HL7.
the class SpreadSheetReloader method processExamples.
private void processExamples(XSSFWorkbook excel) throws FHIRFormatError, FileNotFoundException, IOException {
ListResource list = (ListResource) parseXml(fnOperations());
XSSFSheet src = getSheet(excel, SN_SEARCH);
List<ListResourceEntryComponent> oldEx = list.getEntry();
list.setEntry(new ArrayList<>());
XSSFRow cols = src.getRow(0);
for (int i = 1; i < src.getLastRowNum(); i++) {
XSSFRow row = src.getRow(i);
if (row != null && hasValue(row, cols, CN_NAME)) {
String c = getValue(row, cols, CN_NAME);
ListResourceEntryComponent li = getExample(oldEx, c);
list.addEntry(li);
readExample(row, cols, li);
}
}
}
use of org.hl7.fhir.r5.model.ListResource in project kindling by HL7.
the class SpreadSheetReloader method processPacks.
private void processPacks(XSSFWorkbook excel) throws FHIRFormatError, FileNotFoundException, IOException {
ListResource list = (ListResource) parseXml(fnPacks());
list.getEntry().clear();
for (int i = 0; i < excel.getNumberOfSheets(); i++) {
XSSFSheet sheet = excel.getSheetAt(i);
if (sheet.getSheetName().startsWith("Pack ")) {
String n = sheet.getSheetName().substring(5);
list.addEntry().getItem().setReference("ImplementationGuide/" + resourceName + "-" + n);
processPack(sheet, n);
}
}
saveXml(fnPacks(), list);
}
use of org.hl7.fhir.r5.model.ListResource in project kindling by HL7.
the class SpreadSheetCreator method addPacks.
private void addPacks(XSSFWorkbook excel) throws FHIRFormatError, FileNotFoundException, IOException {
ListResource list = (ListResource) parseXml(fnPacks());
list.setText(null);
for (ListResourceEntryComponent li : list.getEntry()) {
String ref = li.getItem().getReference();
ref = ref.substring(ref.indexOf("/") + 1);
String id = ref.contains("-") ? ref.substring(ref.indexOf("-") + 1) : ref;
XSSFSheet sheet = excel.createSheet("Pack " + id);
addPackColumns(sheet);
addPack(sheet, ref);
}
}
Aggregations