use of org.hl7.fhir.dstu3.model.Patient in project gpconnect-demonstrator by nhsconnect.
the class MedicationAdministrationResourceProvider method getMedicationAdministrationsForPatientId.
@Search
public List<MedicationAdministration> getMedicationAdministrationsForPatientId(@RequiredParam(name = "patient") String patientId) {
ArrayList<MedicationAdministration> medicationAdministrations = new ArrayList<>();
List<MedicationAdministrationDetail> medicationAdministrationDetailList = medicationAdministrationSearch.findMedicationAdministrationForPatient(Long.parseLong(patientId));
if (medicationAdministrationDetailList != null && !medicationAdministrationDetailList.isEmpty()) {
for (MedicationAdministrationDetail medicationAdministrationDetail : medicationAdministrationDetailList) {
MedicationAdministration medicationAdministration = new MedicationAdministration();
String resourceId = String.valueOf(medicationAdministrationDetail.getId());
String versionId = String.valueOf(medicationAdministrationDetail.getLastUpdated().getTime());
String resourceType = medicationAdministration.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
medicationAdministration.setId(id);
medicationAdministration.getMeta().setVersionId(versionId);
medicationAdministration.getMeta().setLastUpdated(medicationAdministrationDetail.getLastUpdated());
medicationAdministration.addDefinition(new Reference("Patient/" + medicationAdministrationDetail.getPatientId()));
medicationAdministration.addDefinition(new Reference("Practitioner/" + medicationAdministrationDetail.getPractitionerId()));
medicationAdministration.setPrescription(new Reference("MedicationOrder/" + medicationAdministrationDetail.getPrescriptionId()));
medicationAdministration.setEffective(new DateType(medicationAdministrationDetail.getAdministrationDate()));
medicationAdministration.setMedication(new Reference("Medication/" + medicationAdministrationDetail.getMedicationId()));
medicationAdministrations.add(medicationAdministration);
}
}
return medicationAdministrations;
}
use of org.hl7.fhir.dstu3.model.Patient in project gpconnect-demonstrator by nhsconnect.
the class MedicationOrderResourceProvider method medicationOrderDetailsToMedicationOrderResourceConverter.
private MedicationRequest medicationOrderDetailsToMedicationOrderResourceConverter(MedicationOrderDetails medicationOrderDetails) {
MedicationRequest medicationOrder = new MedicationRequest();
String resourceId = String.valueOf(medicationOrderDetails.getId());
String versionId = String.valueOf(medicationOrderDetails.getLastUpdated().getTime());
String resourceType = medicationOrder.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
medicationOrder.setId(id);
medicationOrder.getMeta().setVersionId(versionId);
medicationOrder.getMeta().setLastUpdated(medicationOrderDetails.getLastUpdated());
switch(medicationOrderDetails.getOrderStatus().toLowerCase(Locale.UK)) {
case "active":
medicationOrder.setStatus(MedicationRequestStatus.ACTIVE);
break;
case "completed":
medicationOrder.setStatus(MedicationRequestStatus.COMPLETED);
break;
case "draft":
medicationOrder.setStatus(MedicationRequestStatus.DRAFT);
break;
case "entered_in_error":
medicationOrder.setStatus(MedicationRequestStatus.ENTEREDINERROR);
break;
case "on_hold":
medicationOrder.setStatus(MedicationRequestStatus.ONHOLD);
break;
case "stopped":
medicationOrder.setStatus(MedicationRequestStatus.STOPPED);
break;
}
if (medicationOrderDetails.getPatientId() != null) {
medicationOrder.setSubject(new Reference("Patient/" + medicationOrderDetails.getPatientId()));
} else {
medicationOrder.setSubject(new Reference());
}
medicationOrder.setRecorder(new Reference("Practitioner/" + medicationOrderDetails.getAutherId()));
medicationOrder.setMedication(new Reference("Medication/" + medicationOrderDetails.getMedicationId()));
medicationOrder.addDosageInstruction().setText(medicationOrderDetails.getDosageText());
MedicationRequestDispenseRequestComponent dispenseRequest = new MedicationRequestDispenseRequestComponent();
dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_MEDICATION_QUANTITY_TEXT, new StringDt(medicationOrderDetails.getDispenseQuantityText())));
dispenseRequest.addExtension(new Extension(SystemURL.SD_EXTENSION_PERSCRIPTION_REPEAT_REVIEW_DATE, new DateTimeDt(medicationOrderDetails.getDispenseReviewDate())));
dispenseRequest.setId("Medication/" + medicationOrderDetails.getDispenseMedicationId());
dispenseRequest.setNumberOfRepeatsAllowed(medicationOrderDetails.getDispenseRepeatsAllowed());
medicationOrder.setDispenseRequest(dispenseRequest);
return medicationOrder;
}
use of org.hl7.fhir.dstu3.model.Patient in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method validateNames.
private void validateNames(Patient patient) {
List<HumanName> names = patient.getName();
if (names.size() < 1) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("The patient must have at least one Name."), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
List<HumanName> activeOfficialNames = names.stream().filter(nm -> IsActiveName(nm)).filter(nm -> NameUse.OFFICIAL.equals(nm.getUse())).collect(Collectors.toList());
if (activeOfficialNames.size() != 1) {
InvalidRequestException exception = new InvalidRequestException("The patient must have one Active Name with a Use of OFFICIAL");
throw OperationOutcomeFactory.buildOperationOutcomeException(exception, SystemCode.BAD_REQUEST, IssueType.INVALID);
}
List<String> officialFamilyNames = new ArrayList<>();
for (HumanName humanName : activeOfficialNames) {
if (humanName.getFamily() != null) {
officialFamilyNames.add(humanName.getFamily());
}
}
validateNameCount(officialFamilyNames, "family");
}
use of org.hl7.fhir.dstu3.model.Patient in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method valiateGender.
private void valiateGender(Patient patient) {
AdministrativeGender gender = patient.getGender();
if (gender != null) {
EnumSet<AdministrativeGender> genderList = EnumSet.allOf(AdministrativeGender.class);
Boolean valid = false;
for (AdministrativeGender genderItem : genderList) {
if (genderItem.toCode().equalsIgnoreCase(gender.toString())) {
valid = true;
break;
}
}
if (!valid) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException(String.format("The supplied Patient gender %s is an unrecognised type.", gender)), SystemCode.BAD_REQUEST, IssueType.INVALID);
}
}
}
use of org.hl7.fhir.dstu3.model.Patient in project gpconnect-demonstrator by nhsconnect.
the class PatientResourceProvider method setStaticPatientData.
private Patient setStaticPatientData(Patient patient) {
patient.setLanguage(("en-GB"));
patient.addExtension(createCodingExtension("CG", "Greek Cypriot", SystemURL.CS_CC_ETHNIC_CATEGORY, SystemURL.SD_CC_EXT_ETHNIC_CATEGORY));
patient.addExtension(createCodingExtension("SomeSnomedCode", "Some Snomed Code", SystemURL.CS_CC_RELIGIOUS_AFFILI, SystemURL.SD_CC_EXT_RELIGIOUS_AFFILI));
patient.addExtension(new Extension(SystemURL.SD_PATIENT_CADAVERIC_DON, new BooleanType(false)));
patient.addExtension(createCodingExtension("H", "UK Resident", SystemURL.CS_CC_RESIDENTIAL_STATUS, SystemURL.SD_CC_EXT_RESIDENTIAL_STATUS));
patient.addExtension(createCodingExtension("3", "To pay hotel fees only", SystemURL.CS_CC_TREATMENT_CAT, SystemURL.SD_CC_EXT_TREATMENT_CAT));
Extension nhsCommExtension = new Extension();
nhsCommExtension.setUrl(SystemURL.SD_CC_EXT_NHS_COMMUNICATION);
nhsCommExtension.addExtension(createCodingExtension("en", "English", SystemURL.CS_CC_HUMAN_LANG, SystemURL.SD_CC_EXT_COMM_LANGUAGE));
nhsCommExtension.addExtension(new Extension(SystemURL.SD_CC_COMM_PREFERRED, new BooleanType(false)));
nhsCommExtension.addExtension(createCodingExtension("RWR", "Received written", SystemURL.CS_CC_LANG_ABILITY_MODE, SystemURL.SD_CC_MODE_OF_COMM));
nhsCommExtension.addExtension(createCodingExtension("E", "Excellent", SystemURL.CS_CC_LANG_ABILITY_PROFI, SystemURL.SD_CC_COMM_PROFICIENCY));
nhsCommExtension.addExtension(new Extension(SystemURL.SD_CC_INTERPRETER_REQUIRED, new BooleanType(false)));
patient.addExtension(nhsCommExtension);
Identifier localIdentifier = new Identifier();
localIdentifier.setUse(IdentifierUse.USUAL);
localIdentifier.setSystem(SystemURL.ID_LOCAL_PATIENT_IDENTIFIER);
localIdentifier.setValue("123456");
CodeableConcept liType = new CodeableConcept();
Coding liTypeCoding = new Coding();
liTypeCoding.setCode("EN");
liTypeCoding.setDisplay("Employer number");
liTypeCoding.setSystem(SystemURL.VS_IDENTIFIER_TYPE);
liType.addCoding(liTypeCoding);
localIdentifier.setType(liType);
localIdentifier.setAssigner(new Reference("Organization/1"));
patient.addIdentifier(localIdentifier);
Calendar calendar = Calendar.getInstance();
calendar.set(2017, 1, 1);
DateTimeDt endDate = new DateTimeDt(calendar.getTime());
calendar.set(2016, 1, 1);
DateTimeDt startDate = new DateTimeDt(calendar.getTime());
Period pastPeriod = new Period().setStart(calendar.getTime()).setEnd(calendar.getTime());
patient.addName().setFamily("AnotherOfficialFamilyName").addGiven("AnotherOfficialGivenName").setUse(NameUse.OFFICIAL).setPeriod(pastPeriod);
patient.addName().setFamily("AdditionalFamily").addGiven("AdditionalGiven").setUse(NameUse.TEMP);
patient.addTelecom(staticElHelper.getValidTelecom());
patient.addAddress(staticElHelper.getValidAddress());
return patient;
}
Aggregations