Search in sources :

Example 1 with MedicationStatementEntity

use of uk.gov.hscic.medication.statement.MedicationStatementEntity in project gpconnect-demonstrator by nhsconnect.

the class MedicationResourceProvider method addMedicationStatement.

public MedicationStatementEntity addMedicationStatement(LinkedHashMap data) throws ParseException {
    String pattern = "yyyy-MM-dd";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    System.out.println(data);
    MedicationStatementEntity medicationStatementEntity = new MedicationStatementEntity();
    medicationStatementEntity.setDateAsserted(simpleDateFormat.parse("2017-06-12"));
    medicationStatementEntity.setDosageInstruction("Take with meals");
    medicationStatementEntity.setDosageText("Take 2 tablets every 4 hours");
    medicationStatementEntity.setEndDate(simpleDateFormat.parse("2018-06-12"));
    medicationStatementEntity.setLastIssueDate(simpleDateFormat.parse("2017-06-12"));
    medicationStatementEntity.setDosageLastChanged(simpleDateFormat.parse("2018-03-15"));
    medicationStatementEntity.setMedicationRequestId("1");
    // get from frontend
    medicationStatementEntity.setMedicationId(medicationRepository.getMedicationIdByName((String) data.get("medication")));
    // get from frontend
    medicationStatementEntity.setPatientId(patientRepository.getPatientIdByNhsNumbwer(String.valueOf(data.get("nhsNumber"))));
    return medicationStatementRepository.save(medicationStatementEntity);
}
Also used : MedicationStatementEntity(uk.gov.hscic.medication.statement.MedicationStatementEntity) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with MedicationStatementEntity

use of uk.gov.hscic.medication.statement.MedicationStatementEntity 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)

Aggregations

MedicationStatementEntity (uk.gov.hscic.medication.statement.MedicationStatementEntity)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Date (java.util.Date)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 PatientEntity (uk.gov.hscic.patient.details.PatientEntity)1 StructuredAllergyIntoleranceEntity (uk.gov.hscic.patient.structuredAllergyIntolerance.StructuredAllergyIntoleranceEntity)1