Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

To add another object to FHIR synchronization, you must implement the FHIR Strategy Pattern

To do this, Firstly you need to create GenericObjectnameStrategy interface if you wish to synchronize Objectname object

...

After that, the interface, by default needs to be implemented by ObjectnameStrategy class that would contain concrete implementatons of method stubsmethods.

A Strategy Util class, like ObjectNameStrategyUtil  should be created next to retrieve the implemented strategy in the following way:

...


When all these classes are created in the FHIR code, the ObjectName object is prepared to be mapped by FHIR
But, to enable the synchronization, a Client Helper needs to be created.
To do this, an interface ObjectNameHelper needs to be created:


package org.openmrs.module.fhir.api.helper;

import org.hl7.fhir.dstu3.model.ObjectName;
import org.openmrs.ObjectName;

public interface ObsHelper {

Observation.ObservationStatus getObsStatus(Obs obs);

void setStatus(Obs obs, Observation.ObservationStatus status);

CodeableConcept getInterpretation(Obs obs);

void setInterpretation(Obs obs, CodeableConcept interpretation);
}


and implemented accordingly.
Also, in the FHIRClientHelper class, CATEGOY CATEGORY_OBJECT_NAME needs to be added to the CATEGORY_MAP:


CATEGORY_MAP.put(CATEGORY_DRUG_ORDER, MedicationRequest.class);

and handled in the compareResourceObjects:

Code Block
@Override
public boolean compareResourceObjects(String category, Object from, Object dest) {
   boolean result;
   switch (category) {
      case CATEGORY_PATIENT:
         result = FHIRPatientUtil.compareCurrentPatients(dest, from);
         break;
      case CATEGORY_ENCOUNTER:
         result = FHIREncounterUtil.compareCurrentEncounters(dest, from);
         break;
      case CATEGORY_VISIT:
         result = FHIREncounterUtil.compareCurrentEncounters(dest, from);
         break;
      case CATEGORY_OBSERVATION:
         result = FHIRObsUtil.compareCurrentObs(dest, from);
         break;
      case CATEGORY_ALLERGY:
         result = FHIRAllergyIntoleranceUtil.areAllergiesEquals(dest, from);
         break;
      case CATEGORY_PERSON:
         result = FHIRPersonUtil.arePersonsEquals(dest, from);
         break;
      case CATEGORY_COHORT:
         result = FHIRGroupUtil.areGroupsEquals(dest, from);
         break;
      case CATEGORY_DRUG_ORDER:
         result = FHIRMedicationRequestUtil.areMedicationRequestsEquals(dest, from);
         break;
      case CATEGORY_TEST_ORDER:
         result = FHIRProcedureRequestUtil.areProcedureRequestsEqual(dest, from);
         break;
      default:
         result = dest.equals(from);
   }
   return result;
}


And ConvertToOpenMRSObject

Code Block
@Override
public Object convertToOpenMrsObject(Object object, String category) throws NotSupportedException {
   List<String> errors = new ArrayList<>();
   Object result;
   switch (category) {
      case CATEGORY_LOCATION:
         result = FHIRLocationUtil.generateOpenMRSLocation((Location) object, errors);
         break;
      case CATEGORY_OBSERVATION:
         result = FHIRObsUtil.generateOpenMRSObs((Observation) object, errors);
         break;
      case CATEGORY_ENCOUNTER:
         result = FHIREncounterUtil.generateOMRSEncounter((Encounter) object, errors);
         break;
      case CATEGORY_VISIT:
         result = FHIRVisitUtil.generateOMRSVisit((Encounter) object, errors);
         break;
      case CATEGORY_DRUG_ORDER:
         result = FHIRMedicationRequestUtil.generateDrugOrder((MedicationRequest) object,
               errors);
         break;
      case CATEGORY_TEST_ORDER:
         result = FHIRProcedureRequestUtil.generateTestOrder((ProcedureRequest) object,
               errors);
         break;
      case CATEGORY_PERSON:
         result = FHIRPersonUtil.generateOpenMRSPerson((Person) object, errors);
         break;
      case CATEGORY_PATIENT:
         result = FHIRPatientUtil.generateOmrsPatient((Patient) object, errors);
         break;
      case CATEGORY_COHORT:
         result = FHIRGroupUtil.generateCohort((Group) object);
         break;
      case CATEGORY_ALLERGY:
         result = ContextUtil.getAllergyHelper().generateAllergy(object);
         break;
      default:
         throw new NotSupportedException(String.format("Category %s not supported.", category));
   }
   ErrorUtil.checkErrors(errors);
   return result;
}


Also some changes might be required in classes: FHIRUtils, and RestfulBundleResourceProvider.
After that, the ObjectName object should be able to be synchronized in OpenMRS Sync 2.0