Search in sources :

Example 1 with ListResource

use of org.hl7.fhir.dstu3.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", ""));
        }
    }
}
Also used : StructuredAllergyIntoleranceEntity(uk.gov.hscic.patient.structuredAllergyIntolerance.StructuredAllergyIntoleranceEntity) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) Annotation(org.hl7.fhir.dstu3.model.Annotation) Date(java.util.Date) PatientEntity(uk.gov.hscic.patient.details.PatientEntity) MedicationStatementEntity(uk.gov.hscic.medication.statement.MedicationStatementEntity) Extension(org.hl7.fhir.dstu3.model.Extension) CodeType(org.hl7.fhir.dstu3.model.CodeType)

Example 2 with ListResource

use of org.hl7.fhir.dstu3.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);
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) HashMap(java.util.HashMap) ListResource(org.hl7.fhir.r5.model.ListResource) OperationDefinition(org.hl7.fhir.r5.model.OperationDefinition) OperationDefinitionParameterComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent)

Example 3 with ListResource

use of org.hl7.fhir.dstu3.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);
        }
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) ListResourceEntryComponent(org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent) ListResource(org.hl7.fhir.r5.model.ListResource)

Example 4 with ListResource

use of org.hl7.fhir.dstu3.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);
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) ListResource(org.hl7.fhir.r5.model.ListResource)

Example 5 with ListResource

use of org.hl7.fhir.dstu3.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);
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) ListResourceEntryComponent(org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent) ListResource(org.hl7.fhir.r5.model.ListResource)

Aggregations

ListResource (org.hl7.fhir.r5.model.ListResource)12 Element (org.w3c.dom.Element)12 ListResourceEntryComponent (org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent)11 ListResource (org.hl7.fhir.dstu3.model.ListResource)10 Reference (org.hl7.fhir.dstu3.model.Reference)10 ListEntryComponent (org.hl7.fhir.dstu3.model.ListResource.ListEntryComponent)9 ArrayList (java.util.ArrayList)8 ListResource (org.hl7.fhir.r4.model.ListResource)8 Reference (org.hl7.fhir.r4.model.Reference)6 HashMap (java.util.HashMap)5 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)5 SectionComponent (org.hl7.fhir.dstu3.model.Composition.SectionComponent)4 Patient (org.hl7.fhir.r4.model.Patient)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 List (java.util.List)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)2