Search in sources :

Example 1 with PatientEntity

use of uk.gov.hscic.patient.details.PatientEntity 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 PatientEntity

use of uk.gov.hscic.patient.details.PatientEntity in project gpconnect-demonstrator by nhsconnect.

the class RefreshData method createAppointment.

/**
 * only used to set up the first two appointments on start up
 *
 * @param slot
 * @param description
 * @return
 */
private AppointmentDetail createAppointment(SlotDetail slot, String description) {
    AppointmentDetail appointment = new AppointmentDetail();
    appointment.setDescription(description);
    appointment.setStartDateTime(slot.getStartDateTime());
    appointment.setEndDateTime(slot.getEndDateTime());
    appointment.setStatus("booked");
    appointment.setPriority(0);
    appointment.setMinutesDuration(10);
    // beware spring does not strip trailing blanks from property values
    PatientEntity patient = patientStore.findByNhsNumber(patient2NhsNo.trim());
    appointment.setPatientId(patient.getId());
    ScheduleDetail schedule = scheduleStore.findSchedule(slot.getScheduleReference());
    appointment.setPractitionerId(schedule.getPractitionerId());
    appointment.setLocationId(schedule.getLocationId());
    appointment.setLastUpdated(new Date());
    BookingOrgDetail bookingOrgDetail = new BookingOrgDetail();
    bookingOrgDetail.setOrgCode("A20047");
    bookingOrgDetail.setName("Dr Legg's Surgery");
    bookingOrgDetail.setTelephone("0300 303 5678");
    bookingOrgDetail.setSystem("PHONE");
    appointment.setBookingOrganization(bookingOrgDetail);
    return appointment;
}
Also used : PatientEntity(uk.gov.hscic.patient.details.PatientEntity) BookingOrgDetail(uk.gov.hscic.model.appointment.BookingOrgDetail) AppointmentDetail(uk.gov.hscic.model.appointment.AppointmentDetail) ScheduleDetail(uk.gov.hscic.model.appointment.ScheduleDetail) Date(java.util.Date)

Aggregations

Date (java.util.Date)2 PatientEntity (uk.gov.hscic.patient.details.PatientEntity)2 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Annotation (org.hl7.fhir.dstu3.model.Annotation)1 CodeType (org.hl7.fhir.dstu3.model.CodeType)1 Extension (org.hl7.fhir.dstu3.model.Extension)1 MedicationStatementEntity (uk.gov.hscic.medication.statement.MedicationStatementEntity)1 AppointmentDetail (uk.gov.hscic.model.appointment.AppointmentDetail)1 BookingOrgDetail (uk.gov.hscic.model.appointment.BookingOrgDetail)1 ScheduleDetail (uk.gov.hscic.model.appointment.ScheduleDetail)1 StructuredAllergyIntoleranceEntity (uk.gov.hscic.patient.structuredAllergyIntolerance.StructuredAllergyIntoleranceEntity)1