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", ""));
}
}
}
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;
}
Aggregations