Search in sources :

Example 1 with ICondition

use of ch.elexis.core.findings.ICondition in project elexis-server by elexis.

the class ConditionResourceProvider method createCondition.

@Create
public MethodOutcome createCondition(@ResourceParam Condition condition) {
    MethodOutcome outcome = new MethodOutcome();
    Optional<ICondition> exists = getTransformer().getLocalObject(condition);
    if (exists.isPresent()) {
        outcome.setCreated(false);
        outcome.setId(new IdType(condition.getId()));
    } else {
        Optional<ICondition> created = getTransformer().createLocalObject(condition);
        if (created.isPresent()) {
            outcome.setCreated(true);
            outcome.setId(new IdType(created.get().getId()));
        } else {
            throw new InternalErrorException("Creation failed");
        }
    }
    return outcome;
}
Also used : InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) ICondition(ch.elexis.core.findings.ICondition) IdType(org.hl7.fhir.r4.model.IdType) Create(ca.uhn.fhir.rest.annotation.Create)

Example 2 with ICondition

use of ch.elexis.core.findings.ICondition in project elexis-server by elexis.

the class MigratorService method migratePatientCondition.

/**
 * Migrate the existing diagnose text of a patient to an {@link ICondition} instance. Migration
 * is only performed if there is not already a diagnose in form of an {@link ICondition} present
 * for the patient.
 *
 * @param patientId
 */
private void migratePatientCondition(String patientId) {
    Optional<IPatient> patient = CoreModelServiceHolder.get().load(patientId, IPatient.class);
    patient.ifPresent(p -> {
        String diagnosis = p.getDiagnosen();
        if (diagnosis != null && !diagnosis.isEmpty()) {
            List<ICondition> conditions = findingsService.getPatientsFindings(patientId, ICondition.class);
            conditions = conditions.stream().filter(iFinding -> isDiagnose(iFinding)).collect(Collectors.toList());
            if (conditions.isEmpty()) {
                ICondition condition = findingsService.create(ICondition.class);
                condition.setPatientId(patientId);
                condition.setCategory(ConditionCategory.PROBLEMLISTITEM);
                condition.setText(diagnosis);
                findingsService.saveFinding(condition);
            }
        }
    });
}
Also used : IPatient(ch.elexis.core.model.IPatient) ICondition(ch.elexis.core.findings.ICondition)

Example 3 with ICondition

use of ch.elexis.core.findings.ICondition in project elexis-server by elexis.

the class ConditionResourceProvider method findCondition.

@Search()
public List<Condition> findCondition(@RequiredParam(name = Condition.SP_SUBJECT) IdType thePatientId, @OptionalParam(name = Condition.SP_CATEGORY) CodeType categoryCode) {
    if (thePatientId != null && !thePatientId.isEmpty()) {
        Optional<IPatient> patient = modelService.load(thePatientId.getIdPart(), IPatient.class);
        if (patient.isPresent()) {
            if (patient.get().isPatient()) {
                // migrate diagnose condition first
                migratorService.migratePatientsFindings(thePatientId.getIdPart(), ICondition.class, null);
                List<ICondition> findings = findingsService.getPatientsFindings(thePatientId.getIdPart(), ICondition.class);
                if (findings != null && !findings.isEmpty()) {
                    List<Condition> ret = new ArrayList<Condition>();
                    for (ICondition iFinding : findings) {
                        if (categoryCode != null && !isConditionCategory(iFinding, categoryCode)) {
                            continue;
                        }
                        Optional<Condition> fhirEncounter = getTransformer().getFhirObject(iFinding);
                        fhirEncounter.ifPresent(fe -> ret.add(fe));
                    }
                    return ret;
                }
            }
        }
    }
    return Collections.emptyList();
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) ICondition(ch.elexis.core.findings.ICondition) ArrayList(java.util.ArrayList) IPatient(ch.elexis.core.model.IPatient) ICondition(ch.elexis.core.findings.ICondition) Search(ca.uhn.fhir.rest.annotation.Search)

Aggregations

ICondition (ch.elexis.core.findings.ICondition)3 IPatient (ch.elexis.core.model.IPatient)2 Create (ca.uhn.fhir.rest.annotation.Create)1 Search (ca.uhn.fhir.rest.annotation.Search)1 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)1 InternalErrorException (ca.uhn.fhir.rest.server.exceptions.InternalErrorException)1 ArrayList (java.util.ArrayList)1 Condition (org.hl7.fhir.r4.model.Condition)1 IdType (org.hl7.fhir.r4.model.IdType)1